-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(verify): verifies region versions
Verify will retrieve the latest regions version and if has the same version.
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,69 @@ | ||
/* | ||
* Copyright (c) Fabio da Silva Ribeiro <faabiosr@gmail.com> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"slices" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/faabiosr/lb/internal" | ||
) | ||
|
||
var verifyCmd = &cli.Command{ | ||
Name: "verify", | ||
Description: "verifies layer latest versions across regions", | ||
Flags: []cli.Flag{ | ||
&cli.StringSliceFlag{ | ||
Name: "regions", | ||
Aliases: []string{"r"}, | ||
Usage: "list of regions separated by comma.", | ||
Required: true, | ||
}, | ||
}, | ||
ArgsUsage: "layer-name", | ||
Action: func(cc *cli.Context) error { | ||
name := cc.Args().First() | ||
if name == "" { | ||
return errors.New(`required argument "layer-name" not set`) | ||
} | ||
|
||
regions := cc.StringSlice("regions") | ||
if len(regions) <= 1 { | ||
return errors.New(`required flag "regions" must contain at least two regions`) | ||
} | ||
|
||
cfg, err := config.LoadDefaultConfig(cc.Context) | ||
if err != nil { | ||
return fmt.Errorf("failed to load aws config: %w", err) | ||
} | ||
|
||
l := internal.LoadLayer(cfg, name) | ||
|
||
versions, err := l.LatestVersions(cc.Context, regions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bumped := slices.CompactFunc(versions, func(c, v *internal.Version) bool { | ||
return c.Number == v.Number | ||
}) | ||
|
||
if len(bumped) == 1 && bumped[0].Number == 0 { | ||
return errors.New("there are no published versions") | ||
} | ||
|
||
if len(bumped) > 1 { | ||
return errors.New(`some regions are not bumped`) | ||
} | ||
|
||
fmt.Fprintln(cc.App.Writer, "all regions bumped") | ||
return nil | ||
}, | ||
} |