Skip to content

Commit

Permalink
finish refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaeta committed Sep 13, 2024
1 parent e901da7 commit 122db68
Show file tree
Hide file tree
Showing 12 changed files with 1,007 additions and 551 deletions.
6 changes: 3 additions & 3 deletions cmd/baton-slack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ func main() {
}

func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)
logger := ctxzap.Extract(ctx)
cb, err := connector.New(
ctx,
v.GetString(AccessTokenField.FieldName),
v.GetString(EnterpriseTokenField.FieldName),
v.GetBool(SSOEnabledField.FieldName),
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
logger.Error("error creating connector", zap.Error(err))
return nil, err
}

c, err := connectorbuilder.NewConnector(ctx, cb)
if err != nil {
l.Error("error creating connector", zap.Error(err))
logger.Error("error creating connector", zap.Error(err))
return nil, err
}

Expand Down
41 changes: 17 additions & 24 deletions pkg/connector/client/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,29 @@ package enterprise

import (
"fmt"
"strings"

"github.com/conductorone/baton-slack/pkg"
)

const (
UrlPathGetRoleAssignments = "admin.roles.listAssignments"
UrlPathGetTeams = "admin.teams.list"
UrlPathGetUserGroupMembers = "usergroups.users.list"
UrlPathGetUserGroups = "usergroups.list"
UrlPathGetUserInfo = "users.info"
UrlPathGetUsers = "users.list"
UrlPathGetUsersAdmin = "admin.users.list"
UrlPathIDPGroup = "Groups/%s"
UrlPathIDPGroups = "Groups"
UrlPathSetAdmin = "admin.users.setAdmin"
UrlPathSetOwner = "admin.users.setOwner"
UrlPathSetRegular = "admin.users.setRegular"
baseScimUrl = "https://api.slack.com/scim/v2/"
baseUrl = "https://slack.com/api/"
UrlPathGetRoleAssignments = "/api/admin.roles.listAssignments"
UrlPathGetTeams = "/api/admin.teams.list"
UrlPathGetUserGroupMembers = "/api/usergroups.users.list"
UrlPathGetUserGroups = "/api/usergroups.list"
UrlPathGetUserInfo = "/api/users.info"
UrlPathGetUsers = "/api/users.list"
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"
)

func getWorkspaceUrlPathByRole(roleID string) (string, error) {
var role string

if roleID != "" {
roleSplit := strings.Split(roleID, ":")
if len(roleSplit) >= 2 {
role = roleSplit[1]
}
}

role, _ := pkg.ParseID(roleID)
switch role {
case "owner":
return UrlPathSetOwner, nil
Expand Down
14 changes: 5 additions & 9 deletions pkg/connector/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (c *Client) post(
payload map[string]interface{},
useBotToken bool,
) (
*http.Response,
*v2.RateLimitDescription,
error,
) {
Expand All @@ -85,7 +84,6 @@ func (c *Client) getScim(
target interface{},
queryParameters map[string]interface{},
) (
*http.Response,
*v2.RateLimitDescription,
error,
) {
Expand All @@ -104,7 +102,6 @@ func (c *Client) patchScim(
target interface{},
payload []byte,
) (
*http.Response,
*v2.RateLimitDescription,
error,
) {
Expand All @@ -125,7 +122,6 @@ func (c *Client) doRequest(
target interface{},
options ...uhttp.RequestOption,
) (
*http.Response,
*v2.RateLimitDescription,
error,
) {
Expand All @@ -148,26 +144,26 @@ func (c *Client) doRequest(
options...,
)
if err != nil {
return nil, nil, err
return nil, err
}
var ratelimitData v2.RateLimitDescription
response, err := c.wrapper.Do(
request,
uhttp.WithRatelimitData(&ratelimitData),
)
if err != nil {
return nil, &ratelimitData, err
return &ratelimitData, err
}
defer response.Body.Close()

bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, &ratelimitData, err
return &ratelimitData, err
}

if err := json.Unmarshal(bodyBytes, &target); err != nil {
return nil, nil, err
return nil, err
}

return response, &ratelimitData, nil
return &ratelimitData, nil
}
Loading

0 comments on commit 122db68

Please sign in to comment.