Skip to content

Commit

Permalink
Add a mandatory flag --group to gitlab integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyzhuang authored and Roming22 committed Feb 14, 2025
1 parent 8809324 commit 1c4b477
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration-tests/scripts/.ci-env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export GITLAB__TOKEN=
# When using gitlab as auth provider(auth_config="github"), you also need to set the following values
export GITLAB__APP__ID=
export GITLAB__APP_SECRET=
export GITLAB__GROUP=


#### Quay.io
Expand Down
1 change: 1 addition & 0 deletions integration-tests/scripts/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export GITLAB__TOKEN=
# When using gitlab as auth provider(auth_config="github"), you also need to set the following values
export GITLAB__APP__ID=
export GITLAB__APP_SECRET=
export GITLAB__GROUP=


#### Quay.io
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ gitlab_integration() {

GITLAB__APP__ID="${GITLAB__APP__ID:-$(cat /usr/local/rhtap-cli-install/gitlab-app-id)}"
GITLAB__APP_SECRET="${GITLAB__APP_SECRET:-$(cat /usr/local/rhtap-cli-install/gitlab-app-secret)}"
GITLAB__GROUP="${GITLAB__GROUP:-$(cat /usr/local/rhtap-cli-install/gitlab-group)}"

./bin/rhtap-cli integration --kube-config "$KUBECONFIG" gitlab --token="${GITLAB__TOKEN}" --app-id="${GITLAB__APP__ID}" --app-secret="${GITLAB__APP_SECRET}"
./bin/rhtap-cli integration --kube-config "$KUBECONFIG" gitlab --token="${GITLAB__TOKEN}" --app-id="${GITLAB__APP__ID}" --app-secret="${GITLAB__APP_SECRET}" --group="${GITLAB__GROUP}"
fi
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/integrations/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type GitLabIntegration struct {
clientId string // GitLab application client id
clientSecret string // GitLab application client secret
token string // API token credentials
group string // GitLab group name
}

// PersistentFlags sets the persistent flags for the GitLab integration.
Expand All @@ -44,6 +45,8 @@ func (g *GitLabIntegration) PersistentFlags(p *pflag.FlagSet) {
"GitLab application client secret")
p.StringVar(&g.token, "token", g.token,
"GitLab API token")
p.StringVar(&g.group, "group", g.group,
"GitLab group name")
}

// log logger with contextual information.
Expand All @@ -54,6 +57,7 @@ func (g *GitLabIntegration) log() *slog.Logger {
"clientId", g.clientId,
"clientSecret-len", len(g.clientSecret),
"token-len", len(g.token),
"group", g.group,
)
}

Expand All @@ -71,6 +75,9 @@ func (g *GitLabIntegration) Validate() error {
if g.token == "" {
return fmt.Errorf("token is required")
}
if g.group == "" {
return fmt.Errorf("group is required")
}
return nil
}

Expand Down Expand Up @@ -130,6 +137,7 @@ func (g *GitLabIntegration) store(
"clientSecret": []byte(g.clientSecret),
"host": []byte(g.host),
"token": []byte(g.token),
"group": []byte(g.group),
},
}
logger := g.log().With(
Expand Down Expand Up @@ -175,5 +183,6 @@ func NewGitLabIntegration(
clientId: "",
clientSecret: "",
token: "",
group: "",
}
}
1 change: 1 addition & 0 deletions pkg/subcmd/integration_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type IntegrationGitLab struct {
clientId string // Application client id
clientSecret string // Application client secret
token string // API token
group string // Group name
}

var _ Interface = &IntegrationGitLab{}
Expand Down

0 comments on commit 1c4b477

Please sign in to comment.