Skip to content

Commit 6152a19

Browse files
author
Julien Pivotto
authored
Merge pull request #686 from gitlabhq/oauth-token
Support running the provider using an OAuth token
2 parents fb0bde1 + fd696af commit 6152a19

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TEST?=./gitlab
22
SERVICE?=gitlab-ce
3-
GITLAB_TOKEN?=ACCTEST
3+
GITLAB_TOKEN?=ACCTEST1234567890123
44
GITLAB_BASE_URL?=http://127.0.0.1:8080/api/v4
55
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
66

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ $ make testacc GITLAB_TOKEN=example123 GITLAB_BASE_URL=https://example.com/api/v
106106
Then run the desired Go test as you would normally from your IDE, but configure your run configuration to set these environment variables:
107107

108108
```
109-
GITLAB_TOKEN=ACCTEST
109+
GITLAB_TOKEN=ACCTEST1234567890123
110110
GITLAB_BASE_URL=http://127.0.0.1:8080/api/v4
111111
TF_ACC=1
112112
```

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ resource "gitlab_project" "sample_group_project" {
5757

5858
The following arguments are supported in the `provider` block:
5959

60-
* `token` - (Optional) This is the GitLab personal access token. It must be provided, but
61-
it can also be sourced from the `GITLAB_TOKEN` environment variable.
60+
* `token` - (Required) The OAuth2 token or project/personal access token used to connect to GitLab.
61+
It must be provided, but it can also be sourced from the `GITLAB_TOKEN` environment variable.
6262

6363
* `base_url` - (Optional) This is the target GitLab base API endpoint. Providing a value is a
6464
requirement when working with GitLab CE or GitLab Enterprise e.g. `https://my.gitlab.server/api/v4/`.

gitlab/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func (c *Config) Client() (*gitlab.Client, error) {
6767
opts = append(opts, gitlab.WithBaseURL(c.BaseURL))
6868
}
6969

70-
client, err := gitlab.NewClient(c.Token, opts...)
70+
// The OAuth method is also compatible with project/personal access tokens because they are all usable as Bearer tokens.
71+
// https://docs.gitlab.com/ee/api
72+
client, err := gitlab.NewOAuthClient(c.Token, opts...)
7173
if err != nil {
7274
return nil, err
7375
}

gitlab/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var descriptions map[string]string
112112

113113
func init() {
114114
descriptions = map[string]string{
115-
"token": "The OAuth token used to connect to GitLab.",
115+
"token": "The OAuth2 token or project/personal access token used to connect to GitLab.",
116116

117117
"base_url": "The GitLab Base API URL",
118118

scripts/await-healthy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ echo
1111
echo 'GitLab is healthy'
1212

1313
# Print the version, since it is useful debugging information.
14-
curl --silent --show-error --header 'PRIVATE-TOKEN: ACCTEST' http://127.0.0.1:8080/api/v4/version
14+
curl --silent --show-error --header 'Authorization: Bearer ACCTEST1234567890123' http://127.0.0.1:8080/api/v4/version
1515
echo

scripts/healthcheck-and-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test -f $done || {
2424
printf 'user_id: 1, '
2525
printf 'scopes: [:api, :read_user], '
2626
printf 'name: :terraform);'
27-
printf "terraform_token.set_token('ACCTEST');"
27+
printf "terraform_token.set_token('ACCTEST1234567890123');"
2828
printf 'terraform_token.save!;'
2929
) | gitlab-rails console
3030

0 commit comments

Comments
 (0)