-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
client.go
78 lines (65 loc) · 3.52 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package client
import (
"fmt"
"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2023-03-01/configurationstores"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2023-03-01/deletedconfigurationstores"
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2023-03-01/replicas"
authWrapper "github.com/hashicorp/go-azure-sdk/sdk/auth/autorest"
"github.com/hashicorp/go-azure-sdk/sdk/environments"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/azuresdkhacks"
"github.com/tombuildsstuff/kermit/sdk/appconfiguration/1.0/appconfiguration"
)
type Client struct {
ConfigurationStoresClient *configurationstores.ConfigurationStoresClient
DeletedConfigurationStoresClient *deletedconfigurationstores.DeletedConfigurationStoresClient
ReplicasClient *replicas.ReplicasClient
authorizerFunc common.ApiAuthorizerFunc
configureClientFunc func(c *autorest.Client, authorizer autorest.Authorizer)
}
func (c Client) DataPlaneClientWithEndpoint(configurationStoreEndpoint string) (*appconfiguration.BaseClient, error) {
api := environments.NewApiEndpoint("AppConfiguration", configurationStoreEndpoint, nil)
appConfigAuth, err := c.authorizerFunc(api)
if err != nil {
return nil, fmt.Errorf("obtaining auth token for %q: %+v", configurationStoreEndpoint, err)
}
client := appconfiguration.NewWithoutDefaults("", configurationStoreEndpoint)
c.configureClientFunc(&client.Client, authWrapper.AutorestAuthorizer(appConfigAuth))
return &client, nil
}
func (c Client) LinkWorkaroundDataPlaneClientWithEndpoint(configurationStoreEndpoint string) (*azuresdkhacks.DataPlaneClient, error) {
api := environments.NewApiEndpoint("AppConfiguration", configurationStoreEndpoint, nil)
appConfigAuth, err := c.authorizerFunc(api)
if err != nil {
return nil, fmt.Errorf("obtaining auth token for %q: %+v", configurationStoreEndpoint, err)
}
client := appconfiguration.NewWithoutDefaults("", configurationStoreEndpoint)
c.configureClientFunc(&client.Client, authWrapper.AutorestAuthorizer(appConfigAuth))
workaroundClient := azuresdkhacks.NewDataPlaneClient(client)
return &workaroundClient, nil
}
func NewClient(o *common.ClientOptions) (*Client, error) {
configurationStores, err := configurationstores.NewConfigurationStoresClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ConfigurationStores client: %+v", err)
}
o.Configure(configurationStores.Client, o.Authorizers.ResourceManager)
deletedConfigurationStores, err := deletedconfigurationstores.NewDeletedConfigurationStoresClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DeletedConfigurationStores client: %+v", err)
}
o.Configure(deletedConfigurationStores.Client, o.Authorizers.ResourceManager)
replicasClient, err := replicas.NewReplicasClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DeletedConfigurationStores client: %+v", err)
}
o.Configure(replicasClient.Client, o.Authorizers.ResourceManager)
return &Client{
ConfigurationStoresClient: configurationStores,
DeletedConfigurationStoresClient: deletedConfigurationStores,
ReplicasClient: replicasClient,
authorizerFunc: o.Authorizers.AuthorizerFunc,
configureClientFunc: o.ConfigureClient,
}, nil
}