77 "github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
88 "github.com/pkg/errors"
99
10- "github.com/docker/api/azure/login"
1110 "github.com/docker/api/errdefs"
1211)
1312
@@ -30,13 +29,20 @@ func NewACIResourceGroupHelper() ACIResourceGroupHelper {
3029
3130// GetGroup get a resource group from its name
3231func (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+ }
3436 return gc .Get (ctx , groupName )
3537}
3638
3739// ListGroups list resource groups
3840func (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+
4046 groupResponse , err := gc .List (ctx , "" , nil )
4147 if err != nil {
4248 return nil , err
@@ -48,13 +54,20 @@ func (mgt aciResourceGroupHelperImpl) ListGroups(ctx context.Context, subscripti
4854
4955// CreateOrUpdate create or update a resource group
5056func (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+ }
5261 return gc .CreateOrUpdate (ctx , resourceGroupName , parameters )
5362}
5463
5564// Delete deletes a resource group
5665func (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+
5871 future , err := gc .Delete (ctx , resourceGroupName )
5972 if err != nil {
6073 return err
@@ -89,19 +102,18 @@ func (mgt aciResourceGroupHelperImpl) GetSubscriptionIDs(ctx context.Context) ([
89102
90103func getSubscriptionsClient () (subscription.SubscriptionsClient , error ) {
91104 subc := subscription .NewSubscriptionsClient ()
92- authorizer , err := login . NewAuthorizerFromLogin ( )
105+ err := setupClient ( & subc . Client )
93106 if err != nil {
94107 return subscription.SubscriptionsClient {}, errors .Wrap (errdefs .ErrLoginFailed , err .Error ())
95108 }
96- subc .Authorizer = authorizer
97- subc .UserAgent = aciDockerUserAgent
98109 return subc , nil
99110}
100111
101- func getGroupsClient (subscriptionID string ) resources.GroupsClient {
112+ func getGroupsClient (subscriptionID string ) ( resources.GroupsClient , error ) {
102113 groupsClient := resources .NewGroupsClient (subscriptionID )
103- authorizer , _ := login .NewAuthorizerFromLogin ()
104- groupsClient .Authorizer = authorizer
105- groupsClient .UserAgent = aciDockerUserAgent
106- return groupsClient
114+ err := setupClient (& groupsClient .Client )
115+ if err != nil {
116+ return resources.GroupsClient {}, err
117+ }
118+ return groupsClient , nil
107119}
0 commit comments