Skip to content

Commit 978e09a

Browse files
committed
Account creation fixes.
- Have Validate() actually do something. - Fix discrepancy between account creation schema and actually used values (first name vs name). - Better error messages in account creation, like mentioning you need to set --account-creation-group.
1 parent 6a17e1e commit 978e09a

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@ Usage:
6262
Available Commands:
6363
capabilities Get connector capabilities
6464
completion Generate the autocompletion script for the specified shell
65+
config Get connector config
6566
help Help about any command
6667
6768
Flags:
68-
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
69-
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
70-
--access-token string The access token used to authenticate with the GitLab API ($BATON_ACCESS_TOKEN)
71-
--base-url string The base URL for the GitLab API ($BATON_BASE_URL) (default "https://gitlab.com/")
72-
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
73-
-h, --help help for baton-gitlab
74-
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
75-
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
76-
-p, --provisioning If this connector supports provisioning, this must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
77-
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
78-
-v, --version version for baton-gitlab
69+
--access-token string required: The access token to authenticate with the GitLab API ($BATON_ACCESS_TOKEN)
70+
--account-creation-group string The group indicated will be used as a default group for the new users. Required for account creation capability. ($BATON_ACCOUNT_CREATION_GROUP)
71+
--base-url string The base URL of the GitLab instance ($BATON_BASE_URL) (default "https://gitlab.com/")
72+
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
73+
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
74+
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
75+
-h, --help help for baton-gitlab
76+
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
77+
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
78+
--otel-collector-endpoint string The endpoint of the OpenTelemetry collector to send observability data to ($BATON_OTEL_COLLECTOR_ENDPOINT)
79+
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
80+
--skip-full-sync This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
81+
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
82+
-v, --version version for baton-gitlab
7983
8084
Use "baton-gitlab [command] --help" for more information about a command.
8185
```

cmd/baton-gitlab/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ var (
1919
)
2020
AccountCreationGroup = field.StringField(
2121
"account-creation-group",
22-
field.WithDescription("The group indicated will be used as a default group for the new users"),
23-
field.WithDefaultValue(""),
22+
field.WithDescription("The group indicated will be used as a default group for the new users. Required for account creation capability."),
2423
field.WithRequired(false),
2524
)
2625

pkg/connector/connector.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
1010
"github.com/conductorone/baton-sdk/pkg/annotations"
1111
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
12+
gitlabSDK "gitlab.com/gitlab-org/api/client-go"
1213
)
1314

1415
type Connector struct {
@@ -37,7 +38,7 @@ func (d *Connector) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error)
3738
Description: "GitLab is a web-based Git repository manager with built-in CI/CD pipeline functionality.",
3839
AccountCreationSchema: &v2.ConnectorAccountCreationSchema{
3940
FieldMap: map[string]*v2.ConnectorAccountCreationSchema_Field{
40-
"first_name": {
41+
"name": {
4142
DisplayName: "Name",
4243
Required: true,
4344
Description: "This name will be used for the user.",
@@ -85,6 +86,27 @@ func (d *Connector) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error)
8586
// Validate is called to ensure that the connector is properly configured. It should exercise any API credentials
8687
// to be sure that they are valid.
8788
func (d *Connector) Validate(ctx context.Context) (annotations.Annotations, error) {
89+
_, _, err := d.Client.ListGroups(ctx, "")
90+
if err != nil {
91+
return nil, fmt.Errorf("error listing groups: %w", err)
92+
}
93+
94+
if d.Client.AccountCreationGroup != "" {
95+
groupName := d.Client.AccountCreationGroup
96+
groups, _, err := d.Client.Groups.ListGroups(&gitlabSDK.ListGroupsOptions{
97+
Search: &groupName,
98+
},
99+
gitlabSDK.WithContext(ctx),
100+
)
101+
if err != nil {
102+
return nil, fmt.Errorf("error getting account creation group: %w", err)
103+
}
104+
105+
if len(groups) == 0 {
106+
return nil, fmt.Errorf("account creation group not found")
107+
}
108+
}
109+
88110
return nil, nil
89111
}
90112

pkg/connector/users.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func newUserBuilder(client *gitlab.Client) *userBuilder {
257257

258258
func (o *userBuilder) getGroupID(ctx context.Context) (string, error) {
259259
if o.AccountCreationGroup == "" {
260-
return "", fmt.Errorf("a creation group name is required when configuring the connector")
260+
return "", fmt.Errorf("account creation group not set. use --account-creation-group when running the connector")
261261
}
262262

263263
groupName := o.AccountCreationGroup
@@ -267,7 +267,7 @@ func (o *userBuilder) getGroupID(ctx context.Context) (string, error) {
267267
gitlabSDK.WithContext(ctx),
268268
)
269269
if err != nil {
270-
return "", err
270+
return "", fmt.Errorf("error listing groups: %w", err)
271271
}
272272

273273
for _, group := range groups {
@@ -276,7 +276,7 @@ func (o *userBuilder) getGroupID(ctx context.Context) (string, error) {
276276
}
277277
}
278278

279-
return "", fmt.Errorf("group name %s not found", groupName)
279+
return "", fmt.Errorf("account creation group %s not found", groupName)
280280
}
281281

282282
func userResource(user any) (*v2.Resource, error) {

0 commit comments

Comments
 (0)