Skip to content

Commit

Permalink
added comments, added better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
aldevv committed Nov 7, 2024
1 parent 13a35e6 commit 6fafd0a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 41 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/conductorone/baton-slack

go 1.21
go 1.23

toolchain go1.23.0

Expand Down
14 changes: 9 additions & 5 deletions pkg/connector/client/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"github.com/conductorone/baton-slack/pkg"
)

// docs: https://api.slack.com/methods
const (
baseScimUrl = "https://api.slack.com"
baseUrl = "https://slack.com"
UrlPathGetRoleAssignments = "/api/admin.roles.listAssignments"
UrlPathGetTeams = "/api/admin.teams.list"
UrlPathGetUserGroupMembers = "/api/usergroups.users.list"
Expand All @@ -16,11 +19,12 @@ const (
UrlPathGetUsersAdmin = "/api/admin.users.list"
UrlPathIDPGroup = "/scim/v2/Groups/%s"
UrlPathIDPGroups = "/scim/v2/Groups"
UrlPathSetAdmin = "/api/admin.users.setAdmin"
UrlPathSetOwner = "/api/admin.users.setOwner"
UrlPathSetRegular = "/api/admin.users.setRegular"
baseScimUrl = "https://api.slack.com"
baseUrl = "https://slack.com"

// NOTE: these are only for enterprise grid workspaces
// docs: https://api.slack.com/methods/admin.users.setRegular
UrlPathSetRegular = "/api/admin.users.setRegular"
UrlPathSetAdmin = "/api/admin.users.setAdmin"
UrlPathSetOwner = "/api/admin.users.setOwner"
)

func getWorkspaceUrlPathByRole(roleID string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Client) post(
ctx,
http.MethodPost,
c.getUrl(path, nil, false),
&target,
target,
WithBearerToken(token),
uhttp.WithFormBody(toValues(payload)),
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func New(ctx context.Context, apiKey, enterpriseKey string, ssoEnabled bool) (*S
if err != nil {
return nil, fmt.Errorf("slack-connector: failed to create enterprise client. Error: %w", err)
}

return &Slack{
client: client,
apiKey: apiKey,
Expand All @@ -112,7 +111,7 @@ func (s *Slack) ResourceSyncers(ctx context.Context) []connectorbuilder.Resource
userBuilder(s.client, s.enterpriseID, s.enterpriseClient),
workspaceBuilder(s.client, s.enterpriseID, s.enterpriseClient),
userGroupBuilder(s.client, s.enterpriseID, s.enterpriseClient),
workspaceRoleBuilder(s.client, s.enterpriseClient),
workspaceRoleBuilder(s.client, s.enterpriseID, s.enterpriseClient),
enterpriseRoleBuilder(s.enterpriseID, s.enterpriseClient),
groupBuilder(s.enterpriseClient, s.enterpriseID, s.ssoEnabled),
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/connector/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ type workspaceRoleType struct {
resourceType *v2.ResourceType
client *slack.Client
enterpriseClient *enterprise.Client
enterpriseID string
}

func (o *workspaceRoleType) ResourceType(_ context.Context) *v2.ResourceType {
return o.resourceType
}

func workspaceRoleBuilder(client *slack.Client, enterpriseClient *enterprise.Client) *workspaceRoleType {
func workspaceRoleBuilder(client *slack.Client, enterpriseID string, enterpriseClient *enterprise.Client) *workspaceRoleType {
return &workspaceRoleType{
resourceType: resourceTypeWorkspaceRole,
client: client,
enterpriseClient: enterpriseClient,
enterpriseID: enterpriseID,
}
}

Expand Down Expand Up @@ -216,6 +218,10 @@ func (o *workspaceRoleType) Revoke(
annotations.Annotations,
error,
) {
if o.enterpriseID == "" {
return nil, fmt.Errorf("baton-slack: enterprise ID is required to revoke roles")
}

logger := ctxzap.Extract(ctx)

principal := grant.Principal
Expand Down
30 changes: 0 additions & 30 deletions vendor/github.com/conductorone/baton-sdk/pkg/helpers/helpers.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ github.com/conductorone/baton-sdk/pkg/dotc1z/manager
github.com/conductorone/baton-sdk/pkg/dotc1z/manager/local
github.com/conductorone/baton-sdk/pkg/dotc1z/manager/s3
github.com/conductorone/baton-sdk/pkg/field
github.com/conductorone/baton-sdk/pkg/helpers
github.com/conductorone/baton-sdk/pkg/logging
github.com/conductorone/baton-sdk/pkg/metrics
github.com/conductorone/baton-sdk/pkg/pagination
Expand Down

0 comments on commit 6fafd0a

Please sign in to comment.