From e47062a74558b2866afca41a3ba995be04c8a85e Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Mon, 3 Mar 2025 20:02:54 +0530 Subject: [PATCH] SDK Support for 4.6.a (#153) * Add support for alert channel updates * Add support for developer settings * Add support for platform settings * Add support for registration token actions --------- Signed-off-by: Sivaanand Murugesan --- client/alert.go | 8 +++ client/cluster_edge_native.go | 54 ++++++++++++++++++++ client/cluster_group.go | 14 ++++++ client/developer_setting.go | 20 ++++++++ client/platform_setting.go | 92 +++++++++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 client/developer_setting.go create mode 100644 client/platform_setting.go diff --git a/client/alert.go b/client/alert.go index e5d01c1a..47749b2a 100644 --- a/client/alert.go +++ b/client/alert.go @@ -32,6 +32,14 @@ func (h *V1Client) UpdateAlert(body *models.V1Channel, projectUID, component, al return "success", nil } +// UpdateProjectAlerts update alerts for project. +func (h *V1Client) UpdateProjectAlerts(body *models.V1AlertEntity, projectUID, component string) error { + params := clientv1.NewV1ProjectsUIDAlertUpdateParamsWithContext(h.ctx).WithBody(body).WithUID(projectUID). + WithComponent(component) + _, err := h.Client.V1ProjectsUIDAlertUpdate(params) + return err +} + // GetAlert retrieves an existing alert. func (h *V1Client) GetAlert(projectUID, component, alertUID string) (*models.V1Channel, error) { params := clientv1.NewV1ProjectsUIDAlertsUIDGetParamsWithContext(h.ctx). diff --git a/client/cluster_edge_native.go b/client/cluster_edge_native.go index 1cad9989..604fd139 100644 --- a/client/cluster_edge_native.go +++ b/client/cluster_edge_native.go @@ -32,6 +32,41 @@ func (h *V1Client) GetRegistrationToken(tokenName string) (string, error) { return "", nil } +// GetRegistrationTokenByUID retrieves an existing registration token by token UID. +func (h *V1Client) GetRegistrationTokenByUID(tokenUID string) (*models.V1EdgeToken, error) { + // ACL scoped to tenant only + params := clientv1.NewV1EdgeTokensUIDGetParams().WithUID(tokenUID) + resp, err := h.Client.V1EdgeTokensUIDGet(params) + if err != nil { + return nil, err + } + token := resp.Payload + if token == nil { + return nil, errors.New("failed to list registration tokens") + } + return resp.Payload, nil +} + +// GetRegistrationTokenByName retrieves an existing registration token by name. +func (h *V1Client) GetRegistrationTokenByName(tokenName string) (*models.V1EdgeToken, error) { + // ACL scoped to tenant only + params := clientv1.NewV1EdgeTokensListParams() + resp, err := h.Client.V1EdgeTokensList(params) + if err != nil { + return nil, err + } + tokens := resp.GetPayload() + if tokens == nil { + return nil, errors.New("failed to list registration tokens") + } + for _, token := range tokens.Items { + if token.Metadata.Name == tokenName { + return token, nil + } + } + return nil, nil +} + // CreateRegistrationToken creates a new registration token. func (h *V1Client) CreateRegistrationToken(tokenName string, body *models.V1EdgeTokenEntity) (string, string, error) { // ACL scoped to tenant only @@ -46,6 +81,18 @@ func (h *V1Client) CreateRegistrationToken(tokenName string, body *models.V1Edge return *res.Payload.UID, token, err } +// UpdateRegistrationTokenByUID update an existing registration token by uid. +func (h *V1Client) UpdateRegistrationTokenByUID(tokenUID string, body *models.V1EdgeTokenUpdate) error { + // ACL scoped to tenant only + params := clientv1.NewV1EdgeTokensUIDUpdateParamsWithContext(h.ctx).WithUID(tokenUID). + WithBody(body) + _, err := h.Client.V1EdgeTokensUIDUpdate(params) + if err != nil { + return err + } + return nil +} + // DeleteRegistrationToken deletes a registration token by name. func (h *V1Client) DeleteRegistrationToken(tokenUID string) error { // ACL scoped to tenant only @@ -257,3 +304,10 @@ func (h *V1Client) GetNodeStatusMapEdgeNative(configUID, machinePoolName string) } return nMap, nil } + +// UpdateRegistrationTokenState set registration token state +func (h *V1Client) UpdateRegistrationTokenState(tokenUID string, body *models.V1EdgeTokenActiveState) error { + params := clientv1.NewV1EdgeTokensUIDStateParams().WithUID(tokenUID).WithBody(body) + _, err := h.Client.V1EdgeTokensUIDState(params) + return err +} diff --git a/client/cluster_group.go b/client/cluster_group.go index f9a127c4..309f9a5c 100644 --- a/client/cluster_group.go +++ b/client/cluster_group.go @@ -140,3 +140,17 @@ func (h *V1Client) clusterGroupMetadata() ([]*models.V1ObjectScopeEntity, error) } return resp.Payload.Items, nil } + +// UpdateSystemClusterGroupPreference updates system cluster group preferences. +func (h *V1Client) UpdateSystemClusterGroupPreference(tenantUID string, body *models.V1TenantEnableClusterGroup) error { + params := clientv1.NewV1TenantPrefClusterGroupUpdateParamsWithContext(h.ctx).WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantPrefClusterGroupUpdate(params) + return err +} + +// GetSystemClusterGroupPreference get system cluster group preferences. +func (h *V1Client) GetSystemClusterGroupPreference(tenantUID string) (*models.V1TenantEnableClusterGroup, error) { + params := clientv1.NewV1TenantPrefClusterGroupGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantPrefClusterGroupGet(params) + return resp.Payload, err +} diff --git a/client/developer_setting.go b/client/developer_setting.go new file mode 100644 index 00000000..bf49d74c --- /dev/null +++ b/client/developer_setting.go @@ -0,0 +1,20 @@ +package client + +import ( + clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1" + "github.com/spectrocloud/palette-sdk-go/api/models" +) + +// UpdateDeveloperSetting update a Developer Settings +func (h *V1Client) UpdateDeveloperSetting(tenantUID string, body *models.V1DeveloperCredit) error { + params := clientv1.NewV1TenantDeveloperCreditUpdateParamsWithContext(h.ctx).WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantDeveloperCreditUpdate(params) + return err +} + +// GetDeveloperSetting retrieves an existing a Developer Settings by tenant UID +func (h *V1Client) GetDeveloperSetting(tenantUID string) (*models.V1DeveloperCredit, error) { + params := clientv1.NewV1TenantDeveloperCreditGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantDeveloperCreditGet(params) + return resp.Payload, err +} diff --git a/client/platform_setting.go b/client/platform_setting.go new file mode 100644 index 00000000..a8dd6a02 --- /dev/null +++ b/client/platform_setting.go @@ -0,0 +1,92 @@ +package client + +import ( + clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1" + "github.com/spectrocloud/palette-sdk-go/api/models" +) + +// UpdateSessionTimeout update session timout for platform +func (h *V1Client) UpdateSessionTimeout(tenantUID string, body *models.V1AuthTokenSettings) error { + params := clientv1.NewV1TenantUIDAuthTokenSettingsUpdateParamsWithContext(h.ctx).WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantUIDAuthTokenSettingsUpdate(params) + return err +} + +// GetSessionTimeout get session timout for platform +func (h *V1Client) GetSessionTimeout(tenantUID string) (*models.V1AuthTokenSettings, error) { + params := clientv1.NewV1TenantUIDAuthTokenSettingsGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantUIDAuthTokenSettingsGet(params) + return resp.Payload, err +} + +// UpdatePlatformClusterUpgradeSetting update clusters agent upgrade setting for tenant +func (h *V1Client) UpdatePlatformClusterUpgradeSetting(body *models.V1ClusterUpgradeSettingsEntity) error { + params := clientv1.NewV1SpectroClustersUpgradeSettingsParamsWithContext(h.ctx).WithBody(body) + _, err := h.Client.V1SpectroClustersUpgradeSettings(params) + return err +} + +// GetPlatformClustersUpgradeSetting get clusters agent upgrade setting for tenant +func (h *V1Client) GetPlatformClustersUpgradeSetting() (*models.V1ClusterUpgradeSettingsEntity, error) { + params := clientv1.NewV1SpectroClustersUpgradeSettingsGetParamsWithContext(h.ctx) + resp, err := h.Client.V1SpectroClustersUpgradeSettingsGet(params) + return resp.Payload, err +} + +// UpdateClusterAutoRemediationForTenant update cluster auto remediation for platform +func (h *V1Client) UpdateClusterAutoRemediationForTenant(tenantUID string, body *models.V1NodesAutoRemediationSettings) error { + params := clientv1.NewV1TenantClustersNodesAutoRemediationSettingUpdateParamsWithContext(h.ctx). + WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantClustersNodesAutoRemediationSettingUpdate(params) + return err +} + +// GetClusterAutoRemediationForTenant get cluster auto remediation for platform +func (h *V1Client) GetClusterAutoRemediationForTenant(tenantUID string) (*models.V1TenantClusterSettings, error) { + params := clientv1.NewV1TenantClusterSettingsGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantClusterSettingsGet(params) + return resp.Payload, err +} + +// UpdateClusterAutoRemediationForProject update cluster auto remediation for project +func (h *V1Client) UpdateClusterAutoRemediationForProject(projectUID string, body *models.V1NodesAutoRemediationSettings) error { + params := clientv1.NewV1ProjectClustersNodesAutoRemediationSettingUpdateParamsWithContext(h.ctx). + WithUID(projectUID).WithBody(body) + _, err := h.Client.V1ProjectClustersNodesAutoRemediationSettingUpdate(params) + return err +} + +// GetClusterAutoRemediationForProject get cluster auto remediation for project +func (h *V1Client) GetClusterAutoRemediationForProject(projectUID string) (*models.V1ProjectClusterSettings, error) { + params := clientv1.NewV1ProjectClusterSettingsGetParamsWithContext(h.ctx).WithUID(projectUID) + resp, err := h.Client.V1ProjectClusterSettingsGet(params) + return resp.Payload, err +} + +// UpdateLoginBanner update login banner details for platform +func (h *V1Client) UpdateLoginBanner(tenantUID string, body *models.V1LoginBannerSettings) error { + params := clientv1.NewV1TenantUIDLoginBannerUpdateParamsWithContext(h.ctx).WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantUIDLoginBannerUpdate(params) + return err +} + +// GetLoginBanner get login banner details for platform +func (h *V1Client) GetLoginBanner(tenantUID string) (*models.V1LoginBannerSettings, error) { + params := clientv1.NewV1TenantUIDLoginBannerGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantUIDLoginBannerGet(params) + return resp.Payload, err +} + +// UpdateFIPSPreference update fips preference for platform +func (h *V1Client) UpdateFIPSPreference(tenantUID string, body *models.V1FipsSettings) error { + params := clientv1.NewV1TenantFipsSettingsUpdateParamsWithContext(h.ctx).WithTenantUID(tenantUID).WithBody(body) + _, err := h.Client.V1TenantFipsSettingsUpdate(params) + return err +} + +// GetFIPSPreference get fips preference for platform +func (h *V1Client) GetFIPSPreference(tenantUID string) (*models.V1FipsSettings, error) { + params := clientv1.NewV1TenantFipsSettingsGetParamsWithContext(h.ctx).WithTenantUID(tenantUID) + resp, err := h.Client.V1TenantFipsSettingsGet(params) + return resp.Payload, err +}