Skip to content

Commit

Permalink
Fix Gitlab retriever configuration for relay proxy (#1243)
Browse files Browse the repository at this point in the history
* fix doc for Gitlab

Signed-off-by: Thomas Poignant <[email protected]>

* Fix config and encoding issues

Signed-off-by: Thomas Poignant <[email protected]>

---------

Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant authored Nov 12, 2023
1 parent e95722f commit 903cdaa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
3 changes: 0 additions & 3 deletions cmd/relayproxy/config/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ func (c *RetrieverConf) IsValid() error {
if c.Kind == GitHubRetriever && c.RepositorySlug == "" {
return fmt.Errorf("invalid retriever: no \"repositorySlug\" property found for kind \"%s\"", c.Kind)
}
if c.Kind == GitlabRetriever && c.URL == "" {
return fmt.Errorf("invalid retriever: no \"URL\" property found for kind \"%s\"", c.Kind)
}
if c.Kind == GitlabRetriever && c.RepositorySlug == "" {
return fmt.Errorf("invalid retriever: no \"repositorySlug\" property found for kind \"%s\"", c.Kind)
}
Expand Down
8 changes: 0 additions & 8 deletions cmd/relayproxy/config/retriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ func TestRetrieverConf_IsValid(t *testing.T) {
wantErr: true,
errValue: "invalid retriever: no \"repositorySlug\" property found for kind \"github\"",
},
{
name: "kind GitlabRetriever without URL slug",
fields: config.RetrieverConf{
Kind: "gitlab",
},
wantErr: true,
errValue: "invalid retriever: no \"URL\" property found for kind \"gitlab\"",
},
{
name: "kind GitlabRetriever, with URL but without path",
fields: config.RetrieverConf{
Expand Down
18 changes: 7 additions & 11 deletions retriever/gitlabretriever/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

httpretriever "github.com/thomaspoignant/go-feature-flag/retriever/httpretriever"
Expand Down Expand Up @@ -52,22 +53,17 @@ func (r *Retriever) Retrieve(ctx context.Context) ([]byte, error) {
r.BaseURL = "https://gitlab.com"
}

parsedURL, err := url.Parse(r.BaseURL)
if err != nil {
return nil, fmt.Errorf("impossible to parse the param baseUrl %s", err)
}
parsedURL.Path, err = url.JoinPath(
parsedURL.Path,
"api/v4/projects",
path := strings.Join([]string{
r.BaseURL, "api/v4/projects",
url.QueryEscape(r.RepositorySlug),
"repository/files",
url.QueryEscape(r.FilePath),
)
url.QueryEscape(r.FilePath), "raw"}, "/")

parsedURL, err := url.Parse(path)
if err != nil {
return nil, fmt.Errorf("impossible to parse the param baseUrl %s", err)
return nil, fmt.Errorf("impossible to parse the url %s", err)
}

// add branch as
rawQuery := parsedURL.Query()
rawQuery.Set("ref", branch)
parsedURL.RawQuery = rawQuery.Encode()
Expand Down
18 changes: 9 additions & 9 deletions website/docs/relay_proxy/configure_relay_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ In this section we will present all the available retriever configuration availa

### GitLab

| Field name | Type | Default | Description |
|------------------|--------|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `kind` | string | **none** | **(mandatory)** Value should be **`gitlab`**.<br/>_This field is mandatory and describe which retriever you are using._ |
| `repositorySlug` | string | **none** | **(mandatory)** The repository slug of the GitHub repository where your file is located _(ex: `thomaspoignant/go-feature-flag`)_. |
| `path` | string | **none** | **(mandatory)** Path to the file inside the repository _(ex: `config/flag/my-flags.yaml`)_. |
| `baseUrl` | string | `https://gitlab.com` | The base URL of your Gitlab instance. |
| `branch` | string | `main` | The branch we should check in the repository. |
| `token` | string | **none** | Github token is used to access a private repository, you need the repo permission ([how to create a GitHub token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)). |
| `timeout` | string | `10000` | Timeout in millisecond used when calling GitHub. |
| Field name | Type | Default | Description |
|------------------|--------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `kind` | string | **none** | **(mandatory)** Value should be **`gitlab`**.<br/>_This field is mandatory and describe which retriever you are using._ |
| `repositorySlug` | string | **none** | **(mandatory)** The repository slug of the Gitlab repository where your file is located _(ex: `thomaspoignant/go-feature-flag`)_. |
| `path` | string | **none** | **(mandatory)** Path to the file inside the repository _(ex: `config/flag/my-flags.yaml`)_. |
| `baseUrl` | string | `https://gitlab.com` | The base URL of your Gitlab instance. |
| `branch` | string | `main` | The branch we should check in the repository. |
| `token` | string | **none** | Gitlab personal access token used to access a private repository ([Create a personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token)). |
| `timeout` | string | `10000` | Timeout in millisecond used when calling Gitlab. |


### File
Expand Down

0 comments on commit 903cdaa

Please sign in to comment.