-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
506 lines (441 loc) · 20.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
package main
import (
"fmt"
"log"
"main/util"
"os"
"strings"
"time"
"github.com/howeyc/gopass"
"github.com/spf13/cobra"
)
//TODO: Use viper to allow reading from config files
var harborServer, harborServerTarget string
var harborUser, harborUserTarget string
var harborPassword, harborPasswordTarget string
var harborAPIVersion, harborAPIVersionTarget string
var fromStringDate, untilStringDate string
var replicationName string
// database
var dbHostSource, dbHostTarget string
var dbUserSource, dbUserTarget string
var dbPasswordSource, dbPasswordTarget string
var clientId, tenant string
var dbPortSource, dbPortTarget int
var verbose bool
var rootCmd = &cobra.Command{
Use: "harborutils",
Short: "Interacts with harbor registry API",
}
var getProjectsGroupsCmd = &cobra.Command{
Use: "getProjects",
Short: "Get projects from Harbor",
Long: `Get projects from Harbor.`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
for _, project := range listProjects(harborServer, harborUser, harborPassword, harborAPIVersion) {
fmt.Println(project.Name)
}
},
}
var getGroupsCmd = &cobra.Command{
Use: "getGroups <prefix>",
Short: "Get groups from Harbor",
Long: `Get groups from Harbor.
If provided, only look for groups starting by <prefix> `,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
prefix := ""
if len(args) > 0 {
prefix = args[0]
}
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
groups, err := getGroupsFromPrefix(harborServer, harborUser, harborPassword, harborAPIVersion, prefix)
if err == nil {
for _, group := range groups {
fmt.Println(group.GroupName)
fmt.Println(group.LdapGroupDN)
fmt.Println(group.GroupType)
}
} else {
log.Fatal(err)
}
},
}
var deleteGroupsCmd = &cobra.Command{
Use: "deleteGroups <prefix>",
Short: "Delete groups from Harbor",
Long: `Delete groups from Harbor.
If provided, only look for groups starting by <prefix> `,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
prefix := ""
if len(args) > 0 {
prefix = args[0]
}
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
groups, err := getGroupsFromPrefix(harborServer, harborUser, harborPassword, harborAPIVersion, prefix)
if err == nil {
deleteGroups(harborServer, harborUser, harborPassword, harborAPIVersion, groups)
}
},
}
var syncGrantsCmd = &cobra.Command{
Use: "syncGrants <projectList>",
Short: "Propagate grants from primary harbor to secondary",
Long: `Propagate grants form primary server to secondary
Users and groups in registry will be checked against secondary registry and projects updated
if found.
- projectList should contain the project names (separated by comma)`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
harborPasswordTarget = promptForPassword(harborServerTarget, harborPasswordTarget)
var projects ProjectListResponse
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
if harborAPIVersionTarget != "" {
harborAPIVersionTarget = harborAPIVersionTarget + "/"
}
if len(args) > 0 {
project_list := strings.Split(args[0], ",")
for _, prj := range project_list {
project, err := getProject(harborServer, harborUser, harborPassword, prj, harborAPIVersion)
if err == nil {
projects = append(projects, project)
} else {
log.Println(err)
}
}
} else {
projects = listProjects(harborServer, harborUser, harborPassword, harborAPIVersion)
}
for _, project := range projects {
fmt.Println("Sync project ", project.Name)
syncProjectGrants(project)
}
},
}
var syncLabelsCmd = &cobra.Command{
Use: "syncLabels <projectList>",
Short: "Propagate project labels from primary harbor to secondary",
Long: `Propagate project labels form primary server to secondary
- projectList should contain the project names (separated by comma)`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
harborPasswordTarget = promptForPassword(harborServerTarget, harborPasswordTarget)
var projects ProjectListResponse
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
if harborAPIVersionTarget != "" {
harborAPIVersionTarget = harborAPIVersionTarget + "/"
}
if len(args) > 0 {
project_list := strings.Split(args[0], ",")
for _, prj := range project_list {
project, err := getProject(harborServer, harborUser, harborPassword, prj, harborAPIVersion)
if err == nil {
projects = append(projects, project)
} else {
log.Println(err)
}
}
} else {
projects = listProjects(harborServer, harborUser, harborPassword, harborAPIVersion)
}
for _, project := range projects {
fmt.Println("Sync project ", project.Name)
syncProjectLabels(project)
}
},
}
var importLdapUsersCmd = &cobra.Command{
Use: "importLdapUsers <harbor>",
Short: "Propagate users from primary harbor to secondary",
Long: `Propagate users from primary harbor to secondary`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
harborPasswordTarget = promptForPassword(harborServerTarget, harborPasswordTarget)
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
if harborAPIVersionTarget != "" {
harborAPIVersionTarget = harborAPIVersionTarget + "/"
}
users, err := getSourceUsers(harborServer, harborUser, harborPassword, harborAPIVersion)
if err == nil {
usernames := make([]string, len(users))
for i, user := range users {
usernames[i] = user.Username
}
newUserImport := UserImport{}
newUserImport.LdapUIDList = usernames
importLdapUser(harborServerTarget, harborUserTarget, harborPasswordTarget, harborAPIVersionTarget, newUserImport)
} else {
log.Println(err)
}
},
}
var importLdapGroupsCmd = &cobra.Command{
Use: "importLdapGroups <harbor>",
Short: "Propagate groups from primary harbor to secondary",
Long: `Propagate groups from primary harbor to secondary`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
harborPasswordTarget = promptForPassword(harborServerTarget, harborPasswordTarget)
if harborAPIVersion != "" {
harborAPIVersion = harborAPIVersion + "/"
}
if harborAPIVersionTarget != "" {
harborAPIVersionTarget = harborAPIVersionTarget + "/"
}
groups, err := listGroups(harborServer, harborUser, harborPassword, harborAPIVersion)
if err == nil {
for _, g := range groups {
fmt.Println(g.GroupName)
}
importGroups(harborServerTarget, harborUserTarget, harborPasswordTarget, harborAPIVersionTarget, groups)
}
},
}
// Short: "Propagate project labels from primary harbor to secondary",
// Long: `Propagate project labels form primary server to secondary
var syncRobotAccountCmd = &cobra.Command{
Use: "syncRobotAccount",
Short: "Propagate robot account from primary harbor to secondary",
Long: "Propagate robot account from primary harbor to secondary",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
harborAPIVersion = util.ApiVersion(harborAPIVersion)
harborAPIVersionTarget = util.ApiVersion(harborAPIVersion)
syncRobots(harborServer, harborUser, harborPassword, harborAPIVersion, harborServerTarget, harborUserTarget, harborPasswordTarget, harborAPIVersionTarget,
clientDb(dbHostSource, dbUserSource, dbPasswordSource, dbPortSource, verbose),
clientDb(dbHostTarget, dbUserTarget, dbPasswordTarget, dbPortTarget, verbose))
},
}
var fixEmptyEmailsDbCmd = &cobra.Command{
Use: "fixEmptyEmails",
Short: "Fix empty emails in database",
Long: `Fix empty emails in database`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
FixEmptyEmails(clientDb(dbHostSource, dbUserSource, dbPasswordSource, dbPortSource, verbose))
},
}
var syncUsersDbCmd = &cobra.Command{
Use: "syncUsersDb",
Short: "Sync users between harbor primary and harbor secondary",
Long: "Sync users between harbor primary and harbor secondary",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
SyncUsersDatabase(clientDb(dbHostSource, dbUserSource, dbPasswordSource, dbPortSource, verbose),
clientDb(dbHostTarget, dbUserTarget, dbPasswordTarget, dbPortTarget, verbose))
},
}
var getShaCmd = &cobra.Command{
Use: "getSha <project> <image>",
Short: "Get image digest from Harbor",
Long: `Get image disgest from Harbor.`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
var image = args[1]
var project = args[0]
harborAPIVersion = util.ApiVersion(harborAPIVersion)
sha, err := getArtifactSHA(clientId, tenant, harborServer, harborUser, harborPassword, harborAPIVersion, project, image)
if err != nil {
log.Fatal(err)
}
fmt.Println(sha)
},
}
var checkShaCmd = &cobra.Command{
Use: "checkSha <project> <image> <digest>",
Short: "Check image digest against Harbor",
Long: `Check image digest against Harbor.`,
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
harborPassword = promptForPassword(harborServer, harborPassword)
var image = args[1]
var project = args[0]
var digest = args[2]
harborAPIVersion = util.ApiVersion(harborAPIVersion)
equal := checkArtifactSHA(clientId, tenant, harborServer, harborUser, harborPassword, harborAPIVersion, project, image, digest)
if equal {
fmt.Println("Same digest in registry")
os.Exit(0)
}
fmt.Println("Image digest differs")
os.Exit(1)
},
}
var syncRegistriesCmd = &cobra.Command{
Use: "syncRegistries",
Short: "Syncs objects created between two dates from harbor primary to harbor secundary",
Long: "Syncs objects created between two dates from harbor primary to harbor secundary",
Run: func(cmd *cobra.Command, args []string) {
t, err := time.Parse("2006-01-02T15:04:05Z", fromStringDate)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fromDate := t
// t, err = util.ParseRFC3339(untilStringDate, metav1.Now)
t, err = time.Parse("2006-01-02T15:04:05Z", untilStringDate)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
untilDate := t
harborAPIVersion = util.ApiVersion(harborAPIVersion)
fmt.Printf("%s, %s", fromDate, untilDate)
replication(harborServer, harborUser, harborPassword, harborAPIVersion, replicationName, fromDate, untilDate)
},
}
var getReplicationTaksCmd = &cobra.Command{
Use: "replicationTaks",
Short: "returns the status of the last replications tasks (harbor stored the last 50)",
Long: "returns the status of the last replications tasks (harbor stored the last 50)",
Run: func(cmd *cobra.Command, args []string) {
harborAPIVersion = util.ApiVersion(harborAPIVersion)
getReplicationTaksByPolicyName(harborServer, harborUser, harborPassword, harborAPIVersion, replicationName)
},
}
func main() {
rootCmd.PersistentFlags().StringVarP(&harborServer, "harbor", "s", "", "Harbor Server address")
rootCmd.MarkPersistentFlagRequired("harbor")
rootCmd.PersistentFlags().StringVarP(&harborUser, "user", "u", "", "Username Harbor")
rootCmd.MarkPersistentFlagRequired("user")
rootCmd.PersistentFlags().StringVarP(&harborPassword, "password", "p", "", "Password")
rootCmd.PersistentFlags().StringVarP(&harborAPIVersion, "apiVersion", "v", "v2.0", "APIVersion (ie v2.0)")
syncGrantsCmd.PersistentFlags().StringVarP(&harborServerTarget, "harbor2", "", "", "Harbor Secondary Server address")
syncGrantsCmd.MarkPersistentFlagRequired("harbor2")
syncGrantsCmd.PersistentFlags().StringVarP(&harborUserTarget, "user2", "", "", "Username Secondary Harbor")
syncGrantsCmd.MarkPersistentFlagRequired("user2")
syncGrantsCmd.PersistentFlags().StringVarP(&harborPasswordTarget, "password2", "", "", "Password Secondary Harbor")
syncGrantsCmd.PersistentFlags().StringVarP(&harborAPIVersionTarget, "apiVersion2", "", "v2.0", "API Version Secondary Harbor (ie v2.0) ")
syncLabelsCmd.PersistentFlags().StringVarP(&harborServerTarget, "harbor2", "", "", "Harbor Secondary Server address")
syncLabelsCmd.MarkPersistentFlagRequired("harbor2")
syncLabelsCmd.PersistentFlags().StringVarP(&harborUserTarget, "user2", "", "", "Username Secondary Harbor")
syncLabelsCmd.MarkPersistentFlagRequired("user2")
syncLabelsCmd.PersistentFlags().StringVarP(&harborPasswordTarget, "password2", "", "", "Password Secondary Harbor")
syncLabelsCmd.PersistentFlags().StringVarP(&harborAPIVersionTarget, "apiVersion2", "", "", "API Version Secondary Harbor (ie v2.0)")
importLdapUsersCmd.PersistentFlags().StringVarP(&harborServerTarget, "harbor2", "", "", "Harbor Secondary Server address")
importLdapUsersCmd.MarkPersistentFlagRequired("harbor2")
importLdapUsersCmd.PersistentFlags().StringVarP(&harborUserTarget, "user2", "", "", "Username Secondary Harbor")
importLdapUsersCmd.MarkPersistentFlagRequired("user2")
importLdapUsersCmd.PersistentFlags().StringVarP(&harborPasswordTarget, "password2", "", "", "Password Secondary Harbor")
importLdapUsersCmd.PersistentFlags().StringVarP(&harborAPIVersionTarget, "apiVersion2", "", "", "API Version Secondary Harbor (ie v2.0)")
importLdapGroupsCmd.PersistentFlags().StringVarP(&harborServerTarget, "harbor2", "", "", "Harbor Secondary Server address")
importLdapGroupsCmd.MarkPersistentFlagRequired("harbor2")
importLdapGroupsCmd.PersistentFlags().StringVarP(&harborUserTarget, "user2", "", "", "Username Secondary Harbor")
importLdapGroupsCmd.MarkPersistentFlagRequired("user2")
importLdapGroupsCmd.PersistentFlags().StringVarP(&harborPasswordTarget, "password2", "", "", "Password Secondary Harbor")
importLdapGroupsCmd.PersistentFlags().StringVarP(&harborAPIVersionTarget, "apiVersion2", "", "", "API Version Secondary Harbor (ie v2.0)")
fixEmptyEmailsDbCmd.PersistentFlags().StringVarP(&dbHostSource, "dbHostSource", "", "", "source database host")
fixEmptyEmailsDbCmd.MarkPersistentFlagRequired("dbHostSource")
fixEmptyEmailsDbCmd.PersistentFlags().StringVarP(&dbUserSource, "dbUserSource", "", "", "source database user")
fixEmptyEmailsDbCmd.MarkPersistentFlagRequired("dbUserSource")
fixEmptyEmailsDbCmd.PersistentFlags().StringVarP(&dbPasswordSource, "dbPasswordSource", "", "", "source database password")
fixEmptyEmailsDbCmd.MarkPersistentFlagRequired("dbPasswordSource")
fixEmptyEmailsDbCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false, "verbose output, shows all sql operations")
fixEmptyEmailsDbCmd.MarkPersistentFlagRequired("")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbHostSource, "dbHostSource", "", "", "source database host")
syncUsersDbCmd.MarkPersistentFlagRequired("dbHostSource")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbUserSource, "dbUserSource", "", "", "source database user")
syncUsersDbCmd.MarkPersistentFlagRequired("dbUserSource")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbPasswordSource, "dbPasswordSource", "", "", "source database password")
syncUsersDbCmd.MarkPersistentFlagRequired("dbPasswordSource")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbHostTarget, "dbHostTarget", "", "", "source database host")
syncUsersDbCmd.MarkPersistentFlagRequired("dbHostTarget")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbUserTarget, "dbUserTarget", "", "", "source database user")
syncUsersDbCmd.MarkPersistentFlagRequired("dbUserTarget")
syncUsersDbCmd.PersistentFlags().StringVarP(&dbPasswordTarget, "dbPasswordTarget", "", "", "source database password")
syncUsersDbCmd.MarkPersistentFlagRequired("dbPasswordTarget")
syncUsersDbCmd.PersistentFlags().IntVarP(&dbPortSource, "dbPortSource", "", 5432, "source database port, defualt 5432")
syncUsersDbCmd.PersistentFlags().IntVarP(&dbPortTarget, "dbPortTarget", "", 5432, "target database port, default 5432")
syncUsersDbCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false, "verbose output, shows all sql operations")
syncUsersDbCmd.MarkPersistentFlagRequired("")
syncRobotAccountCmd.PersistentFlags().StringVarP(&harborServerTarget, "harbor2", "", "", "Harbor Secondary Server address")
syncRobotAccountCmd.MarkPersistentFlagRequired("harbor2")
syncRobotAccountCmd.PersistentFlags().StringVarP(&harborUserTarget, "user2", "", "", "Username Secondary Harbor")
syncRobotAccountCmd.MarkPersistentFlagRequired("user2")
syncRobotAccountCmd.PersistentFlags().StringVarP(&harborPasswordTarget, "password2", "", "", "Password Secondary Harbor")
syncRobotAccountCmd.PersistentFlags().StringVarP(&harborAPIVersionTarget, "apiVersion2", "", "", "API Version Secondary Harbor (ie v2.0)")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbHostSource, "dbHostSource", "", "", "source database host")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbHostSource")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbUserSource, "dbUserSource", "", "", "source database user")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbUserSource")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbPasswordSource, "dbPasswordSource", "", "", "source database password")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbPasswordSource")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbHostTarget, "dbHostTarget", "", "", "source database host")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbHostTarget")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbUserTarget, "dbUserTarget", "", "", "source database user")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbUserTarget")
syncRobotAccountCmd.PersistentFlags().StringVarP(&dbPasswordTarget, "dbPasswordTarget", "", "", "source database password")
syncRobotAccountCmd.MarkPersistentFlagRequired("dbPasswordTarget")
syncRobotAccountCmd.PersistentFlags().IntVarP(&dbPortSource, "dbPortSource", "", 5432, "source database port, defualt 5432")
syncRobotAccountCmd.PersistentFlags().IntVarP(&dbPortTarget, "dbPortTarget", "", 5432, "target database port, default 5432")
syncRobotAccountCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "", false, "verbose output, shows all sql operations")
syncRobotAccountCmd.MarkPersistentFlagRequired("")
syncRegistriesCmd.PersistentFlags().StringVarP(&fromStringDate, "fromDate", "", "", "Syncronitation from date specific date (RFC3339)")
syncRegistriesCmd.MarkPersistentFlagRequired("fromDate")
syncRegistriesCmd.PersistentFlags().StringVarP(&untilStringDate, "untilDate", "", "", "Syncronitation until date specific date (RFC3339)")
syncRegistriesCmd.MarkPersistentFlagRequired("untilDate")
syncRegistriesCmd.PersistentFlags().StringVarP(&replicationName, "replicationName", "", "", "Replication Rule Name, the configuration of this replication will be used")
syncRegistriesCmd.MarkPersistentFlagRequired("replicationName")
getShaCmd.PersistentFlags().StringVarP(&clientId, "oidcClient", "", "", "Oidc client id for authentication")
getShaCmd.MarkPersistentFlagRequired("oidcClient")
getShaCmd.PersistentFlags().StringVarP(&tenant, "tenant", "", "", "Azure tenant for oidc authentication")
getShaCmd.MarkPersistentFlagRequired("tenant")
checkShaCmd.PersistentFlags().StringVarP(&clientId, "oidcClient", "", "", "Oidc client id for authentication")
checkShaCmd.MarkPersistentFlagRequired("oidcClient")
checkShaCmd.PersistentFlags().StringVarP(&tenant, "tenant", "", "", "Azure tenant for oidc authentication")
checkShaCmd.MarkPersistentFlagRequired("tenant")
rootCmd.AddCommand(getProjectsGroupsCmd)
rootCmd.AddCommand(getGroupsCmd)
rootCmd.AddCommand(deleteGroupsCmd)
rootCmd.AddCommand(syncGrantsCmd)
rootCmd.AddCommand(syncLabelsCmd)
rootCmd.AddCommand(importLdapUsersCmd)
rootCmd.AddCommand(importLdapGroupsCmd)
rootCmd.AddCommand(syncRobotAccountCmd)
rootCmd.AddCommand(fixEmptyEmailsDbCmd)
rootCmd.AddCommand(syncUsersDbCmd)
rootCmd.AddCommand(syncRegistriesCmd)
rootCmd.AddCommand(getShaCmd)
rootCmd.AddCommand(checkShaCmd)
getReplicationTaksCmd.PersistentFlags().StringVarP(&replicationName, "replicationName", "", "", "Replication Rule Name, the configuration of this replication will be used")
getReplicationTaksCmd.MarkPersistentFlagRequired("replicationName")
rootCmd.AddCommand(getReplicationTaksCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func promptForPassword(field, pass string) string {
var password string
if pass == "" {
print("Password for ", field, ": ")
pass, _ := gopass.GetPasswd()
password = string(pass)
} else {
password = pass
}
return password
}