-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-agent-project-assignment-#914
- Loading branch information
Showing
24 changed files
with
501 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package client_test | ||
|
||
import ( | ||
. "github.com/env0/terraform-provider-env0/client" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("VCSToken", func() { | ||
vcsType := "github" | ||
repository := "http://myrepo.com/" | ||
|
||
mockVcsToken := VscToken{ | ||
Token: 12345, | ||
} | ||
|
||
Describe("get", func() { | ||
var ret *VscToken | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/vcs-token/"+vcsType, map[string]string{ | ||
"organizationId": organizationId, | ||
"repository": repository, | ||
}, gomock.Any()). | ||
Do(func(path string, request interface{}, response *VscToken) { | ||
*response = mockVcsToken | ||
}).Times(1) | ||
|
||
ret, err = apiClient.VcsToken(vcsType, repository) | ||
}) | ||
|
||
It("should return vcs token", func() { | ||
Expect(*ret).To(Equal(mockVcsToken)) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package client | ||
|
||
type VscToken struct { | ||
Token int `json:"token"` | ||
} | ||
|
||
func (client *ApiClient) VcsToken(vcsType string, repository string) (*VscToken, error) { | ||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result VscToken | ||
if err := client.http.Get("/vcs-token/"+vcsType, map[string]string{ | ||
"organizationId": organizationId, | ||
"repository": repository, | ||
}, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "env0_github_installation_id Data Source - terraform-provider-env0" | ||
subcategory: "" | ||
description: |- | ||
returns the github installation id of a git hub repositroy | ||
--- | ||
|
||
# env0_github_installation_id (Data Source) | ||
|
||
returns the github installation id of a git hub repositroy | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "env0_github_installation_id" "example" { | ||
repository = "https://github.com/env0/templates" | ||
} | ||
output "github_installation_id" { | ||
value = data.env0_github_installation_id.example.github_installation_id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `repository` (String) the name of the repository | ||
|
||
### Read-Only | ||
|
||
- `github_installation_id` (Number) the github installation id | ||
- `id` (String) The ID of this resource. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package env0 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/env0/terraform-provider-env0/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataGithubInstallationId() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "returns the github installation id of a git hub repositroy", | ||
|
||
ReadContext: dataGithubInstallationIdRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"repository": { | ||
Type: schema.TypeString, | ||
Description: "the name of the repository", | ||
Required: true, | ||
}, | ||
"github_installation_id": { | ||
Type: schema.TypeInt, | ||
Description: "the github installation id", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataGithubInstallationIdRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
apiClient := meta.(client.ApiClientInterface) | ||
|
||
repositroy := d.Get("repository").(string) | ||
|
||
token, err := apiClient.VcsToken("github", repositroy) | ||
if err != nil { | ||
return diag.Errorf("failed to get github installation id: %v", err) | ||
} | ||
|
||
d.Set("github_installation_id", token.Token) | ||
d.SetId(repositroy) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package env0 | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/env0/terraform-provider-env0/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestGithubInstallationIdDataSource(t *testing.T) { | ||
mockToken := client.VscToken{ | ||
Token: 12345, | ||
} | ||
|
||
mockRepositroy := "http://myrepo.com" | ||
|
||
resourceType := "env0_github_installation_id" | ||
resourceName := "test" | ||
accessor := dataSourceAccessor(resourceType, resourceName) | ||
|
||
getValidTestCase := func(repository string) resource.TestCase { | ||
return resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dataSourceConfigCreate(resourceType, resourceName, map[string]interface{}{ | ||
"repository": repository, | ||
}), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(accessor, "github_installation_id", strconv.Itoa(mockToken.Token)), | ||
), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
getErrorTestCase := func(repository string, expectedError string) resource.TestCase { | ||
return resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dataSourceConfigCreate(resourceType, resourceName, map[string]interface{}{ | ||
"repository": repository, | ||
}), | ||
ExpectError: regexp.MustCompile(expectedError), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
t.Run("get by repository", func(t *testing.T) { | ||
runUnitTest(t, | ||
getValidTestCase(mockRepositroy), | ||
func(mock *client.MockApiClientInterface) { | ||
mock.EXPECT().VcsToken("github", mockRepositroy).Return(&mockToken, nil).AnyTimes() | ||
}, | ||
) | ||
}) | ||
|
||
t.Run("get by repository - failed", func(t *testing.T) { | ||
runUnitTest(t, | ||
getErrorTestCase(mockRepositroy, "failed to get github installation id: error"), | ||
func(mock *client.MockApiClientInterface) { | ||
mock.EXPECT().VcsToken("github", mockRepositroy).Return(nil, errors.New("error")).AnyTimes() | ||
}, | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.