Skip to content

Commit 92965c9

Browse files
committed
a
1 parent 268af2b commit 92965c9

6 files changed

Lines changed: 30 additions & 24 deletions

File tree

cli/cage/cageapp/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cageapp
22

33
import (
44
"io"
5+
"os"
56

67
"github.com/loilo-inc/canarycage/env"
78
"github.com/urfave/cli/v2"
@@ -12,6 +13,10 @@ type App struct {
1213
Stdin io.Reader
1314
}
1415

16+
func NewApp() *App {
17+
return &App{Stdin: os.Stdin}
18+
}
19+
1520
func RegionFlag(dest *string) *cli.StringFlag {
1621
return &cli.StringFlag{
1722
Name: "region",

cli/cage/cageapp/flags_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cageapp
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestNewApp(t *testing.T) {
11+
app := NewApp()
12+
assert := assert.New(t)
13+
14+
assert.NotNil(app, "NewApp() returned nil")
15+
assert.Equal(os.Stdin, app.Stdin, "expected Stdin to be os.Stdin")
16+
assert.False(app.CI, "expected CI to be false")
17+
}

cli/cage/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
)
2020

2121
func main() {
22-
flag := &cageapp.App{}
22+
appConf := cageapp.NewApp()
2323
app := cli.NewApp()
2424
app.Name = "canarycage"
2525
app.HelpName = "cage"
@@ -28,9 +28,9 @@ func main() {
2828
app.Description = "A deployment tool for AWS ECS"
2929
cmds := commands.NewCageCommands(cageapp.ProvideCageCli)
3030
app.Commands = []*cli.Command{
31-
cmds.Up(flag),
32-
cmds.RollOut(flag),
33-
cmds.Run(flag),
31+
cmds.Up(appConf),
32+
cmds.RollOut(appConf),
33+
cmds.Run(appConf),
3434
commands.Upgrade(upgrade.NewUpgrader(version)),
3535
commands.Scan(cageapp.ProvideScanDI),
3636
}
@@ -39,7 +39,7 @@ func main() {
3939
Name: "ci",
4040
Usage: "CI mode. Skip all confirmations and use default values.",
4141
EnvVars: []string{"CI"},
42-
Destination: &flag.CI,
42+
Destination: &appConf.CI,
4343
},
4444
}
4545
if err := app.Run(os.Args); err != nil {

cli/cage/scan/ecs.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scan
33
import (
44
"context"
55
"fmt"
6-
"regexp"
76
"strings"
87

98
"github.com/aws/aws-sdk-go-v2/service/ecs"
@@ -105,9 +104,3 @@ func splitRepoTag(value string) (string, string) {
105104
}
106105
return repository, tag
107106
}
108-
109-
var ecrURLPattern = regexp.MustCompile(`^\d{12}\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com$`)
110-
111-
func IsEcr(registry string) bool {
112-
return ecrURLPattern.MatchString(registry)
113-
}

cli/cage/scan/ecs_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,3 @@ func TestSplitRepoTag(t *testing.T) {
278278
assert.Equal(t, "latest", tag)
279279
})
280280
}
281-
282-
func TestIsEcr(t *testing.T) {
283-
t.Run("matches valid ecr registry", func(t *testing.T) {
284-
assert.True(t, IsEcr("123456789012.dkr.ecr.us-west-2.amazonaws.com"))
285-
})
286-
287-
t.Run("rejects non-ecr registry", func(t *testing.T) {
288-
assert.False(t, IsEcr("example.com"))
289-
})
290-
}

cli/cage/scan/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ func (i *ImageInfo) IsECRImage() bool {
1919
return i.Registry == "public.ecr.aws" || i.registryHasECRSuffix()
2020
}
2121

22+
var ecrURLPattern = regexp.MustCompile(`^[0-9]{12}\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com$`)
23+
2224
func (i *ImageInfo) registryHasECRSuffix() bool {
23-
pat := regexp.MustCompile(`^[0-9]{12}\.dkr\.ecr\.[a-z0-9-]+\.amazonaws\.com$`)
24-
return pat.MatchString(i.Registry)
25+
return ecrURLPattern.MatchString(i.Registry)
2526
}
2627

2728
type ScanResult struct {

0 commit comments

Comments
 (0)