Skip to content

Commit

Permalink
remove multiple APIs that are removed from palette-api-go
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-gaur committed Jul 31, 2024
1 parent ad63992 commit a1b967c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 201 deletions.
79 changes: 0 additions & 79 deletions client/cluster_edge.go

This file was deleted.

79 changes: 0 additions & 79 deletions client/cluster_libvirt.go

This file was deleted.

29 changes: 23 additions & 6 deletions client/macro.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"errors"
clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
Expand All @@ -15,10 +16,14 @@ func (h *V1Client) CreateMacro(uid string, macros *models.V1Macros) error {
_, err := h.Client.V1ProjectsUIDMacrosCreate(params)
return err
}
tenantUID, err := h.GetTenantUID()
userInfo, err := h.GetUsersInfo()
if err != nil {
return err
}
if userInfo == nil {
return errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosCreateParams().
WithTenantUID(tenantUID).
Expand Down Expand Up @@ -57,10 +62,14 @@ func (h *V1Client) GetMacros(projectUID string) ([]*models.V1Macro, error) {
}
macros = resp.Payload.Macros
} else {
tenantUID, err := h.GetTenantUID()
if err != nil || tenantUID == "" {
userInfo, err := h.GetUsersInfo()
if err != nil {
return nil, err
}
if userInfo == nil {
return nil, errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosListParams().
WithTenantUID(tenantUID)
Expand All @@ -83,10 +92,14 @@ func (h *V1Client) UpdateMacro(uid string, macros *models.V1Macros) error {
_, err := h.Client.V1ProjectsUIDMacrosUpdateByMacroName(params)
return err
}
tenantUID, err := h.GetTenantUID()
if err != nil || tenantUID == "" {
userInfo, err := h.GetUsersInfo()
if err != nil {
return err
}
if userInfo == nil {
return errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosUpdateByMacroNameParams().
WithTenantUID(tenantUID).
Expand All @@ -106,10 +119,14 @@ func (h *V1Client) DeleteMacro(uid string, body *models.V1Macros) error {
return err
}
} else {
tenantUID, err := h.GetTenantUID()
userInfo, err := h.GetUsersInfo()
if err != nil {
return err
}
if userInfo == nil {
return errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams().
WithTenantUID(tenantUID).
Expand Down
35 changes: 28 additions & 7 deletions client/macros.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"errors"
"fmt"

clientv1 "github.com/spectrocloud/palette-api-go/client/v1"
Expand All @@ -18,10 +19,14 @@ func (h *V1Client) CreateMacros(uid string, macros *models.V1Macros) (string, er
return "", err
}
} else {
tenantUID, err := h.GetTenantUID()
userInfo, err := h.GetUsersInfo()
if err != nil {
return "", err
}
if userInfo == nil {
return "", errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosCreateParams().
WithTenantUID(tenantUID).
Expand Down Expand Up @@ -91,10 +96,14 @@ func (h *V1Client) GetMacrosV2(projectUID string) ([]*models.V1Macro, error) {
}
return macrosListOk.Payload.Macros, nil
}
tenantUID, err := h.GetTenantUID()
if err != nil || tenantUID == "" {
userInfo, err := h.GetUsersInfo()
if err != nil {
return nil, err
}
if userInfo == nil {
return nil, errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosListParams().
WithTenantUID(tenantUID)
Expand All @@ -114,10 +123,14 @@ func (h *V1Client) UpdateMacros(uid string, macros *models.V1Macros) error {
_, err := h.Client.V1ProjectsUIDMacrosUpdate(params)
return err
}
tenantUID, err := h.GetTenantUID()
if err != nil || tenantUID == "" {
userInfo, err := h.GetUsersInfo()
if err != nil {
return err
}
if userInfo == nil {
return errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosUpdateParams().
WithTenantUID(tenantUID).
Expand All @@ -135,10 +148,14 @@ func (h *V1Client) DeleteMacros(uid string, body *models.V1Macros) error {
_, err := h.Client.V1ProjectsUIDMacrosDeleteByMacroName(params)
return err
}
tenantUID, err := h.GetTenantUID()
userInfo, err := h.GetUsersInfo()
if err != nil {
return err
}
if userInfo == nil {
return errors.New("empty userinfo received from GetUsersInfo()")
}
tenantUID := userInfo.TenantUID
// As discussed with hubble team, we should not set context for tenant macros.
params := clientv1.NewV1TenantsUIDMacrosDeleteByMacroNameParams().
WithTenantUID(tenantUID).
Expand All @@ -154,10 +171,14 @@ func (h *V1Client) GetMacrosID(uid string) (string, error) {
if uid != "" {
hashID = fmt.Sprintf("%s-%s-%s", "project", "macros", uid)
} else {
tenantID, err := h.GetTenantUID()
userInfo, err := h.GetUsersInfo()
if err != nil {
return "", err
}
if userInfo == nil {
return "", errors.New("empty userinfo received from GetUsersInfo()")
}
tenantID := userInfo.TenantUID
hashID = fmt.Sprintf("%s-%s-%s", "tenant", "macros", tenantID)
}
return hashID, nil
Expand Down
30 changes: 0 additions & 30 deletions client/node_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUID, machineName, no
return resp.Payload.Status.MaintenanceStatus, nil
}

// GetNodeMaintenanceStatusEdge retrieves maintenance status for an edge node.
// TODO: edgev1 deprecation
func (h *V1Client) GetNodeMaintenanceStatusEdge(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) {
params := clientv1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUID).
WithMachinePoolName(machineName).
WithMachineUID(nodeID)

resp, err := h.Client.V1CloudConfigsEdgePoolMachinesUIDGet(params)
if err != nil {
return nil, err
}
return resp.Payload.Status.MaintenanceStatus, nil
}

// GetNodeMaintenanceStatusEdgeVsphere retrieves maintenance status for a vSphere edge node.
// TODO: edgev1 deprecation
func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) {
Expand Down Expand Up @@ -174,21 +159,6 @@ func (h *V1Client) GetNodeMaintenanceStatusGke(configUID, machineName, nodeID st
return resp.Payload.Status.MaintenanceStatus, nil
}

// GetNodeMaintenanceStatusLibvirt retrieves maintenance status for a libvirt node.
// TODO: edgev1 deprecation
func (h *V1Client) GetNodeMaintenanceStatusLibvirt(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) {
params := clientv1.NewV1CloudConfigsLibvirtPoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUID).
WithMachinePoolName(machineName).
WithMachineUID(nodeID)

resp, err := h.Client.V1CloudConfigsLibvirtPoolMachinesUIDGet(params)
if err != nil {
return nil, err
}
return resp.Payload.Status.MaintenanceStatus, nil
}

// GetNodeMaintenanceStatusOpenStack retrieves maintenance status for an OpenStack node.
func (h *V1Client) GetNodeMaintenanceStatusOpenStack(configUID, machineName, nodeID string) (*models.V1MachineMaintenanceStatus, error) {
params := clientv1.NewV1CloudConfigsOpenStackPoolMachinesUIDGetParamsWithContext(h.ctx).
Expand Down

0 comments on commit a1b967c

Please sign in to comment.