@@ -219,19 +219,19 @@ func (i *imlAuthorizationModule) initGateway(ctx context.Context, partitionId st
219219 return clientDriver .Application ().Online (ctx , applications ... )
220220}
221221
222- func (i * imlAuthorizationModule ) online (ctx context.Context , s * service.Service ) error {
223- clusters , err := i .clusterService .List (ctx )
224- if err != nil {
225- return err
226- }
227- if len (clusters ) < 1 {
228- return nil
229- }
222+ func (i * imlAuthorizationModule ) getApplicationRelease (ctx context.Context , s * service.Service ) (* gateway.ApplicationRelease , error ) {
230223 authorizations , err := i .authorizationService .ListByApp (ctx , s .Id )
231224 if err != nil {
232- return err
225+ return nil , err
226+ }
227+ if len (authorizations ) < 1 {
228+ return & gateway.ApplicationRelease {
229+ BasicItem : & gateway.BasicItem {
230+ ID : s .Id ,
231+ },
232+ }, nil
233233 }
234- app := & gateway.ApplicationRelease {
234+ return & gateway.ApplicationRelease {
235235 BasicItem : & gateway.BasicItem {
236236 ID : s .Id ,
237237 Description : s .Description ,
@@ -256,10 +256,40 @@ func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service)
256256 },
257257 }
258258 }),
259+ }, nil
260+ }
261+ func (i * imlAuthorizationModule ) doOffline (ctx context.Context , clusterId string , app * gateway.ApplicationRelease ) error {
262+ client , err := i .clusterService .GatewayClient (ctx , clusterId )
263+ if err != nil {
264+ return err
259265 }
266+ defer func () {
267+ _ = client .Close (ctx )
268+ }()
269+ return client .Application ().Offline (ctx , app )
270+ }
260271
272+ func (i * imlAuthorizationModule ) online (ctx context.Context , s * service.Service ) error {
273+ clusters , err := i .clusterService .List (ctx )
274+ if err != nil {
275+ return err
276+ }
277+ if len (clusters ) < 1 {
278+ return nil
279+ }
280+ release , err := i .getApplicationRelease (ctx , s )
281+ if err != nil {
282+ return err
283+ }
261284 for _ , c := range clusters {
262- err := i .doOnline (ctx , c .Uuid , app )
285+ if len (release .Authorizations ) < 1 {
286+ err = i .doOffline (ctx , c .Uuid , release )
287+ if err != nil {
288+ log .Warnf ("service authorization offline for cluster[%s] %v" , c .Name , err )
289+ }
290+ continue
291+ }
292+ err = i .doOnline (ctx , c .Uuid , release )
263293 if err != nil {
264294 log .Warnf ("service authorization online for cluster[%s] %v" , c .Name , err )
265295 }
@@ -375,7 +405,7 @@ func (i *imlAuthorizationModule) EditAuthorization(ctx context.Context, appId st
375405}
376406
377407func (i * imlAuthorizationModule ) DeleteAuthorization (ctx context.Context , pid string , aid string ) error {
378- _ , err := i .serviceService .Get (ctx , pid )
408+ s , err := i .serviceService .Get (ctx , pid )
379409 if err != nil {
380410 return err
381411 }
@@ -385,35 +415,11 @@ func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid st
385415 if err != nil {
386416 return err
387417 }
388- clusters , err := i .clusterService .List (ctx )
389- if err != nil {
390- return err
391- }
392- app := & gateway.ApplicationRelease {
393- BasicItem : & gateway.BasicItem {
394- ID : pid ,
395- },
396- }
397- for _ , c := range clusters {
398- err := i .doOffline (ctx , c .Uuid , app )
399- if err != nil {
400- log .Warnf ("service authorization offline for cluster[%s] %v" , c .Name , err )
401- }
402- }
403- return nil
418+
419+ return i .online (ctx , s )
404420 })
405421}
406- func (i * imlAuthorizationModule ) doOffline (ctx context.Context , clusterId string , app * gateway.ApplicationRelease ) error {
407- client , err := i .clusterService .GatewayClient (ctx , clusterId )
408- if err != nil {
409- return err
410- }
411- defer func () {
412- _ = client .Close (ctx )
413- }()
414- return client .Application ().Offline (ctx , app )
415422
416- }
417423func (i * imlAuthorizationModule ) Authorizations (ctx context.Context , pid string ) ([]* application_authorization_dto.AuthorizationItem , error ) {
418424 _ , err := i .serviceService .Get (ctx , pid )
419425 if err != nil {
0 commit comments