Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBAC support added to CLI Migrate #1171

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion cmd/cli/docs/botkube_migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Supported Botkube bot platforms for migration:
- 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
}
mszostok marked this conversation as resolved.
Show resolved Hide resolved

// 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
Loading