From fd3c1884dff99d334af77d5a1e1342761c83a558 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 19 Apr 2022 21:22:28 +0100 Subject: [PATCH] Update to Hamilton v0.44.0 and go-azure-helpers v0.28.0. Closes #16291 --- go.mod | 2 +- go.sum | 3 +- .../hamilton/environments/endpoints.go | 2 +- .../manicminer/hamilton/msgraph/models.go | 2 + .../hamilton/msgraph/serviceprincipals.go | 65 +++++++++++++++++++ vendor/modules.txt | 2 +- 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index df98ada780c5..eaaa14830c49 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/hashicorp/go-version v1.3.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 github.com/magodo/terraform-provider-azurerm-example-gen v0.0.0-20220407025246-3a3ee0ab24a8 - github.com/manicminer/hamilton v0.43.0 + github.com/manicminer/hamilton v0.44.0 github.com/mitchellh/mapstructure v1.4.1 github.com/rickb777/date v1.12.5-0.20200422084442-6300e543c4d9 github.com/sergi/go-diff v1.2.0 diff --git a/go.sum b/go.sum index 1f7fefe34eee..253ead9bd7ef 100644 --- a/go.sum +++ b/go.sum @@ -359,8 +359,9 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/magodo/terraform-provider-azurerm-example-gen v0.0.0-20220407025246-3a3ee0ab24a8 h1:HHSqLmPZaa8U66U7N2Gtx3gYptSHrUB/rB5t+6fZTkQ= github.com/magodo/terraform-provider-azurerm-example-gen v0.0.0-20220407025246-3a3ee0ab24a8/go.mod h1:iMzpAzVr2v/NUVie/apAYtZlFZYFndPcp6/E0VLxgAM= -github.com/manicminer/hamilton v0.43.0 h1:X/XrzLWFhPx1mlLBycqgKRcIjM9vfCd/QR5YnJKIDTI= github.com/manicminer/hamilton v0.43.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk= +github.com/manicminer/hamilton v0.44.0 h1:mLb4Vxbt2dsAvOpaB7xd/5D8LaTTX6ACwVP4TmW8qwE= +github.com/manicminer/hamilton v0.44.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk= github.com/manicminer/hamilton-autorest v0.2.0 h1:dDL+t2DrQza0EfNYINYCvXISeNwVqzgVAQh+CH/19ZU= github.com/manicminer/hamilton-autorest v0.2.0/go.mod h1:NselDpNTImEmOc/fa41kPg6YhDt/6S95ejWbTGZ6tlg= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= diff --git a/vendor/github.com/manicminer/hamilton/environments/endpoints.go b/vendor/github.com/manicminer/hamilton/environments/endpoints.go index a6922d37cd99..450e74c5a916 100644 --- a/vendor/github.com/manicminer/hamilton/environments/endpoints.go +++ b/vendor/github.com/manicminer/hamilton/environments/endpoints.go @@ -33,7 +33,7 @@ const ( KeyVaultPublicEndpoint ApiEndpoint = "https://vault.azure.net" KeyVaultChinaEndpoint ApiEndpoint = "https://vault.azure.cn" - KeyVaultUSGovEndpoint ApiEndpoint = "https://vault.microsoftazure.us" + KeyVaultUSGovEndpoint ApiEndpoint = "https://vault.usgovcloudapi.net" OperationalInsightsPublicEndpoint ApiEndpoint = "https://api.loganalytics.io" OperationalInsightsUSGovEndpoint ApiEndpoint = "https://api.loganalytics.us" diff --git a/vendor/github.com/manicminer/hamilton/msgraph/models.go b/vendor/github.com/manicminer/hamilton/msgraph/models.go index 2533fedc7889..343c94152f32 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/models.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/models.go @@ -1052,6 +1052,7 @@ type KeyCredential struct { EndDateTime *time.Time `json:"endDateTime,omitempty"` KeyId *string `json:"keyId,omitempty"` StartDateTime *time.Time `json:"startDateTime,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` Type KeyCredentialType `json:"type"` Usage KeyCredentialUsage `json:"usage"` Key *string `json:"key,omitempty"` @@ -1282,6 +1283,7 @@ type ServicePrincipal struct { PasswordCredentials *[]PasswordCredential `json:"passwordCredentials,omitempty"` PasswordSingleSignOnSettings *PasswordSingleSignOnSettings `json:"passwordSingleSignOnSettings,omitempty"` PreferredSingleSignOnMode *PreferredSingleSignOnMode `json:"preferredSingleSignOnMode,omitempty"` + PreferredTokenSigningKeyThumbprint *string `json:"preferredTokenSigningKeyThumbprint,omitempty"` PreferredTokenSigningKeyEndDateTime *time.Time `json:"preferredTokenSigningKeyEndDateTime,omitempty"` PublishedPermissionScopes *[]PermissionScope `json:"publishedPermissionScopes,omitempty"` ReplyUrls *[]string `json:"replyUrls,omitempty"` diff --git a/vendor/github.com/manicminer/hamilton/msgraph/serviceprincipals.go b/vendor/github.com/manicminer/hamilton/msgraph/serviceprincipals.go index 1727d9b91d56..698523bfc072 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/serviceprincipals.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/serviceprincipals.go @@ -578,6 +578,71 @@ func (c *ServicePrincipalsClient) RemovePassword(ctx context.Context, servicePri return status, nil } +// AddTokenSigningCertificate appends a new self signed certificate (keys and password) to a Service Principal. +func (c *ServicePrincipalsClient) AddTokenSigningCertificate(ctx context.Context, servicePrincipalId string, keyCredential KeyCredential) (*KeyCredential, int, error) { + var status int + + body, err := json.Marshal(keyCredential) + if err != nil { + return nil, status, fmt.Errorf("json.Marshal(): %v", err) + } + + resp, status, _, err := c.BaseClient.Post(ctx, PostHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusOK, http.StatusCreated}, + Uri: Uri{ + Entity: fmt.Sprintf("/servicePrincipals/%s/addTokenSigningCertificate", servicePrincipalId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("ServicePrincipalsClient.BaseClient.Post(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var newKeyCredential KeyCredential + if err := json.Unmarshal(respBody, &newKeyCredential); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &newKeyCredential, status, nil +} + +// SetPreferredTokenSigningKeyThumbprint sets the field preferredTokenSigningKeyThumbprint for a Service Principal. +func (c *ServicePrincipalsClient) SetPreferredTokenSigningKeyThumbprint(ctx context.Context, servicePrincipalId string, thumbprint string) (int, error) { + var status int + + body, err := json.Marshal(struct { + Thumbprint string `json:"preferredTokenSigningKeyThumbprint"` + }{ + Thumbprint: thumbprint, + }) + if err != nil { + return status, fmt.Errorf("json.Marshal(): %v", err) + } + + _, status, _, err = c.BaseClient.Patch(ctx, PatchHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/servicePrincipals/%s", servicePrincipalId), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("ServicePrincipalsClient.BaseClient.Patch(): %v", err) + } + + return status, nil +} + // ListOwnedObjects retrieves the owned objects of the specified Service Principal. // id is the object ID of the service principal. func (c *ServicePrincipalsClient) ListOwnedObjects(ctx context.Context, id string) (*[]string, int, error) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 8138caa9b19f..46a13a920e9c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -338,7 +338,7 @@ github.com/hashicorp/yamux # github.com/magodo/terraform-provider-azurerm-example-gen v0.0.0-20220407025246-3a3ee0ab24a8 ## explicit; go 1.16 github.com/magodo/terraform-provider-azurerm-example-gen/examplegen -# github.com/manicminer/hamilton v0.43.0 +# github.com/manicminer/hamilton v0.44.0 ## explicit; go 1.16 github.com/manicminer/hamilton/auth github.com/manicminer/hamilton/environments