@@ -139,10 +139,6 @@ func Create(name string, content []byte, serviceAccountName string, serviceAccou
139
139
return nil , err
140
140
}
141
141
142
- if c .ServiceAccount == nil {
143
- c .ServiceAccount = new (string )
144
- }
145
-
146
142
//service account overrides have been provided, use them
147
143
if serviceAccountName != "" {
148
144
//set the project id if one was not presented
@@ -154,14 +150,17 @@ func Create(name string, content []byte, serviceAccountName string, serviceAccou
154
150
if err = apiclient .CreateServiceAccount (serviceAccountName ); err != nil {
155
151
return nil , err
156
152
}
157
- } else { //use the default compute engine SA
153
+ } else if grantPermission { //use the default compute engine SA to grant permissions
158
154
serviceAccountName , err = apiclient .GetComputeEngineDefaultServiceAccount (apiclient .GetProjectID ())
159
155
if err != nil {
160
156
return nil , err
161
157
}
162
158
}
163
159
164
- * c .ServiceAccount = serviceAccountName
160
+ if c .ServiceAccount == nil && serviceAccountName != "" {
161
+ c .ServiceAccount = new (string )
162
+ * c .ServiceAccount = serviceAccountName
163
+ }
165
164
166
165
if c .ConnectorDetails == nil {
167
166
return nil , fmt .Errorf ("connectorDetails must be set. See https://github.com/srinandan/integrationcli#connectors-for-third-party-applications for more details" )
@@ -282,9 +281,9 @@ func Create(name string, content []byte, serviceAccountName string, serviceAccou
282
281
c .AuthConfig .UserPassword .Password .SecretVersion = secretVersion
283
282
c .AuthConfig .UserPassword .PasswordDetails = nil //clean the input
284
283
285
- if grantPermission {
284
+ if grantPermission && c . ServiceAccount != nil {
286
285
//grant connector service account access to secretVersion
287
- if err = apiclient .SetSecretManagerIAMPermission (apiclient .GetProjectID (), secretName , serviceAccountName ); err != nil {
286
+ if err = apiclient .SetSecretManagerIAMPermission (apiclient .GetProjectID (), secretName , * c . ServiceAccount ); err != nil {
288
287
return nil , err
289
288
}
290
289
}
0 commit comments