-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from datadrivers/feat/258/gitlfs
feat(repository): Add resource and data source for hosted gitlfs repository
- Loading branch information
Showing
11 changed files
with
466 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
page_title: "Data Source nexus_repository_gitlfs_hosted" | ||
subcategory: "Repository" | ||
description: |- | ||
Use this data source to get an existing hosted yum repository. | ||
--- | ||
# Data Source nexus_repository_gitlfs_hosted | ||
Use this data source to get an existing hosted yum repository. | ||
## Example Usage | ||
```terraform | ||
data "nexus_repository_gitlfs_hosted" "internal" { | ||
name = "gitlfs-internal" | ||
} | ||
``` | ||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) A unique identifier for this repository | ||
|
||
### Read-Only | ||
|
||
- `cleanup` (List of Object) Cleanup policies (see [below for nested schema](#nestedatt--cleanup)) | ||
- `component` (List of Object) Component configuration for the hosted repository (see [below for nested schema](#nestedatt--component)) | ||
- `id` (String) Used to identify data source at nexus | ||
- `online` (Boolean) Whether this repository accepts incoming requests | ||
- `storage` (List of Object) The storage configuration of the repository (see [below for nested schema](#nestedatt--storage)) | ||
|
||
<a id="nestedatt--cleanup"></a> | ||
### Nested Schema for `cleanup` | ||
|
||
Read-Only: | ||
|
||
- `policy_names` (Set of String) | ||
|
||
|
||
<a id="nestedatt--component"></a> | ||
### Nested Schema for `component` | ||
|
||
Read-Only: | ||
|
||
- `proprietary_components` (Boolean) | ||
|
||
|
||
<a id="nestedatt--storage"></a> | ||
### Nested Schema for `storage` | ||
|
||
Read-Only: | ||
|
||
- `blob_store_name` (String) | ||
- `strict_content_type_validation` (Boolean) | ||
- `write_policy` (String) |
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,72 @@ | ||
--- | ||
page_title: "Resource nexus_repository_gitlfs_hosted" | ||
subcategory: "Repository" | ||
description: |- | ||
Use this resource to create a hosted gitlfs repository. | ||
--- | ||
# Resource nexus_repository_gitlfs_hosted | ||
Use this resource to create a hosted gitlfs repository. | ||
## Example Usage | ||
```terraform | ||
resource "nexus_repository_gitlfs_hosted" "internal" { | ||
name = "gitlfs-internal" | ||
online = true | ||
storage { | ||
blob_store_name = "default" | ||
strict_content_type_validation = false | ||
write_policy = "ALLOW" | ||
} | ||
} | ||
``` | ||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) A unique identifier for this repository | ||
- `storage` (Block List, Min: 1, Max: 1) The storage configuration of the repository (see [below for nested schema](#nestedblock--storage)) | ||
|
||
### Optional | ||
|
||
- `cleanup` (Block List) Cleanup policies (see [below for nested schema](#nestedblock--cleanup)) | ||
- `component` (Block List, Max: 1) Component configuration for the hosted repository (see [below for nested schema](#nestedblock--component)) | ||
- `online` (Boolean) Whether this repository accepts incoming requests | ||
|
||
### Read-Only | ||
|
||
- `id` (String) Used to identify resource at nexus | ||
|
||
<a id="nestedblock--storage"></a> | ||
### Nested Schema for `storage` | ||
|
||
Required: | ||
|
||
- `blob_store_name` (String) Blob store used to store repository contents | ||
- `strict_content_type_validation` (Boolean) Whether to validate uploaded content's MIME type appropriate for the repository format | ||
|
||
Optional: | ||
|
||
- `write_policy` (String) Controls if deployments of and updates to assets are allowed | ||
|
||
|
||
<a id="nestedblock--cleanup"></a> | ||
### Nested Schema for `cleanup` | ||
|
||
Optional: | ||
|
||
- `policy_names` (Set of String) List of policy names | ||
|
||
|
||
<a id="nestedblock--component"></a> | ||
### Nested Schema for `component` | ||
|
||
Required: | ||
|
||
- `proprietary_components` (Boolean) Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) | ||
## Import | ||
Import is supported using the following syntax: | ||
```shell | ||
# import using the name of repository | ||
terraform import nexus_repository_gitlfs_hosted.internal gitlfs-internal | ||
``` |
3 changes: 3 additions & 0 deletions
3
examples/data-sources/nexus_repository_gitlfs_hosted/data-source.tf
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,3 @@ | ||
data "nexus_repository_gitlfs_hosted" "internal" { | ||
name = "gitlfs-internal" | ||
} |
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,2 @@ | ||
# import using the name of repository | ||
terraform import nexus_repository_gitlfs_hosted.internal gitlfs-internal |
10 changes: 10 additions & 0 deletions
10
examples/resources/nexus_repository_gitlfs_hosted/resource.tf
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,10 @@ | ||
resource "nexus_repository_gitlfs_hosted" "internal" { | ||
name = "gitlfs-internal" | ||
online = true | ||
|
||
storage { | ||
blob_store_name = "default" | ||
strict_content_type_validation = false | ||
write_policy = "ALLOW" | ||
} | ||
} |
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,7 @@ | ||
package acceptance | ||
|
||
const ( | ||
TemplateStringRepositoryGitlfsHosted = ` | ||
resource "nexus_repository_gitlfs_hosted" "acceptance" { | ||
` + TemplateStringHostedRepository | ||
) |
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
31 changes: 31 additions & 0 deletions
31
internal/services/repository/data_source_repository_gitlfs_hosted.go
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,31 @@ | ||
package repository | ||
|
||
import ( | ||
"github.com/datadrivers/terraform-provider-nexus/internal/schema/common" | ||
"github.com/datadrivers/terraform-provider-nexus/internal/schema/repository" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceRepositoryGitlfsHosted() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Use this data source to get an existing hosted yum repository.", | ||
|
||
Read: dataSourceRepositoryGitlfsHostedRead, | ||
Schema: map[string]*schema.Schema{ | ||
// Common schemas | ||
"id": common.DataSourceID, | ||
"name": repository.DataSourceName, | ||
"online": repository.DataSourceOnline, | ||
// Hosted schemas | ||
"cleanup": repository.DataSourceCleanup, | ||
"component": repository.DataSourceComponent, | ||
"storage": repository.DataSourceHostedStorage, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRepositoryGitlfsHostedRead(d *schema.ResourceData, m interface{}) error { | ||
d.SetId(d.Get("name").(string)) | ||
|
||
return resourceGitlfsHostedRepositoryRead(d, m) | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/services/repository/data_source_repository_gitlfs_hosted_test.go
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,50 @@ | ||
package repository_test | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/datadrivers/go-nexus-client/nexus3/schema/repository" | ||
"github.com/datadrivers/terraform-provider-nexus/internal/acceptance" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func testAccDataSourceRepositoryGitlfsHostedConfig() string { | ||
return ` | ||
data "nexus_repository_gitlfs_hosted" "acceptance" { | ||
name = nexus_repository_gitlfs_hosted.acceptance.id | ||
}` | ||
} | ||
|
||
func TestAccDataSourceRepositoryGitlfsHosted(t *testing.T) { | ||
repoUsingDefaults := repository.GitLfsHostedRepository{ | ||
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)), | ||
Online: true, | ||
Storage: repository.HostedStorage{ | ||
BlobStoreName: "default", | ||
StrictContentTypeValidation: false, | ||
}, | ||
} | ||
dataSourceName := "data.nexus_repository_gitlfs_hosted.acceptance" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.AccPreCheck(t) }, | ||
Providers: acceptance.TestAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceRepositoryGitlfsHostedConfig(repoUsingDefaults) + testAccDataSourceRepositoryGitlfsHostedConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "id", repoUsingDefaults.Name), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", repoUsingDefaults.Name), | ||
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repoUsingDefaults.Online)), | ||
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repoUsingDefaults.Storage.BlobStoreName), | ||
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repoUsingDefaults.Storage.StrictContentTypeValidation)), | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.