Skip to content

Commit

Permalink
chore(servicestage/auth): host parameter is no longer required (#6079)
Browse files Browse the repository at this point in the history
* chore(servicestage/auth): remove the validation definition

* chore(servicestage/auth): update the behavior of host param
  • Loading branch information
Lance52259 authored Dec 24, 2024
1 parent 0fd6ae1 commit 68dcbb7
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 47 deletions.
12 changes: 6 additions & 6 deletions docs/resources/servicestage_repo_token_authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ token with various types of the Open-Source repository.
## Example Usage

```hcl
variable "authorization_name"
variable "repository_host"
variable "personal_access_token"
variable "authorization_name" {}
variable "personal_access_token" {}
resource "huaweicloud_servicestage_repo_token_authorization" "test" {
type = "github"
name = var.authorization_name
host = var.repository_host
token = var.personal_access_token
}
```
Expand All @@ -43,11 +41,13 @@ The following arguments are supported:

Changing this parameter will create a new authorization.

* `host` - (Required, String, ForceNew) Specified the host name of the repository.
* `token` - (Required, String, ForceNew) Specified the personal access token of the repository.
Changing this parameter will create a new authorization.

* `token` - (Required, String, ForceNew) Specified the personal access token of the repository.
<!-- markdownlint-disable MD034 -->
* `host` - (Optional, String, ForceNew) Specified the host name of the repository, e.g. **https://api.github.com**.
Changing this parameter will create a new authorization.
<!-- markdownlint-enable MD034 -->

## Attribute Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
github.com/chnsz/golangsdk v0.0.0-20241224015804-3881691a8961
github.com/chnsz/golangsdk v0.0.0-20241224061204-e794f144e5ec
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chnsz/golangsdk v0.0.0-20241224015804-3881691a8961 h1:fz4oQHt1QyL3r5sP1sHNiwysBqyk7Z+Paq5mGothiRw=
github.com/chnsz/golangsdk v0.0.0-20241224015804-3881691a8961/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/chnsz/golangsdk v0.0.0-20241224061204-e794f144e5ec h1:TzFxp/PH01bwLEDRrIEgTCffn+BqasKT8QGw1B2OeYI=
github.com/chnsz/golangsdk v0.0.0-20241224061204-e794f144e5ec/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
5 changes: 2 additions & 3 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ var (
HW_DLI_FLINK_STREAM_GRAPH = os.Getenv("HW_DLI_FLINK_STREAM_GRAPH")
HW_DLI_ELASTIC_RESOURCE_POOL = os.Getenv("HW_DLI_ELASTIC_RESOURCE_POOL")

HW_GITHUB_REPO_HOST = os.Getenv("HW_GITHUB_REPO_HOST") // Repository host (Github, Gitlab, Gitee)
HW_GITHUB_PERSONAL_TOKEN = os.Getenv("HW_GITHUB_PERSONAL_TOKEN") // Personal access token (Github, Gitlab, Gitee)
HW_GITHUB_REPO_PWD = os.Getenv("HW_GITHUB_REPO_PWD") // Repository password (DevCloud, BitBucket)
HW_GITHUB_REPO_URL = os.Getenv("HW_GITHUB_REPO_URL") // Repository URL (Github, Gitlab, Gitee)
Expand Down Expand Up @@ -1254,8 +1253,8 @@ func TestAccPreCheckDliElasticResourcePool(t *testing.T) {

// lintignore:AT003
func TestAccPreCheckRepoTokenAuth(t *testing.T) {
if HW_GITHUB_REPO_HOST == "" || HW_GITHUB_PERSONAL_TOKEN == "" {
t.Skip("Repository configurations are not completed for acceptance test of personal access token authorization.")
if HW_GITHUB_PERSONAL_TOKEN == "" {
t.Skip("HW_GITHUB_PERSONAL_TOKEN must be set for token authorization test within ServiceStage.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,9 @@ resource "huaweicloud_cce_node" "test" {
resource "huaweicloud_servicestage_repo_token_authorization" "test" {
type = "github"
name = "%[1]s"
host = "%[2]s"
token = "%[3]s"
token = "%[2]s"
}
`, rName, acceptance.HW_GITHUB_REPO_HOST, acceptance.HW_GITHUB_PERSONAL_TOKEN)
`, rName, acceptance.HW_GITHUB_PERSONAL_TOKEN)
}

func testAccComponent_web(rName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func getAuthResourceFunc(conf *config.Config, state *terraform.ResourceState) (i

func TestAccRepoTokenAuth_basic(t *testing.T) {
var (
auth repositories.Authorization
randName = acceptance.RandomAccResourceNameWithDash()
resourceName = "huaweicloud_servicestage_repo_token_authorization.test"
)
auth interface{}

name = acceptance.RandomAccResourceNameWithDash()

rc := acceptance.InitResourceCheck(
resourceName,
&auth,
getAuthResourceFunc,
withHost = "huaweicloud_servicestage_repo_token_authorization.with_host"
withoutHost = "huaweicloud_servicestage_repo_token_authorization.without_host"

rcWithHost = acceptance.InitResourceCheck(withHost, &auth, getAuthResourceFunc)
rcWithoutHost = acceptance.InitResourceCheck(withoutHost, &auth, getAuthResourceFunc)
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -50,36 +50,58 @@ func TestAccRepoTokenAuth_basic(t *testing.T) {
acceptance.TestAccPreCheckRepoTokenAuth(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
CheckDestroy: resource.ComposeTestCheckFunc(
rcWithHost.CheckResourceDestroy(),
rcWithoutHost.CheckResourceDestroy(),
),
Steps: []resource.TestStep{
{
Config: testAccRepoTokenAuth_basic(randName),
Config: testAccRepoTokenAuth_basic(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", randName),
resource.TestCheckResourceAttr(resourceName, "type", "github"),
rcWithHost.CheckResourceExists(),
resource.TestCheckResourceAttr(withHost, "name", name+"-with-host"),
resource.TestCheckResourceAttr(withHost, "type", "github"),
resource.TestCheckResourceAttr(withHost, "host", "https://api.github.com"),
rcWithoutHost.CheckResourceExists(),
resource.TestCheckResourceAttr(withoutHost, "name", name+"-without-host"),
resource.TestCheckResourceAttr(withoutHost, "type", "github"),
resource.TestCheckNoResourceAttr(withoutHost, "host"),
),
},
{
ResourceName: resourceName,
ResourceName: withHost,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"token",
"host",
},
},
{
ResourceName: withoutHost,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"token",
},
},
},
})
}

func testAccRepoTokenAuth_basic(rName string) string {
return fmt.Sprintf(`
resource "huaweicloud_servicestage_repo_token_authorization" "test" {
resource "huaweicloud_servicestage_repo_token_authorization" "with_host" {
type = "github"
name = "%[1]s-with-host"
token = "%[2]s"
host = "https://api.github.com"
}
resource "huaweicloud_servicestage_repo_token_authorization" "without_host" {
type = "github"
name = "%s"
host = "%s"
token = "%s"
name = "%[1]s-without-host"
token = "%[2]s"
}
`, rName, acceptance.HW_GITHUB_REPO_HOST, acceptance.HW_GITHUB_PERSONAL_TOKEN)
`, rName, acceptance.HW_GITHUB_PERSONAL_TOKEN)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/chnsz/golangsdk"
"github.com/chnsz/golangsdk/openstack/servicestage/v1/repositories"
Expand Down Expand Up @@ -46,21 +45,19 @@ func ResourceRepoTokenAuth() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"github", "gitlab", "gitee",
}, false),
},
"host": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"token": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
},
"host": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
// Have not setting code, computed is unnecessary.
},
},
}
}
Expand All @@ -75,8 +72,8 @@ func resourceRepoTokenAuthCreate(ctx context.Context, d *schema.ResourceData, me

opt := repositories.PersonalAuthOpts{
Name: d.Get("name").(string),
Host: d.Get("host").(string),
Token: d.Get("token").(string),
Host: d.Get("host").(string),
}
auth, err := repositories.CreatePersonalAuth(client, d.Get("type").(string), opt)
if err != nil {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/apparentlymart/go-cidr/cidr
# github.com/apparentlymart/go-textseg/v13 v13.0.0
## explicit; go 1.16
github.com/apparentlymart/go-textseg/v13/textseg
# github.com/chnsz/golangsdk v0.0.0-20241224015804-3881691a8961
# github.com/chnsz/golangsdk v0.0.0-20241224061204-e794f144e5ec
## explicit; go 1.14
github.com/chnsz/golangsdk
github.com/chnsz/golangsdk/auth
Expand Down

0 comments on commit 68dcbb7

Please sign in to comment.