2019-01-23 08:04:05 -05:00
|
|
|
package hyperone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
openapi "github.com/hyperonecom/h1-client-go"
|
2019-01-23 08:04:05 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Artifact struct {
|
|
|
|
imageName string
|
|
|
|
imageID string
|
|
|
|
client *openapi.APIClient
|
2020-01-30 05:27:58 -05:00
|
|
|
|
|
|
|
// StateData should store data such as GeneratedData
|
|
|
|
// to be shared with post-processors
|
|
|
|
StateData map[string]interface{}
|
2019-01-23 08:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) BuilderId() string {
|
|
|
|
return BuilderID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Files() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Id() string {
|
|
|
|
return a.imageID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) String() string {
|
|
|
|
return fmt.Sprintf("Image '%s' created, ID: %s", a.imageName, a.imageID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) State(name string) interface{} {
|
2020-01-30 05:27:58 -05:00
|
|
|
return a.StateData[name]
|
2019-01-23 08:04:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) Destroy() error {
|
|
|
|
if a.imageID == "" {
|
|
|
|
// No image to destroy
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := a.client.ImageApi.ImageDelete(context.TODO(), a.imageID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|