Skip to content

Commit

Permalink
SDK Migration: migrate users to go-azure-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Sep 23, 2024
1 parent eb72b8d commit 76d0ffa
Show file tree
Hide file tree
Showing 9 changed files with 696 additions and 485 deletions.
52 changes: 35 additions & 17 deletions internal/services/users/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,50 @@
package client

import (
"github.com/hashicorp/go-azure-sdk/microsoft-graph/me/stable/me"
userBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/users/beta/user"
"github.com/hashicorp/go-azure-sdk/microsoft-graph/users/stable/manager"
"github.com/hashicorp/go-azure-sdk/microsoft-graph/users/stable/user"
"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

type Client struct {
DirectoryObjectsClient *msgraph.DirectoryObjectsClient
MeClient *msgraph.MeClient
UsersClient *msgraph.UsersClient
ManagerClient *manager.ManagerClient
MeClient *me.MeClient
UserClient *user.UserClient
UserClientBeta *userBeta.UserClient
}

func NewClient(o *common.ClientOptions) *Client {
directoryObjectsClient := msgraph.NewDirectoryObjectsClient()
o.ConfigureClient(&directoryObjectsClient.BaseClient)
func NewClient(o *common.ClientOptions) (*Client, error) {
managerClient, err := manager.NewManagerClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(managerClient.Client)

meClient := msgraph.NewMeClient()
o.ConfigureClient(&meClient.BaseClient)
meClient, err := me.NewMeClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(meClient.Client)

usersClient := msgraph.NewUsersClient()
o.ConfigureClient(&usersClient.BaseClient)
userClient, err := user.NewUserClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(userClient.Client)

// See https://learn.microsoft.com/en-us/graph/known-issues#showinaddresslist-property-is-out-of-sync-with-microsoft-exchange (it works in the beta API)
usersClient.BaseClient.ApiVersion = msgraph.VersionBeta
// See https://developer.microsoft.com/en-us/graph/known-issues/?search=14972 (it works in the beta API)
userClientBeta, err := userBeta.NewUserClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(userClientBeta.Client)

return &Client{
DirectoryObjectsClient: directoryObjectsClient,
MeClient: meClient,
UsersClient: usersClient,
}
ManagerClient: managerClient,
MeClient: meClient,
UserClient: userClient,
UserClientBeta: userClientBeta,
}, nil
}
17 changes: 17 additions & 0 deletions internal/services/users/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package users

const (
AgeGroupAdult = "Adult"
AgeGroupMinor = "Minor"
AgeGroupNotAdult = "NotAdult"
)

var possibleValuesForAgeGroup = []string{AgeGroupAdult, AgeGroupMinor, AgeGroupNotAdult}

const (
ConsentProvidedForMinorDenied = "Denied"
ConsentProvidedForMinorGranted = "Granted"
ConsentProvidedForMinorNotRequired = "NotRequired"
)

var possibleValuesForConsentProvidedForMinor = []string{ConsentProvidedForMinorDenied, ConsentProvidedForMinorGranted, ConsentProvidedForMinorNotRequired}
2 changes: 1 addition & 1 deletion internal/services/users/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package users

import "github.com/hashicorp/terraform-provider-azuread/internal/tf/pluginsdk"
import "github.com/hashicorp/terraform-provider-azuread/internal/helpers/tf/pluginsdk"

type Registration struct{}

Expand Down
Loading

0 comments on commit 76d0ffa

Please sign in to comment.