Skip to content

Commit

Permalink
RBAC support added to CLI Migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyinbabal committed Aug 2, 2023
1 parent b8e2b72 commit f961a5c
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 35 deletions.
1 change: 0 additions & 1 deletion cmd/cli/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func NewMigrate() *cobra.Command {
- Mattermost
Limitations:
- RBAC is defaulted
- Plugins are sourced from Botkube repository
Use label selector to choose which Botkube pod you want to migrate. By default it's set to app=botkube.
Expand Down
28 changes: 28 additions & 0 deletions internal/cli/migrate/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (c *Converter) convertExecutors(executors map[string]bkconfig.Executors) ([
{
Name: cfgName,
Configuration: string(rawCfg),
Rbac: c.convertRbac(p.Context),
},
},
})
Expand Down Expand Up @@ -121,6 +122,7 @@ func (c *Converter) convertSources(sources map[string]bkconfig.Sources) ([]*gqlM
{
Name: cfgName,
Configuration: string(rawCfg),
Rbac: c.convertRbac(p.Context),
},
},
})
Expand All @@ -130,6 +132,21 @@ func (c *Converter) convertSources(sources map[string]bkconfig.Sources) ([]*gqlM
return out, errs.ErrorOrNil()
}

func (c *Converter) convertRbac(ctx bkconfig.PluginContext) *gqlModel.RBACInput {
return &gqlModel.RBACInput{
User: &gqlModel.UserPolicySubjectInput{
Type: graphqlPolicySubjectType(ctx.RBAC.User.Type),
Static: &gqlModel.UserStaticSubjectInput{Value: ctx.RBAC.User.Static.Value},
Prefix: &ctx.RBAC.User.Prefix,
},
Group: &gqlModel.GroupPolicySubjectInput{
Type: graphqlPolicySubjectType(ctx.RBAC.Group.Type),
Static: &gqlModel.GroupStaticSubjectInput{Values: ctx.RBAC.Group.Static.Values},
Prefix: &ctx.RBAC.Group.Prefix,
},
}
}

// ConvertPlatforms converts cloud supported platforms.
func (c *Converter) ConvertPlatforms(platforms map[string]bkconfig.Communications) *gqlModel.PlatformsCreateInput {
out := gqlModel.PlatformsCreateInput{}
Expand Down Expand Up @@ -222,3 +239,14 @@ func toSlicePointers[T any](in []T) []*T {
}
return out
}

func graphqlPolicySubjectType(sub bkconfig.PolicySubjectType) gqlModel.PolicySubjectType {
switch sub {
case bkconfig.StaticPolicySubjectType:
return gqlModel.PolicySubjectTypeStatic
case bkconfig.ChannelNamePolicySubjectType:
return gqlModel.PolicySubjectTypeChannelName
default:
return gqlModel.PolicySubjectTypeEmpty
}
}
9 changes: 9 additions & 0 deletions internal/ptr/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ func ToSlice[T any](in []*T) []T {
return out
}

// FromSlice returns slice of pointers for a given type.
func FromSlice[T any](in []T) []*T {
out := make([]*T, 0, len(in))
for idx := range in {
out = append(out, &in[idx])
}
return out
}

// FromType returns pointer for a given input type.
func FromType[T any](in T) *T {
return &in
Expand Down
8 changes: 8 additions & 0 deletions internal/remote/graphql/connected_platforms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package graphql

// OrganizationConnectedPlatforms represents connected platforms.
type OrganizationConnectedPlatforms struct {
OrganizationID string `graphql:"-"`
Slacks []*SlackWorkspace `json:"slacks"`
Slack *SlackWorkspace `json:"slack"`
}
Loading

0 comments on commit f961a5c

Please sign in to comment.