in step_deprecate_images.go [48:76]
func (d *DeprecateImages) validate(ctx context.Context, s *Step) DError {
deprecationStates := []string{"", "ACTIVE", "DEPRECATED", "OBSOLETE", "DELETED"}
for _, di := range *d {
if exists, err := projectExists(s.w.ComputeClient, di.Project); err != nil {
return Errf("cannot deprecate image %q: bad project lookup: %q, error: %v", di.Image, di.Project, err)
} else if !exists {
return Errf("cannot deprecate image %q: project does not exist: %q", di.Image, di.Project)
}
// Verify State is one of the deprecated states.
// The Alpha check also requires the value to not be emptry string as in that case the GA API will be used.
if di.DeprecationStatusAlpha.State != "" && !strIn(di.DeprecationStatusAlpha.State, deprecationStates) {
return Errf("DeprecationStatusAlpha.State of %q not in %q", di.DeprecationStatusAlpha.State, deprecationStates)
} else if !strIn(di.DeprecationStatus.State, deprecationStates) {
return Errf("DeprecationStatus.State of %q not in %q", di.DeprecationStatus.State, deprecationStates)
}
// regUse needs the partal url of a non daisy resource.
lookup := di.Image
if _, ok := s.w.images.get(di.Image); !ok {
lookup = fmt.Sprintf("projects/%s/global/images/%s", di.Project, di.Image)
}
if _, err := s.w.images.regUse(lookup, s); err != nil {
return newErr("failed to register use of image when deprecating", err)
}
}
return nil
}