From 1c4b477ecfed7a1cae8a5a2a825d6fa6e6828d8e Mon Sep 17 00:00:00 2001 From: Lingyan Zhuang Date: Thu, 13 Feb 2025 20:36:29 +0800 Subject: [PATCH] Add a mandatory flag --group to gitlab integration --- integration-tests/scripts/.ci-env | 1 + integration-tests/scripts/.env.template | 1 + integration-tests/scripts/install.sh | 3 ++- pkg/integrations/gitlab.go | 9 +++++++++ pkg/subcmd/integration_gitlab.go | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/integration-tests/scripts/.ci-env b/integration-tests/scripts/.ci-env index 41a16d1b..9195bc75 100644 --- a/integration-tests/scripts/.ci-env +++ b/integration-tests/scripts/.ci-env @@ -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 diff --git a/integration-tests/scripts/.env.template b/integration-tests/scripts/.env.template index a35e46ec..ac78952b 100644 --- a/integration-tests/scripts/.env.template +++ b/integration-tests/scripts/.env.template @@ -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 diff --git a/integration-tests/scripts/install.sh b/integration-tests/scripts/install.sh index 3f32b44e..e6cb23a8 100755 --- a/integration-tests/scripts/install.sh +++ b/integration-tests/scripts/install.sh @@ -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 } diff --git a/pkg/integrations/gitlab.go b/pkg/integrations/gitlab.go index 2a2056e9..07677aa6 100644 --- a/pkg/integrations/gitlab.go +++ b/pkg/integrations/gitlab.go @@ -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. @@ -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. @@ -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, ) } @@ -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 } @@ -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( @@ -175,5 +183,6 @@ func NewGitLabIntegration( clientId: "", clientSecret: "", token: "", + group: "", } } diff --git a/pkg/subcmd/integration_gitlab.go b/pkg/subcmd/integration_gitlab.go index 207763d9..964909be 100644 --- a/pkg/subcmd/integration_gitlab.go +++ b/pkg/subcmd/integration_gitlab.go @@ -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{}