7
7
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
8
8
"github.com/pkg/errors"
9
9
10
- "github.com/docker/api/azure/login"
11
10
"github.com/docker/api/errdefs"
12
11
)
13
12
@@ -30,13 +29,20 @@ func NewACIResourceGroupHelper() ACIResourceGroupHelper {
30
29
31
30
// GetGroup get a resource group from its name
32
31
func (mgt aciResourceGroupHelperImpl ) GetGroup (ctx context.Context , subscriptionID string , groupName string ) (resources.Group , error ) {
33
- gc := getGroupsClient (subscriptionID )
32
+ gc , err := getGroupsClient (subscriptionID )
33
+ if err != nil {
34
+ return resources.Group {}, err
35
+ }
34
36
return gc .Get (ctx , groupName )
35
37
}
36
38
37
39
// ListGroups list resource groups
38
40
func (mgt aciResourceGroupHelperImpl ) ListGroups (ctx context.Context , subscriptionID string ) ([]resources.Group , error ) {
39
- gc := getGroupsClient (subscriptionID )
41
+ gc , err := getGroupsClient (subscriptionID )
42
+ if err != nil {
43
+ return nil , err
44
+ }
45
+
40
46
groupResponse , err := gc .List (ctx , "" , nil )
41
47
if err != nil {
42
48
return nil , err
@@ -48,13 +54,20 @@ func (mgt aciResourceGroupHelperImpl) ListGroups(ctx context.Context, subscripti
48
54
49
55
// CreateOrUpdate create or update a resource group
50
56
func (mgt aciResourceGroupHelperImpl ) CreateOrUpdate (ctx context.Context , subscriptionID string , resourceGroupName string , parameters resources.Group ) (result resources.Group , err error ) {
51
- gc := getGroupsClient (subscriptionID )
57
+ gc , err := getGroupsClient (subscriptionID )
58
+ if err != nil {
59
+ return resources.Group {}, err
60
+ }
52
61
return gc .CreateOrUpdate (ctx , resourceGroupName , parameters )
53
62
}
54
63
55
64
// Delete deletes a resource group
56
65
func (mgt aciResourceGroupHelperImpl ) Delete (ctx context.Context , subscriptionID string , resourceGroupName string ) (err error ) {
57
- gc := getGroupsClient (subscriptionID )
66
+ gc , err := getGroupsClient (subscriptionID )
67
+ if err != nil {
68
+ return err
69
+ }
70
+
58
71
future , err := gc .Delete (ctx , resourceGroupName )
59
72
if err != nil {
60
73
return err
@@ -89,17 +102,18 @@ func (mgt aciResourceGroupHelperImpl) GetSubscriptionIDs(ctx context.Context) ([
89
102
90
103
func getSubscriptionsClient () (subscription.SubscriptionsClient , error ) {
91
104
subc := subscription .NewSubscriptionsClient ()
92
- authorizer , err := login . NewAuthorizerFromLogin ( )
105
+ err := setupClient ( & subc . Client )
93
106
if err != nil {
94
107
return subscription.SubscriptionsClient {}, errors .Wrap (errdefs .ErrLoginFailed , err .Error ())
95
108
}
96
- subc .Authorizer = authorizer
97
109
return subc , nil
98
110
}
99
111
100
- func getGroupsClient (subscriptionID string ) resources.GroupsClient {
112
+ func getGroupsClient (subscriptionID string ) ( resources.GroupsClient , error ) {
101
113
groupsClient := resources .NewGroupsClient (subscriptionID )
102
- authorizer , _ := login .NewAuthorizerFromLogin ()
103
- groupsClient .Authorizer = authorizer
104
- return groupsClient
114
+ err := setupClient (& groupsClient .Client )
115
+ if err != nil {
116
+ return resources.GroupsClient {}, err
117
+ }
118
+ return groupsClient , nil
105
119
}
0 commit comments