Skip to content

Commit db62b66

Browse files
authored
Merge pull request #47 from ConductorOne/add_account_deprovisioning
[BB-785] Add account deprovisioning
2 parents fce6664 + 4837999 commit db62b66

File tree

4 files changed

+53
-63
lines changed

4 files changed

+53
-63
lines changed

.github/workflows/release.yaml

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,18 @@ name: Release
33
on:
44
push:
55
tags:
6-
- '*'
6+
- "*"
77

88
jobs:
9-
goreleaser:
10-
runs-on: macos-latest
11-
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
with:
15-
fetch-depth: 0
16-
- name: Set up Go
17-
uses: actions/setup-go@v4
18-
with:
19-
go-version: 1.23.x
20-
- name: Set up Gon
21-
run: brew tap conductorone/gon && brew install conductorone/gon/gon
22-
- name: Import Keychain Certs
23-
uses: apple-actions/import-codesign-certs@v1
24-
with:
25-
p12-file-base64: ${{ secrets.APPLE_SIGNING_KEY_P12 }}
26-
p12-password: ${{ secrets.APPLE_SIGNING_KEY_P12_PASSWORD }}
27-
- name: Run GoReleaser
28-
uses: goreleaser/goreleaser-action@v6
29-
with:
30-
version: "~> v2"
31-
args: release --clean
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.RELENG_GITHUB_TOKEN }}
34-
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
35-
AC_PROVIDER: ${{ secrets.AC_PROVIDER }}
36-
goreleaser-docker:
37-
runs-on: ubuntu-latest
38-
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v2
41-
with:
42-
fetch-depth: 0
43-
- name: Set up Go
44-
uses: actions/setup-go@v4
45-
with:
46-
go-version: 1.23.x
47-
- name: Docker Login
48-
uses: docker/login-action@v1
49-
with:
50-
registry: ghcr.io
51-
username: ${{ github.repository_owner }}
52-
password: ${{ secrets.RELENG_GITHUB_TOKEN }}
53-
- name: Set up Docker Buildx
54-
uses: docker/setup-buildx-action@v1
55-
- name: Run GoReleaser
56-
uses: goreleaser/goreleaser-action@v6
57-
with:
58-
version: "~> v2"
59-
args: release --clean -f .goreleaser.docker.yaml
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.RELENG_GITHUB_TOKEN }}
9+
release:
10+
uses: ConductorOne/github-workflows/.github/workflows/release.yaml@v2
11+
with:
12+
tag: ${{ github.ref_name }}
13+
lambda: false
14+
secrets:
15+
RELENG_GITHUB_TOKEN: ${{ secrets.RELENG_GITHUB_TOKEN }}
16+
APPLE_SIGNING_KEY_P12: ${{ secrets.APPLE_SIGNING_KEY_P12 }}
17+
APPLE_SIGNING_KEY_P12_PASSWORD: ${{ secrets.APPLE_SIGNING_KEY_P12_PASSWORD }}
18+
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
19+
AC_PROVIDER: ${{ secrets.AC_PROVIDER }}
20+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}

