@@ -66,18 +66,7 @@ func ImagePush(c *cli.Context) {
66
66
logrus .Fatal ("Error executing 'push': " , err )
67
67
}
68
68
69
- var ecrClient ecrclient.Client
70
- useFips := c .Bool (flags .UseFIPSFlag )
71
-
72
- if useFips {
73
- ecrClient , err = ecrclient .NewFipsClient (commandConfig )
74
- if err != nil {
75
- logrus .Fatal ("Error executing 'push': " , err )
76
- }
77
- } else {
78
- ecrClient = ecrclient .NewClient (commandConfig )
79
- }
80
-
69
+ ecrClient := getECRClient (c , commandConfig )
81
70
stsClient := stsclient .NewClient (commandConfig )
82
71
83
72
if err := pushImage (c , rdwr , dockerClient , ecrClient , stsClient ); err != nil {
@@ -102,18 +91,7 @@ func ImagePull(c *cli.Context) {
102
91
logrus .Fatal ("Error executing 'pull': " , err )
103
92
}
104
93
105
- var ecrClient ecrclient.Client
106
- useFips := c .Bool (flags .UseFIPSFlag )
107
-
108
- if useFips {
109
- ecrClient , err = ecrclient .NewFipsClient (commandConfig )
110
- if err != nil {
111
- logrus .Fatal ("Error executing 'pull': " , err )
112
- }
113
- } else {
114
- ecrClient = ecrclient .NewClient (commandConfig )
115
- }
116
-
94
+ ecrClient := getECRClient (c , commandConfig )
117
95
stsClient := stsclient .NewClient (commandConfig )
118
96
119
97
if err := pullImage (c , rdwr , dockerClient , ecrClient , stsClient ); err != nil {
@@ -133,22 +111,27 @@ func ImageList(c *cli.Context) {
133
111
logrus .Fatal ("Error executing 'images': " , err )
134
112
}
135
113
136
- var ecrClient ecrclient.Client
114
+ ecrClient := getECRClient (c , commandConfig )
115
+
116
+ if err := getImages (c , rdwr , ecrClient ); err != nil {
117
+ logrus .Fatal ("Error executing 'images': " , err )
118
+ return
119
+ }
120
+ }
121
+
122
+ func getECRClient (c * cli.Context , commandConfig * config.CommandConfig ) ecrclient.Client {
123
+ ecrClient := ecrclient .NewClient (commandConfig )
124
+
137
125
useFips := c .Bool (flags .UseFIPSFlag )
138
126
139
127
if useFips {
140
- ecrClient , err = ecrclient .NewFipsClient (commandConfig )
128
+ fipsClient , err : = ecrclient .NewFipsClient (commandConfig )
141
129
if err != nil {
142
- logrus .Fatal ("Error executing 'images' : " , err )
130
+ logrus .Fatal ("Error creating FIPS client : " , err )
143
131
}
144
- } else {
145
- ecrClient = ecrclient .NewClient (commandConfig )
146
- }
147
-
148
- if err := getImages (c , rdwr , ecrClient ); err != nil {
149
- logrus .Fatal ("Error executing 'images': " , err )
150
- return
132
+ ecrClient = fipsClient
151
133
}
134
+ return ecrClient
152
135
}
153
136
154
137
func pushImage (c * cli.Context , rdwr config.ReadWriter , dockerClient dockerclient.Client , ecrClient ecrclient.Client , stsClient stsclient.Client ) error {
0 commit comments