Skip to content

Commit

Permalink
Clean up unneeded parameters (#324)
Browse files Browse the repository at this point in the history
There are some OpenStack parameters which is not
valid for Huawei Cloud. This tries to clean up them.
  • Loading branch information
niuzhenguo authored May 27, 2020
1 parent 073c551 commit e5d9a67
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 97 deletions.
53 changes: 4 additions & 49 deletions huaweicloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
"github.com/huaweicloud/golangsdk"
huaweisdk "github.com/huaweicloud/golangsdk/openstack"
"github.com/huaweicloud/golangsdk/openstack/objectstorage/v1/swauth"
"github.com/huaweicloud/golangsdk/openstack/obs"
)

Expand All @@ -37,18 +36,15 @@ type Config struct {
Cloud string
DomainID string
DomainName string
EndpointType string
IdentityEndpoint string
Insecure bool
Password string
Region string
Swauth bool
TenantID string
TenantName string
Token string
Username string
UserID string
useOctavia bool
AgencyName string
AgencyDomainName string
DelegatedProject string
Expand All @@ -61,24 +57,6 @@ type Config struct {
}

func (c *Config) LoadAndValidate() error {
validEndpoint := false
validEndpoints := []string{
"internal", "internalURL",
"admin", "adminURL",
"public", "publicURL",
"",
}

for _, endpoint := range validEndpoints {
if c.EndpointType == endpoint {
validEndpoint = true
}
}

if !validEndpoint {
return fmt.Errorf("Invalid endpoint type provided")
}

err := fmt.Errorf("Must config token or aksk or username password to be authorized")

if c.Token != "" {
Expand Down Expand Up @@ -178,12 +156,10 @@ func genClient(c *Config, ao golangsdk.AuthOptionsProvider) (*golangsdk.Provider
},
}

// If using Swift Authentication, there's no need to validate authentication normally.
if !c.Swauth {
err = huaweisdk.Authenticate(client, ao)
if err != nil {
return nil, err
}
// Validate authentication normally.
err = huaweisdk.Authenticate(client, ao)
if err != nil {
return nil, err
}

return client, nil
Expand Down Expand Up @@ -527,21 +503,6 @@ func (c *Config) cciV1Client(region string) (*golangsdk.ServiceClient, error) {
})
}

func (c *Config) objectStorageV1Client(region string) (*golangsdk.ServiceClient, error) {
// If Swift Authentication is being used, return a swauth client.
if c.Swauth {
return swauth.NewObjectStorageV1(c.HwClient, swauth.AuthOpts{
User: c.Username,
Key: c.Password,
})
}

return huaweisdk.NewObjectStorageV1(c.HwClient, golangsdk.EndpointOpts{
Region: c.determineRegion(region),
Availability: c.getHwEndpointType(),
})
}

func (c *Config) loadBalancerV2Client(region string) (*golangsdk.ServiceClient, error) {
return huaweisdk.NewLoadBalancerV2(c.HwClient, golangsdk.EndpointOpts{
Region: c.determineRegion(region),
Expand Down Expand Up @@ -603,12 +564,6 @@ func (c *Config) loadIAMV3Client(region string) (*golangsdk.ServiceClient, error
}

func (c *Config) getHwEndpointType() golangsdk.Availability {
if c.EndpointType == "internal" || c.EndpointType == "internalURL" {
return golangsdk.AvailabilityInternal
}
if c.EndpointType == "admin" || c.EndpointType == "adminURL" {
return golangsdk.AvailabilityAdmin
}
return golangsdk.AvailabilityPublic
}

Expand Down
3 changes: 0 additions & 3 deletions huaweicloud/lb_v2_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@ func waitForLBV2viaPool(networkingClient *golangsdk.ServiceClient, id string, ta
}

func chooseLBV2Client(d *schema.ResourceData, config *Config) (*golangsdk.ServiceClient, error) {
if config.useOctavia {
return config.loadBalancerV2Client(GetRegion(d, config))
}
return config.networkingV2Client(GetRegion(d, config))
}

Expand Down
31 changes: 0 additions & 31 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["insecure"],
},

"endpoint_type": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""),
},

"cacert_file": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -147,20 +141,6 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["key"],
},

"swauth": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("OS_SWAUTH", false),
Description: descriptions["swauth"],
},

"use_octavia": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("OS_USE_OCTAVIA", false),
Description: descriptions["use_octavia"],
},

"cloud": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -393,18 +373,10 @@ func init() {

"cacert_file": "A Custom CA certificate.",

"endpoint_type": "The catalog endpoint type to use.",

"cert": "A client certificate to authenticate with.",

"key": "A client private key to authenticate with.",

"swauth": "Use Swift's authentication system instead of Keystone. Only used for\n" +
"interaction with Swift.",

"use_octavia": "If set to `true`, API requests will go the Load Balancer\n" +
"service (Octavia) instead of the Networking service (Neutron).",

"cloud": "An entry in a `clouds.yaml` file to use.",

"agency_name": "The name of agency",
Expand All @@ -425,18 +397,15 @@ func configureProvider(d *schema.ResourceData, terraformVersion string) (interfa
Cloud: d.Get("cloud").(string),
DomainID: d.Get("domain_id").(string),
DomainName: d.Get("domain_name").(string),
EndpointType: d.Get("endpoint_type").(string),
IdentityEndpoint: d.Get("auth_url").(string),
Insecure: d.Get("insecure").(bool),
Password: d.Get("password").(string),
Region: d.Get("region").(string),
Swauth: d.Get("swauth").(bool),
Token: d.Get("token").(string),
TenantID: d.Get("tenant_id").(string),
TenantName: d.Get("tenant_name").(string),
Username: d.Get("user_name").(string),
UserID: d.Get("user_id").(string),
useOctavia: d.Get("use_octavia").(bool),
AgencyName: d.Get("agency_name").(string),
AgencyDomainName: d.Get("agency_domain_name").(string),
DelegatedProject: d.Get("delegated_project").(string),
Expand Down
14 changes: 0 additions & 14 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,6 @@ The following arguments are supported:
authentication. You can specify either a path to the file or the contents of
the key. If omitted the `OS_KEY` environment variable is used.

* `endpoint_type` - (Optional) Specify which type of endpoint to use from the
service catalog. It can be set using the OS_ENDPOINT_TYPE environment
variable. If not set, public endpoints is used.

* `swauth` - (Optional) Set to `true` to authenticate against Swauth, a
Swift-native authentication system. If omitted, the `OS_SWAUTH` environment
variable is used. You must also set `username` to the Swauth/Swift username
such as `username:project`. Set the `password` to the Swauth/Swift key.
Finally, set `auth_url` as the location of the Swift service. Note that this
will only work when used with the HuaweiCloud Object Storage resources.

* `use_octavia` - (Optional) If set to `true`, API requests will go the Load Balancer
service (Octavia) instead of the Networking service (Neutron).

* `agency_name` - (Optional) if authorized by assume role, it must be set. The
name of agency.

Expand Down

0 comments on commit e5d9a67

Please sign in to comment.