Skip to content

Commit

Permalink
Migration: move policies from defaults to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Mar 21, 2024
1 parent 308cfa8 commit 6ebe98a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions idm/policy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,24 @@ func Upgrade4199(ctx context.Context) error {
}
return nil
}

func Upgrade4399(ctx context.Context) error {
dao := servicecontext.GetDAO(ctx).(DAO)
if dao == nil {
return fmt.Errorf("cannot find DAO for policies initialization")
}
groups, e := dao.ListPolicyGroups(ctx, "")
if e != nil {
return e
}
for _, group := range groups {
if strings.HasPrefix(group.Name, "PolicyGroup.ACLSample") {
if er := dao.DeletePolicyGroup(ctx, group); er != nil {
log.Logger(ctx).Error("could not delete policy group "+group.Uuid, zap.Error(er))
} else {
log.Logger(ctx).Info("Removed sample policy group replaced by the template picker " + group.Uuid)
}
}
}
return nil
}
4 changes: 4 additions & 0 deletions idm/policy/grpc/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func init() {
TargetVersion: service.ValidVersion("4.1.99"),
Up: policy.Upgrade4199,
},
{
TargetVersion: service.ValidVersion("4.3.99"),
Up: policy.Upgrade4399,
},
}),
service.WithGRPC(func(ctx context.Context, server grpc.ServiceRegistrar) error {
handler := NewHandler(ctx, servicecontext.GetDAO(ctx).(policy.DAO))
Expand Down

0 comments on commit 6ebe98a

Please sign in to comment.