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

Explicitly set the API version instead of relying on SDK default version #990

Merged
merged 1 commit into from
Jan 27, 2023
Merged
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
5 changes: 3 additions & 2 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/auth"
"github.com/manicminer/hamilton/environments"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

type ClientBuilder struct {
Expand Down Expand Up @@ -53,6 +53,7 @@ func (b *ClientBuilder) Build(ctx context.Context) (*Client, error) {

o := &common.ClientOptions{
Authorizer: authorizer,
ApiVersion: msgraph.Version10,
Environment: client.Environment,
TenantID: client.TenantID,

Expand Down
7 changes: 5 additions & 2 deletions internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
"github.com/hashicorp/terraform-provider-azuread/version"
"github.com/manicminer/hamilton/auth"
"github.com/manicminer/hamilton/environments"
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/version"
)

type contextKey string
Expand All @@ -28,6 +27,7 @@ type ClientOptions struct {
TerraformVersion string

Authorizer auth.Authorizer
ApiVersion msgraph.ApiVersion
}

func (o ClientOptions) ConfigureClient(c *msgraph.Client) {
Expand All @@ -46,6 +46,9 @@ func (o ClientOptions) ConfigureClient(c *msgraph.Client) {

// Default retry limit, can be overridden from within a resource
c.RetryableClient.RetryMax = 9

// Explicitly set API version
c.ApiVersion = o.ApiVersion
}

func (o ClientOptions) requestLogger(req *http.Request) (*http.Request, error) {
Expand Down
3 changes: 1 addition & 2 deletions internal/services/applications/client/client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package client

import (
"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/environments"
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
)

type Client struct {
Expand Down
4 changes: 1 addition & 3 deletions internal/services/conditionalaccess/client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package client

import (
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

type Client struct {
Expand All @@ -17,7 +16,6 @@ func NewClient(o *common.ClientOptions) *Client {

policiesClient := msgraph.NewConditionalAccessPoliciesClient(o.TenantID)
o.ConfigureClient(&policiesClient.BaseClient)
policiesClient.BaseClient.ApiVersion = msgraph.Version10

return &Client{
NamedLocationsClient: namedLocationsClient,
Expand Down
1 change: 0 additions & 1 deletion internal/services/serviceprincipals/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewClient(o *common.ClientOptions) *Client {
o.ConfigureClient(&directoryObjectsClient.BaseClient)

servicePrincipalsClient := msgraph.NewServicePrincipalsClient(o.TenantID)
servicePrincipalsClient.BaseClient.ApiVersion = msgraph.Version10
o.ConfigureClient(&servicePrincipalsClient.BaseClient)

synchronizationJobClient := msgraph.NewSynchronizationJobClient(o.TenantID)
Expand Down