/
init.go
56 lines (48 loc) · 1.64 KB
/
init.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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package azure
import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/utils/v3/ssh"
"github.com/juju/juju/environs"
"github.com/juju/juju/provider/azure/internal/azureauth"
"github.com/juju/juju/provider/azure/internal/azurecli"
)
const (
// ProviderType defines the Azure provider.
ProviderType = "azure"
)
// NewProvider instantiates and returns the Azure EnvironProvider using the
// given configuration.
func NewProvider(config ProviderConfig) (environs.CloudEnvironProvider, error) {
environProvider, err := NewEnvironProvider(config)
if err != nil {
return nil, errors.Trace(err)
}
return environProvider, nil
}
func init() {
environProvider, err := NewProvider(ProviderConfig{
RetryClock: &clock.WallClock,
GenerateSSHKey: ssh.GenerateKey,
ServicePrincipalCreator: &azureauth.ServicePrincipalCreator{},
AzureCLI: azurecli.AzureCLI{},
CreateTokenCredential: func(appId, appPassword, tenantID string, opts azcore.ClientOptions) (azcore.TokenCredential, error) {
return azidentity.NewClientSecretCredential(
tenantID, appId, appPassword, &azidentity.ClientSecretCredentialOptions{
ClientOptions: opts,
},
)
},
})
if err != nil {
panic(err)
}
environs.RegisterProvider(ProviderType, environProvider)
// TODO(axw) register an image metadata data source that queries
// the Azure image registry, and introduce a way to disable the
// common simplestreams source.
}