-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
auth.go
41 lines (35 loc) · 1.32 KB
/
auth.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
package clients
import (
"context"
"fmt"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/authentication"
)
type ResourceManagerAccount struct {
AuthenticatedAsAServicePrincipal bool
ClientId string
Environment azure.Environment
ObjectId string
SubscriptionId string
TenantId string
}
func NewResourceManagerAccount(ctx context.Context, config authentication.Config, env azure.Environment) (*ResourceManagerAccount, error) {
objectId := ""
// TODO remove this when we confirm that MSI no longer returns nil with getAuthenticatedObjectID
if getAuthenticatedObjectID := config.GetAuthenticatedObjectID; getAuthenticatedObjectID != nil {
v, err := getAuthenticatedObjectID(ctx)
if err != nil {
return nil, fmt.Errorf("Error getting authenticated object ID: %v", err)
}
objectId = v
}
account := ResourceManagerAccount{
AuthenticatedAsAServicePrincipal: config.AuthenticatedAsAServicePrincipal,
ClientId: config.ClientID,
Environment: env,
ObjectId: objectId,
TenantId: config.TenantID,
SubscriptionId: config.SubscriptionID,
}
return &account, nil
}