cmd/baton-slack/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/conductorone/baton-sdk/pkg/config"
8+
configSdk "github.com/conductorone/baton-sdk/pkg/config"
99
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
1010
"github.com/conductorone/baton-sdk/pkg/types"
11+
"github.com/conductorone/baton-slack/pkg/config"
1112
"github.com/conductorone/baton-slack/pkg/connector"
1213
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1314
"github.com/spf13/viper"
@@ -22,11 +23,11 @@ var (
2223
func main() {
2324
ctx := context.Background()
2425

25-
_, cmd, err := config.DefineConfiguration(
26+
_, cmd, err := configSdk.DefineConfiguration(
2627
ctx,
2728
connectorName,
2829
getConnector,
29-
Configuration,
30+
config.Configuration,
3031
)
3132
if err != nil {
3233
fmt.Fprintln(os.Stderr, err.Error())
@@ -46,10 +47,10 @@ func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, e
4647
logger := ctxzap.Extract(ctx)
4748
cb, err := connector.New(
4849
ctx,
49-
v.GetString(AccessTokenField.FieldName),
50-
v.GetString(EnterpriseTokenField.FieldName),
51-
v.GetBool(SSOEnabledField.FieldName),
52-
v.GetBool(GovEnvironmentField.FieldName),
50+
v.GetString(config.AccessTokenField.FieldName),
51+
v.GetString(config.EnterpriseTokenField.FieldName),
52+
v.GetBool(config.SSOEnabledField.FieldName),
53+
v.GetBool(config.GovEnvironmentField.FieldName),
5354
)
5455
if err != nil {
5556
logger.Error("error creating connector", zap.Error(err))
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package config
22

33
import (
44
"github.com/conductorone/baton-sdk/pkg/field"
@@ -7,20 +7,24 @@ import (
77
var (
88
AccessTokenField = field.StringField(
99
"token",
10+
field.WithDisplayName("Access Token"),
1011
field.WithDescription("The Slack bot user oauth token used to connect to the Slack API"),
1112
field.WithRequired(true),
1213
)
1314
EnterpriseTokenField = field.StringField(
1415
"enterprise-token",
16+
field.WithDisplayName("Enterprise Token"),
1517
field.WithDescription("The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API"),
1618
)
1719
SSOEnabledField = field.BoolField(
1820
"sso-enabled",
21+
field.WithDisplayName("SSO Enabled"),
1922
field.WithDescription("Flag indicating that the SSO has been configured for Enterprise Grid Organization. Enables usage of SCIM API"),
2023
field.WithDefaultValue(false),
2124
)
2225
GovEnvironmentField = field.BoolField(
2326
"gov-env",
27+
field.WithDisplayName("Gov Environment"),
2428
field.WithDescription("Flag indicating to use Slack-Gov environment."),
2529
field.WithDefaultValue(false),
2630
)
@@ -45,5 +49,5 @@ var (
4549
),
4650
}
4751

48-
Configuration = field.NewConfiguration(ConfigurationFields)
52+
Configuration = field.NewConfiguration(ConfigurationFields, field.WithConstraints(FieldRelationships...))
4953
)

pkg/connector/user.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,32 @@ func (o *userResourceType) CreateAccount(
301301
}, nil, outputAnnotations, nil
302302
}
303303

304+
func (o *userResourceType) Delete(ctx context.Context, resourceId *v2.ResourceId) (annotations.Annotations, error) {
305+
if o.enterpriseClient == nil {
306+
return nil, fmt.Errorf("baton-slack: enterprise client required for user deletion")
307+
}
308+
309+
userID := resourceId.Resource
310+
outputAnnotations := annotations.New()
311+
312+
user, ratelimitData, err := o.enterpriseClient.GetUserInfo(ctx, userID)
313+
outputAnnotations.WithRateLimiting(ratelimitData)
314+
if err != nil {
315+
return outputAnnotations, fmt.Errorf("baton-slack: failed to get user info: %w", err)
316+
}
317+
318+
ratelimitData, err = o.enterpriseClient.RemoveUser(ctx, user.Profile.Team, userID)
319+
outputAnnotations.WithRateLimiting(ratelimitData)
320+
if err != nil {
321+
if err.Error() == enterprise.SlackErrUserAlreadyDeleted {
322+
return outputAnnotations, nil
323+
}
324+
return outputAnnotations, fmt.Errorf("baton-slack: failed to delete user %s: %w", userID, err)
325+
}
326+
327+
return outputAnnotations, nil
328+
}
329+
304330
func (o *userResourceType) CreateAccountCapabilityDetails(ctx context.Context) (*v2.CredentialDetailsAccountProvisioning, annotations.Annotations, error) {
305331
return &v2.CredentialDetailsAccountProvisioning{
306332
SupportedCredentialOptions: []v2.CapabilityDetailCredentialOption{

0 commit comments

Comments
 (0)