feat(api-client): Add update and delete methods for external registries and secret bundles/groups
This commit is contained in:
		| @@ -180,6 +180,20 @@ export class CloudlyApiClient { | |||||||
|     getRegistryById: async (registryNameArg: string) => { |     getRegistryById: async (registryNameArg: string) => { | ||||||
|       return ExternalRegistry.getExternalRegistryById(this, registryNameArg); |       return ExternalRegistry.getExternalRegistryById(this, registryNameArg); | ||||||
|     }, |     }, | ||||||
|  |     updateRegistry: async (registryId: string, registryData: plugins.servezoneInterfaces.data.IExternalRegistry['data']): Promise<{ resultRegistry: plugins.servezoneInterfaces.data.IExternalRegistry }> => { | ||||||
|  |       const op = 'updateExternalRegistry'; | ||||||
|  |       const payload = { identity: this.identity, registryId, registryData } as any; | ||||||
|  |       const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_UpdateRegistry>(op); | ||||||
|  |       if (wsReq) return wsReq.fire(payload); | ||||||
|  |       return this.createHttpRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_UpdateRegistry>(op).fire(payload); | ||||||
|  |     }, | ||||||
|  |     deleteRegistry: async (registryId: string): Promise<{ ok: boolean }> => { | ||||||
|  |       const op = 'deleteExternalRegistryById'; | ||||||
|  |       const payload = { identity: this.identity, registryId } as any; | ||||||
|  |       const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_DeleteRegistryById>(op); | ||||||
|  |       if (wsReq) return wsReq.fire(payload); | ||||||
|  |       return this.createHttpRequest<plugins.servezoneInterfaces.requests.externalRegistry.IReq_DeleteRegistryById>(op).fire(payload); | ||||||
|  |     }, | ||||||
|     getRegistries: async () => { |     getRegistries: async () => { | ||||||
|       return ExternalRegistry.getExternalRegistries(this); |       return ExternalRegistry.getExternalRegistries(this); | ||||||
|     }, |     }, | ||||||
| @@ -292,6 +306,13 @@ export class CloudlyApiClient { | |||||||
|     }, |     }, | ||||||
|     createSecretBundle: async (optionsArg: Parameters<typeof SecretBundle.createSecretBundle>[1]) => { |     createSecretBundle: async (optionsArg: Parameters<typeof SecretBundle.createSecretBundle>[1]) => { | ||||||
|       return SecretBundle.createSecretBundle(this, optionsArg); |       return SecretBundle.createSecretBundle(this, optionsArg); | ||||||
|  |     }, | ||||||
|  |     deleteSecretBundleById: async (secretBundleId: string): Promise<{ ok: boolean }> => { | ||||||
|  |       const op = 'deleteSecretBundleById'; | ||||||
|  |       const payload = { identity: this.identity, secretBundleId } as any; | ||||||
|  |       const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.secretbundle.IReq_DeleteSecretBundleById>(op); | ||||||
|  |       if (wsReq) return wsReq.fire(payload); | ||||||
|  |       return this.createHttpRequest<plugins.servezoneInterfaces.requests.secretbundle.IReq_DeleteSecretBundleById>(op).fire(payload); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -305,6 +326,13 @@ export class CloudlyApiClient { | |||||||
|     }, |     }, | ||||||
|     createSecretGroup: async (optionsArg: Parameters<typeof SecretGroup.createSecretGroup>[1]) => { |     createSecretGroup: async (optionsArg: Parameters<typeof SecretGroup.createSecretGroup>[1]) => { | ||||||
|       return SecretGroup.createSecretGroup(this, optionsArg); |       return SecretGroup.createSecretGroup(this, optionsArg); | ||||||
|  |     }, | ||||||
|  |     deleteSecretGroupById: async (secretGroupId: string): Promise<{ ok: boolean }> => { | ||||||
|  |       const op = 'deleteSecretGroupById'; | ||||||
|  |       const payload = { identity: this.identity, secretGroupId } as any; | ||||||
|  |       const wsReq = this.createWsRequest<plugins.servezoneInterfaces.requests.secretgroup.IReq_DeleteSecretGroupById>(op); | ||||||
|  |       if (wsReq) return wsReq.fire(payload); | ||||||
|  |       return this.createHttpRequest<plugins.servezoneInterfaces.requests.secretgroup.IReq_DeleteSecretGroupById>(op).fire(payload); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -102,7 +102,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const secretGroups = await apiClient.secretgroup.getSecretGroups(); |     const secretGroups = await apiClient.secretgroup.getSecretGroups(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       secretGroups: secretGroups as any, |       secretGroups: (secretGroups as any[]).map((sg: any) => ({ id: sg.id, data: sg.data })), | ||||||
|     }; |     }; | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     console.error('Failed to fetch secret groups:', err); |     console.error('Failed to fetch secret groups:', err); | ||||||
| @@ -118,7 +118,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const responseSecretBundles = await apiClient.secretbundle.getSecretBundles(); |     const responseSecretBundles = await apiClient.secretbundle.getSecretBundles(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       secretBundles: responseSecretBundles as any, |       secretBundles: (responseSecretBundles as any[]).map((sb: any) => ({ id: sb.id, data: sb.data })), | ||||||
|     }; |     }; | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     console.error('Failed to fetch secret bundles:', err); |     console.error('Failed to fetch secret bundles:', err); | ||||||
| @@ -134,7 +134,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const images = await apiClient.image.getImages(); |     const images = await apiClient.image.getImages(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       images: images as any, |       images: (images as any[]).map((im: any) => ({ id: im.id, data: im.data })), | ||||||
|     }; |     }; | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     console.error('Failed to fetch images:', err); |     console.error('Failed to fetch images:', err); | ||||||
| @@ -150,7 +150,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const clusters = await apiClient.cluster.getClusters(); |     const clusters = await apiClient.cluster.getClusters(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       clusters: clusters as any, |       clusters: (clusters as any[]).map((cl: any) => ({ id: cl.id, data: cl.data })), | ||||||
|     } |     } | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     console.error('Failed to fetch clusters:', err); |     console.error('Failed to fetch clusters:', err); | ||||||
| @@ -166,7 +166,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const registries = await apiClient.externalRegistry.getRegistries(); |     const registries = await apiClient.externalRegistry.getRegistries(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       externalRegistries: registries as any, |       externalRegistries: (registries as any[]).map((r: any) => ({ id: r.id, data: r.data })), | ||||||
|     }; |     }; | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|     console.error('Failed to fetch external registries:', error); |     console.error('Failed to fetch external registries:', error); | ||||||
| @@ -182,7 +182,7 @@ export const getAllDataAction = dataState.createAction(async (statePartArg) => { | |||||||
|     const services = await apiClient.services.getServices(); |     const services = await apiClient.services.getServices(); | ||||||
|     currentState = { |     currentState = { | ||||||
|       ...currentState, |       ...currentState, | ||||||
|       services: services as any, |       services: (services as any[]).map((s: any) => ({ id: s.id, data: s.data })), | ||||||
|     }; |     }; | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|     console.error('Failed to fetch services:', error); |     console.error('Failed to fetch services:', error); | ||||||
| @@ -295,10 +295,7 @@ export const deleteSecretGroupAction = dataState.createAction( | |||||||
|     let currentState = statePartArg.getState(); |     let currentState = statePartArg.getState(); | ||||||
|     try { |     try { | ||||||
|       apiClient.identity = loginStatePart.getState().identity; |       apiClient.identity = loginStatePart.getState().identity; | ||||||
|       const sg = (currentState.secretGroups as any[])?.find(s => s.id === payloadArg.secretGroupId); |       await apiClient.secretgroup.deleteSecretGroupById(payloadArg.secretGroupId); | ||||||
|       if (sg) { |  | ||||||
|         await sg.delete(apiClient as any, sg.id); |  | ||||||
|       } |  | ||||||
|       currentState = await dataState.dispatchAction(getAllDataAction, null); |       currentState = await dataState.dispatchAction(getAllDataAction, null); | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       console.error('Failed to delete secret group:', err); |       console.error('Failed to delete secret group:', err); | ||||||
| @@ -313,10 +310,7 @@ export const deleteSecretBundleAction = dataState.createAction( | |||||||
|     let currentState = statePartArg.getState(); |     let currentState = statePartArg.getState(); | ||||||
|     try { |     try { | ||||||
|       apiClient.identity = loginStatePart.getState().identity; |       apiClient.identity = loginStatePart.getState().identity; | ||||||
|       const sb = (currentState.secretBundles as any[])?.find(b => b.id === payloadArg.configBundleId); |       await apiClient.secretbundle.deleteSecretBundleById(payloadArg.configBundleId); | ||||||
|       if (sb) { |  | ||||||
|         await sb.delete(apiClient as any, sb.id); |  | ||||||
|       } |  | ||||||
|       currentState = await dataState.dispatchAction(getAllDataAction, null); |       currentState = await dataState.dispatchAction(getAllDataAction, null); | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       console.error('Failed to delete secret bundle:', err); |       console.error('Failed to delete secret bundle:', err); | ||||||
| @@ -465,11 +459,7 @@ export const updateExternalRegistryAction = dataState.createAction( | |||||||
|     let currentState = statePartArg.getState(); |     let currentState = statePartArg.getState(); | ||||||
|     try { |     try { | ||||||
|       apiClient.identity = loginStatePart.getState().identity; |       apiClient.identity = loginStatePart.getState().identity; | ||||||
|       const reg = (currentState.externalRegistries as any[])?.find(r => r.id === payloadArg.registryId); |       await apiClient.externalRegistry.updateRegistry(payloadArg.registryId, payloadArg.registryData); | ||||||
|       if (reg) { |  | ||||||
|         reg.data = payloadArg.registryData; |  | ||||||
|         await reg.update(); |  | ||||||
|       } |  | ||||||
|       currentState = await dataState.dispatchAction(getAllDataAction, null); |       currentState = await dataState.dispatchAction(getAllDataAction, null); | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       console.error('Failed to update external registry:', err); |       console.error('Failed to update external registry:', err); | ||||||
| @@ -483,10 +473,7 @@ export const deleteExternalRegistryAction = dataState.createAction( | |||||||
|     let currentState = statePartArg.getState(); |     let currentState = statePartArg.getState(); | ||||||
|     try { |     try { | ||||||
|       apiClient.identity = loginStatePart.getState().identity; |       apiClient.identity = loginStatePart.getState().identity; | ||||||
|       const reg = (currentState.externalRegistries as any[])?.find(r => r.id === payloadArg.registryId); |       await apiClient.externalRegistry.deleteRegistry(payloadArg.registryId); | ||||||
|       if (reg) { |  | ||||||
|         await reg.delete(apiClient as any, reg.id); |  | ||||||
|       } |  | ||||||
|       currentState = await dataState.dispatchAction(getAllDataAction, null); |       currentState = await dataState.dispatchAction(getAllDataAction, null); | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       console.error('Failed to delete external registry:', err); |       console.error('Failed to delete external registry:', err); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user