Skip to content

Commit 61e5af1

Browse files
authored
feat: allow repository to use bearer token for authentication (#714)
Signed-off-by: Nathanael Liechti <[email protected]>
1 parent 72d889d commit 61e5af1

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

docs/resources/repository.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ resource "argocd_repository" "private" {
4343

4444
### Optional
4545

46+
- `bearer_token` (String, Sensitive) BearerToken contains the bearer token used for Git BitBucket Data Center auth at the repo server
4647
- `enable_lfs` (Boolean) Whether `git-lfs` support should be enabled for this repository.
4748
- `enable_oci` (Boolean) Whether `helm-oci` support should be enabled for this repository.
4849
- `githubapp_enterprise_base_url` (String) GitHub API URL for GitHub app authentication.

internal/provider/model_repository.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type repositoryModel struct {
3434
GitHubAppInstallationID types.String `tfsdk:"githubapp_installation_id"`
3535
GitHubAppEnterpriseBaseURL types.String `tfsdk:"githubapp_enterprise_base_url"`
3636
GitHubAppPrivateKey types.String `tfsdk:"githubapp_private_key"`
37+
BearerToken types.String `tfsdk:"bearer_token"`
3738
}
3839

3940
func repositorySchemaAttributes() map[string]schema.Attribute {
@@ -75,6 +76,11 @@ func repositorySchemaAttributes() map[string]schema.Attribute {
7576
Optional: true,
7677
Sensitive: true,
7778
},
79+
"bearer_token": schema.StringAttribute{
80+
MarkdownDescription: "BearerToken contains the bearer token used for Git BitBucket Data Center auth at the repo server",
81+
Optional: true,
82+
Sensitive: true,
83+
},
7884
"ssh_private_key": schema.StringAttribute{
7985
MarkdownDescription: "PEM data for authenticating at the repo server. Only used with Git repos.",
8086
Optional: true,
@@ -143,6 +149,7 @@ func (m *repositoryModel) toAPIModel() (*v1alpha1.Repository, error) {
143149
Project: m.Project.ValueString(),
144150
Username: m.Username.ValueString(),
145151
Password: m.Password.ValueString(),
152+
BearerToken: m.BearerToken.ValueString(),
146153
SSHPrivateKey: m.SSHPrivateKey.ValueString(),
147154
TLSClientCertData: m.TLSClientCertData.ValueString(),
148155
TLSClientCertKey: m.TLSClientCertKey.ValueString(),

internal/provider/resource_repository_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,56 @@ func TestAccArgoCDRepository_GitHubAppConsistency(t *testing.T) {
225225
})
226226
}
227227

228+
// TestAccArgoCDRepository_BearerTokenConsistency tests consistency of bearer token field
229+
// Note: This test uses a Helm repository which doesn't require authentication but allows token auth
230+
func TestAccArgoCDRepository_BearerTokenConsistency(t *testing.T) {
231+
config := `
232+
resource "argocd_repository" "bearer_token" {
233+
repo = "https://helm.nginx.com/stable"
234+
type = "helm"
235+
bearer_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"
236+
}
237+
`
238+
239+
resource.Test(t, resource.TestCase{
240+
PreCheck: func() { testAccPreCheck(t) },
241+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
242+
Steps: []resource.TestStep{
243+
{
244+
Config: config,
245+
Check: resource.ComposeAggregateTestCheckFunc(
246+
resource.TestCheckResourceAttr(
247+
"argocd_repository.bearer_token",
248+
"bearer_token",
249+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30",
250+
),
251+
resource.TestCheckResourceAttr(
252+
"argocd_repository.bearer_token",
253+
"connection_state_status",
254+
"Successful",
255+
),
256+
),
257+
},
258+
{
259+
// Apply the same configuration again to test for consistency
260+
Config: config,
261+
Check: resource.ComposeAggregateTestCheckFunc(
262+
resource.TestCheckResourceAttr(
263+
"argocd_repository.bearer_token",
264+
"bearer_token",
265+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30",
266+
),
267+
resource.TestCheckResourceAttr(
268+
"argocd_repository.bearer_token",
269+
"connection_state_status",
270+
"Successful",
271+
),
272+
),
273+
},
274+
},
275+
})
276+
}
277+
228278
// TestAccArgoCDRepository_UsernamePasswordConsistency tests consistency of username/password fields
229279
// Note: This test uses a Helm repository which doesn't require authentication but allows username/password fields
230280
func TestAccArgoCDRepository_UsernamePasswordConsistency(t *testing.T) {

0 commit comments

Comments
 (0)