Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s3): fix s3 credentials secret retrieval #491

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ovh/data_cloud_project_user_s3_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func dataCloudProjectUserS3CredentialRead(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] Will read public cloud secret access key for access key %s user %s on project: %s", accessKey, userID, serviceName)

endpoint := fmt.Sprintf(
"/cloud/project/%s/user/%s/s3Credentials/%s",
"/cloud/project/%s/user/%s/s3Credentials/%s/secret",
url.PathEscape(serviceName),
url.PathEscape(userID),
url.PathEscape(accessKey),
)

s3Credential := &CloudProjectUserS3Credential{}
if err := config.OVHClient.Get(endpoint, &s3Credential); err != nil {
s3Credential := &CloudProjectUserS3CredentialSecret{}
if err := config.OVHClient.Post(endpoint, nil, &s3Credential); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}

Expand Down
10 changes: 4 additions & 6 deletions ovh/resource_cloud_project_user_s3_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceCloudProjectUserS3CredentialCreate(d *schema.ResourceData, meta int
serviceName := d.Get("service_name").(string)
userID := d.Get("user_id").(string)

s3Credential := &CloudProjectUserS3Credential{}
s3Credential := &CloudProjectUserS3CredentialSecret{}

log.Printf("[DEBUG] Will create Public Cloud S3 AccessKey for user: %s from project: %s", userID, serviceName)
endpoint := fmt.Sprintf(
Expand All @@ -94,7 +94,6 @@ func resourceCloudProjectUserS3CredentialCreate(d *schema.ResourceData, meta int
}

d.SetId(s3Credential.Access)
d.Set("secret_access_key", s3Credential.Secret)
for k, v := range s3Credential.ToMap() {
d.Set(k, v)
}
Expand All @@ -109,22 +108,21 @@ func resourceCloudProjectUserS3CredentialRead(d *schema.ResourceData, meta inter
serviceName := d.Get("service_name").(string)
userID := d.Get("user_id").(string)

s3Credential := &CloudProjectUserS3Credential{}
s3Credential := &CloudProjectUserS3CredentialSecret{}

log.Printf("[DEBUG] Will read the Public Cloud S3 AccessKey %s for user %s from project: %s", d.Id(), userID, serviceName)

endpoint := fmt.Sprintf(
"/cloud/project/%s/user/%s/s3Credentials/%s",
"/cloud/project/%s/user/%s/s3Credentials/%s/secret",
url.PathEscape(serviceName),
userID,
d.Id(),
)

if err := config.OVHClient.Get(endpoint, s3Credential); err != nil {
if err := config.OVHClient.Post(endpoint, nil, s3Credential); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}

d.SetId(s3Credential.Access)
// set resource attributes
for k, v := range s3Credential.ToMap() {
d.Set(k, v)
Expand Down
33 changes: 31 additions & 2 deletions ovh/types_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,53 @@ type CloudProjectUserOpenstackRC struct {

type CloudProjectUserS3Credential struct {
Access string `json:"access"`
Secret string `json:"secret"`
ServiceName string `json:"tenantId"`
UserId string `json:"userId"`
}

type CloudProjectUserS3Secret struct {
Secret string `json:"secret"`
}

type CloudProjectUserS3CredentialSecret struct {
CloudProjectUserS3Credential
CloudProjectUserS3Secret
}

func (u *CloudProjectUserS3Credential) String() string {
return fmt.Sprintf("CloudProjectUserS3Credential[ServiceName:%s, UserId: %s, Access: %s]", u.ServiceName, u.UserId, u.Access)
}

func (u CloudProjectUserS3Credential) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["access_key_id"] = u.Access
obj["secret_access_key"] = u.Secret
obj["service_name"] = u.ServiceName
obj["internal_user_id"] = u.UserId
return obj
}

func (u *CloudProjectUserS3Secret) String() string {
return "CloudProjectUserS3Secret[Secret: ***]"
}

func (u CloudProjectUserS3Secret) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["secret_access_key"] = u.Secret
return obj
}

func (u *CloudProjectUserS3CredentialSecret) String() string {
return fmt.Sprintf("CloudProjectUserS3CredentialSecret[ServiceName:%s, UserId: %s, Access: %s, Secret: ***]", u.ServiceName, u.UserId, u.Access)
}

func (u CloudProjectUserS3CredentialSecret) ToMap() map[string]interface{} {
obj := u.CloudProjectUserS3Credential.ToMap()
for k, v := range u.CloudProjectUserS3Secret.ToMap() {
obj[k] = v
}
return obj
}

type CloudProjectRegionResponse struct {
ContinentCode string `json:"continentCode"`
DatacenterLocation string `json:"datacenterLocation"`
Expand Down