-
Notifications
You must be signed in to change notification settings - Fork 0
/
qsgpm.go
54 lines (49 loc) · 1.12 KB
/
qsgpm.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
package qsgpm
import (
"context"
"log"
)
type App struct {
svc *QuickSightService
cfg *Config
}
func New(ctx context.Context, cfg *Config) (*App, error) {
svc, err := newQuickSightService(ctx)
if err != nil {
return nil, err
}
return &App{
svc: svc,
cfg: cfg,
}, nil
}
type RunOption struct {
DryRun bool
}
func (app *App) Run(ctx context.Context, opt RunOption) error {
svc := app.svc
if opt.DryRun {
svc = svc.GetDryRunService()
}
namespaces := app.cfg.GetNamespaces()
for _, namespace := range namespaces {
log.Printf("[debug] namespace: %s", namespace)
expectGroups := newGroups()
p := svc.NewUsersPaginator(namespace)
for p.HasMoreUsers() {
users, err := p.NextUsers(ctx)
if err != nil {
return err
}
for _, user := range users {
if groupNames, ok := app.cfg.GetGroupNames(user); ok {
expectGroups.Assign(*user.UserName, groupNames)
}
customPermissionName := app.cfg.GetCustomPermissionName(user)
svc.UpdateUserCustomPermission(ctx, user, customPermissionName)
}
}
svc.ApplyGroups(ctx, namespace, expectGroups, WithCreateOnly(app.cfg.CreateOnly))
}
return nil
}