Skip to content

Commit

Permalink
Gitlab enterprise repo optional token (#72)
Browse files Browse the repository at this point in the history
* make gitlab enterprise resource token argument be optional so creds will be created only if token is provided
  • Loading branch information
amiros89 authored Sep 26, 2024
1 parent 651db5c commit ac8685c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ type RepoSpaceAssociation struct {
}

type GitlabEnterpriseRepoSpaceAssociation struct {
Name string `json:"repository_name"`
URL string `json:"repository_url"`
Token string `json:"token"`
Branch string `json:"branch"`
CredentialName string `json:"credential_name"`
Name string `json:"repository_name"`
URL string `json:"repository_url"`
Token *string `json:"token"`
Branch string `json:"branch"`
CredentialName string `json:"credential_name"`
}

type CodeCommitRepoSpaceAssociation struct {
Expand Down
2 changes: 1 addition & 1 deletion client/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Client) OnboardCodeCommitRepoToSpace(space_name string, repository_name
return nil
}

func (c *Client) OnboardGitlabEnterpriseRepoToSpace(space_name string, repository_name string, repository_url string, token string, branch string, credential_name string) error {
func (c *Client) OnboardGitlabEnterpriseRepoToSpace(space_name string, repository_name string, repository_url string, token *string, branch string, credential_name string) error {
data := GitlabEnterpriseRepoSpaceAssociation{
Token: token,
Name: repository_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ resource "torque_gitlab_enterprise_repository_space_association" "repository" {
- `repository_name` (String) The name of the GitlabEnterprise repository to onboard. In this example, repo_name
- `repository_url` (String) The url of the specific GitlabEnterprise repository/project to onboard. For example: https://gitlab-on-prem.example.com/repo_name
- `space_name` (String) Existing Torque Space name
- `token` (String) Authentication Token to the project/repository

### Optional

- `token` (String) Authentication Token to the project/repository. If omitted, existing credentials provided in the credential_name field will be used for authentication. If provided, a new credentials object will be created.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (r *TorqueSpaceGitlabEnterpriseRepositoryResource) Schema(ctx context.Conte
},
},
"token": schema.StringAttribute{
Description: "Authentication Token to the project/repository",
Required: true,
Description: "Authentication Token to the project/repository. If omitted, existing credentials provided in the credential_name field will be used for authentication. If provided, a new credentials object will be created.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down Expand Up @@ -121,7 +121,7 @@ func (r *TorqueSpaceGitlabEnterpriseRepositoryResource) Create(ctx context.Conte
}

err := r.client.OnboardGitlabEnterpriseRepoToSpace(data.SpaceName.ValueString(), data.RepositoryName.ValueString(),
data.RepositoryUrl.ValueString(), data.Token.ValueString(), data.Branch.ValueString(), data.CredentialName.ValueString())
data.RepositoryUrl.ValueString(), data.Token.ValueStringPointer(), data.Branch.ValueString(), data.CredentialName.ValueString())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to onboard repository to space, got error: %s", err))
return
Expand Down

0 comments on commit ac8685c

Please sign in to comment.