-
Notifications
You must be signed in to change notification settings - Fork 76
[CDTOOL-1297] Add support for service validation #1695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rcaril
merged 11 commits into
main
from
rcaril/CDTOOL-1297-add-support-for-service-version-validate
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
84e051d
feature(service/validate):
rcaril d24ffca
Update validate.go
rcaril 702d696
Update serviceversion_test.go
rcaril 2c0e110
feature(service/validate):
rcaril e720a2c
Update validate.go
rcaril 235b539
Update serviceversion_test.go
rcaril 9c7c1cf
Merge branch 'rcaril/CDTOOL-1297-add-support-for-service-version-vali…
rcaril d5c1642
update changelog
rcaril b961bc8
Merge branch 'main' into rcaril/CDTOOL-1297-add-support-for-service-v…
rcaril 48f9476
fix(lint): fixed double error reference
rcaril 533d6b2
Merge branch 'main' into rcaril/CDTOOL-1297-add-support-for-service-v…
rcaril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package version | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
|
|
||
| "github.com/fastly/go-fastly/v13/fastly" | ||
|
|
||
| "github.com/fastly/cli/pkg/argparser" | ||
| fsterr "github.com/fastly/cli/pkg/errors" | ||
| "github.com/fastly/cli/pkg/global" | ||
| "github.com/fastly/cli/pkg/text" | ||
| ) | ||
|
|
||
| // ValidateCommand calls the Fastly API to validate a service version. | ||
| type ValidateCommand struct { | ||
| argparser.Base | ||
| argparser.JSONOutput | ||
|
|
||
| input fastly.ValidateVersionInput | ||
| serviceVersion argparser.OptionalServiceVersion | ||
| } | ||
|
|
||
| // NewValidateCommand returns a usable command registered under the parent. | ||
| func NewValidateCommand(parent argparser.Registerer, g *global.Data) *ValidateCommand { | ||
| c := ValidateCommand{ | ||
| Base: argparser.Base{ | ||
| Globals: g, | ||
| }, | ||
| } | ||
| c.CmdClause = parent.Command("validate", "Validate a service version") | ||
| c.RegisterFlagBool(c.JSONFlag()) // --json | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagServiceIDName, | ||
| Description: argparser.FlagServiceIDDesc, | ||
| Dst: &g.Manifest.Flag.ServiceID, | ||
| Short: 's', | ||
| Required: true, | ||
| }) | ||
| c.RegisterFlag(argparser.StringFlagOpts{ | ||
| Name: argparser.FlagVersionName, | ||
| Description: argparser.FlagVersionDesc, | ||
| Dst: &c.serviceVersion.Value, | ||
| Required: true, | ||
| }) | ||
| return &c | ||
| } | ||
|
|
||
| // Exec invokes the application logic for the command. | ||
| func (c *ValidateCommand) Exec(_ io.Reader, out io.Writer) error { | ||
| if c.Globals.Verbose() && c.JSONOutput.Enabled { | ||
| return fsterr.ErrInvalidVerboseJSONCombo | ||
| } | ||
|
|
||
| serviceID, serviceVersion, err := argparser.ServiceDetails(argparser.ServiceDetailsOpts{ | ||
| APIClient: c.Globals.APIClient, | ||
| Manifest: *c.Globals.Manifest, | ||
| Out: out, | ||
| ServiceVersionFlag: c.serviceVersion, | ||
| VerboseMode: c.Globals.Flags.Verbose, | ||
| }) | ||
| if err != nil { | ||
| c.Globals.ErrLog.AddWithContext(err, map[string]any{ | ||
| "Service ID": serviceID, | ||
| "Service Version": fsterr.ServiceVersion(serviceVersion), | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| c.input.ServiceID = serviceID | ||
| c.input.ServiceVersion = fastly.ToValue(serviceVersion.Number) | ||
|
|
||
| valid, msg, err := c.Globals.APIClient.ValidateVersion(context.TODO(), &c.input) | ||
| if err != nil { | ||
| c.Globals.ErrLog.AddWithContext(err, map[string]any{ | ||
| "Service ID": serviceID, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| if ok, err := c.WriteJSON(out, map[string]any{ | ||
| "valid": valid, | ||
| "message": msg, | ||
| }); ok { | ||
| return err | ||
| } | ||
|
|
||
| if valid { | ||
| if msg != "" { | ||
| text.Success(out, "Service %s version %d is valid: %s", serviceID, c.input.ServiceVersion, msg) | ||
| } else { | ||
| text.Success(out, "Service %s version %d is valid", serviceID, c.input.ServiceVersion) | ||
| } | ||
| } else { | ||
| if msg != "" { | ||
| text.Error(out, "Service %s version %d is not valid: %s", serviceID, c.input.ServiceVersion, msg) | ||
| } else { | ||
| text.Error(out, "Service %s version %d is not valid", serviceID, c.input.ServiceVersion) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.