Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions scimdirectory/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions scimdirectory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,24 @@ func (c *Client) RotateAPIKey(ctx context.Context, id string) (*clerk.SCIMDirect
err = c.Backend.Call(ctx, req, resource)
return resource, err
}

type CredentialsParams struct {
clerk.APIParams
ServiceAccountJSON *string `json:"service_account_json,omitempty"`
SubjectEmail *string `json:"subject_email,omitempty"`
}

// AddCredentials adds pull-provider credentials (e.g. a Google service-account
// key and subject email) for a SCIM directory. They are validated and sealed
// server-side; on success the directory is enabled.
func (c *Client) AddCredentials(ctx context.Context, id string, params *CredentialsParams) (*clerk.SCIMDirectory, error) {
path, err := clerk.JoinPath(path, id, "credentials")
if err != nil {
return nil, err
}
req := clerk.NewAPIRequest(http.MethodPost, path)
req.SetParams(params)
resource := &clerk.SCIMDirectory{}
err = c.Backend.Call(ctx, req, resource)
return resource, err
}
36 changes: 36 additions & 0 deletions scimdirectory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,39 @@ func TestRotateAPIKey(t *testing.T) {
assert.Equal(t, "Test SCIM Directory", scimDirectory.Name)
assert.Equal(t, "sk_new_rotated_key", *scimDirectory.APIKey)
}

func TestAddCredentials(t *testing.T) {
t.Parallel()

response := map[string]interface{}{
"object": "scim_directory",
"id": "scim_test123",
"name": "Test SCIM Directory",
"enterprise_connection_id": "entc_123",
"provider": "google",
"enabled": true,
"created_at": 1640995200,
"updated_at": 1640995200,
}

responseJSON, _ := json.Marshal(response)

config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(responseJSON),
Method: http.MethodPost,
Path: "/v1/scim_directories/scim_test123/credentials",
},
}

client := NewClient(config)
scimDirectory, err := client.AddCredentials(context.Background(), "scim_test123", &CredentialsParams{
ServiceAccountJSON: clerk.String(`{"type":"service_account"}`),
SubjectEmail: clerk.String("admin@example.com"),
})
require.NoError(t, err)
assert.Equal(t, "scim_test123", scimDirectory.ID)
assert.True(t, scimDirectory.Enabled)
}
Loading