Skip to content

Commit

Permalink
feat: deprecate v1 api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-github committed Nov 21, 2024
1 parent 772f09e commit 6e328bd
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 77 deletions.
39 changes: 14 additions & 25 deletions xelon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ type Client struct {

common service // Reuse a single struct instead of allocating one for each service on the heap.

Clouds *CloudsService
Devices *DevicesService
Clouds *CloudsServiceV1
Devices *DevicesServiceV1
Kubernetes *KubernetesService
LoadBalancerClusters *LoadBalancerClustersService
LoadBalancers *LoadBalancersService
Networks *NetworksService
PersistentStorages *PersistentStoragesService
SSHKeys *SSHKeysService
Templates *TemplatesService
Tenants *TenantsService
Networks *NetworksServiceV1
PersistentStorages *PersistentStoragesServiceV1
SSHKeys *SSHKeysServiceV1
Templates *TemplatesServiceV1
Tenants *TenantsServiceV1
}

type service struct {
Expand Down Expand Up @@ -134,16 +134,16 @@ func NewClient(token string, opts ...ClientOption) *Client {

c.common.client = c

c.Clouds = (*CloudsService)(&c.common)
c.Devices = (*DevicesService)(&c.common)
c.Clouds = (*CloudsServiceV1)(&c.common)
c.Devices = (*DevicesServiceV1)(&c.common)
c.Kubernetes = (*KubernetesService)(&c.common)
c.LoadBalancerClusters = (*LoadBalancerClustersService)(&c.common)
c.LoadBalancers = (*LoadBalancersService)(&c.common)
c.Networks = (*NetworksService)(&c.common)
c.PersistentStorages = (*PersistentStoragesService)(&c.common)
c.SSHKeys = (*SSHKeysService)(&c.common)
c.Templates = (*TemplatesService)(&c.common)
c.Tenants = (*TenantsService)(&c.common)
c.Networks = (*NetworksServiceV1)(&c.common)
c.PersistentStorages = (*PersistentStoragesServiceV1)(&c.common)
c.SSHKeys = (*SSHKeysServiceV1)(&c.common)
c.Templates = (*TemplatesServiceV1)(&c.common)
c.Tenants = (*TenantsServiceV1)(&c.common)

// Notify user if no ClientID is set
if c.clientID == "" {
Expand All @@ -153,17 +153,6 @@ func NewClient(token string, opts ...ClientOption) *Client {
return c
}

// Deprecated: SetBaseURL overrides the default BaseURL. Use WithBaseURL instead.
func (c *Client) SetBaseURL(baseURL string) {
parsedURL, _ := url.Parse(baseURL)
c.baseURL = parsedURL
}

// Deprecated: SetUserAgent overrides the default UserAgent. Use WithUserAgent instead.
func (c *Client) SetUserAgent(ua string) {
c.userAgent = ua
}

// NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved
// relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash.
// If specified, the value pointed to by body is JSON encoded and included as the request body.
Expand Down
8 changes: 0 additions & 8 deletions xelon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ func TestClient_NewClient(t *testing.T) {
assert.Equal(t, "auth-token", client.token)
}

func TestClient_SetUserAgent(t *testing.T) {
client := &Client{}

client.SetUserAgent("custom-user-agent")

assert.Equal(t, "custom-user-agent", client.userAgent)
}

func TestClient_Defaults(t *testing.T) {
client := NewClient("auth-token")

Expand Down
7 changes: 4 additions & 3 deletions xelon/clouds.go → xelon/clouds_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

const cloudsBasePath = "hv"

// CloudsService handles communication with the organization's cloud related methods of the Xelon API.
type CloudsService service
// CloudsServiceV1 handles communication with the organization's cloud related methods of the Xelon API.
// Deprecated.
type CloudsServiceV1 service

type Cloud struct {
ID int `json:"id,omitempty"`
Expand All @@ -18,7 +19,7 @@ type Cloud struct {
Type int `json:"type,omitempty"`
}

func (s *CloudsService) List(ctx context.Context, tenantID string) ([]Cloud, *Response, error) {
func (s *CloudsServiceV1) List(ctx context.Context, tenantID string) ([]Cloud, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand Down
File renamed without changes.
19 changes: 10 additions & 9 deletions xelon/devices.go → xelon/devices_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

const devicesBasePath = "vmlist"

// DevicesService handles communication with the devices related methods of the Xelon API.
type DevicesService service
// DevicesServiceV1 handles communication with the devices related methods of the Xelon API.
// Deprecated.
type DevicesServiceV1 service

// Device represents a Xelon device.
type Device struct {
Expand Down Expand Up @@ -95,7 +96,7 @@ type DeviceRoot struct {
}

// List provides a list of all devices.
func (s *DevicesService) List(ctx context.Context, tenantID string, opts *DeviceListOptions) ([]DeviceLocalVMDetails, *Response, error) {
func (s *DevicesServiceV1) List(ctx context.Context, tenantID string, opts *DeviceListOptions) ([]DeviceLocalVMDetails, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand Down Expand Up @@ -126,7 +127,7 @@ func (s *DevicesService) List(ctx context.Context, tenantID string, opts *Device
}

// Get provides detailed information for a device identified by tenant and localvmid.
func (s *DevicesService) Get(ctx context.Context, tenantID, localVMID string) (*DeviceRoot, *Response, error) {
func (s *DevicesServiceV1) Get(ctx context.Context, tenantID, localVMID string) (*DeviceRoot, *Response, error) {
if tenantID == "" || localVMID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -148,7 +149,7 @@ func (s *DevicesService) Get(ctx context.Context, tenantID, localVMID string) (*
}

// Create makes a new device with given payload.
func (s *DevicesService) Create(ctx context.Context, createRequest *DeviceCreateRequest) (*DeviceCreateResponse, *Response, error) {
func (s *DevicesServiceV1) Create(ctx context.Context, createRequest *DeviceCreateRequest) (*DeviceCreateResponse, *Response, error) {
if createRequest == nil {
return nil, nil, ErrEmptyPayloadNotAllowed
}
Expand All @@ -170,7 +171,7 @@ func (s *DevicesService) Create(ctx context.Context, createRequest *DeviceCreate
}

// Delete removes a device identified by localvmid.
func (s *DevicesService) Delete(ctx context.Context, localVMID string) (*Response, error) {
func (s *DevicesServiceV1) Delete(ctx context.Context, localVMID string) (*Response, error) {
if localVMID == "" {
return nil, ErrEmptyArgument
}
Expand All @@ -186,7 +187,7 @@ func (s *DevicesService) Delete(ctx context.Context, localVMID string) (*Respons
}

// Start starts a specific device identified by localvmid.
func (s *DevicesService) Start(ctx context.Context, localVMID string) (*Response, error) {
func (s *DevicesServiceV1) Start(ctx context.Context, localVMID string) (*Response, error) {
if localVMID == "" {
return nil, ErrEmptyArgument
}
Expand All @@ -202,7 +203,7 @@ func (s *DevicesService) Start(ctx context.Context, localVMID string) (*Response
}

// Stop stops a specific device identified by localvmid.
func (s *DevicesService) Stop(ctx context.Context, localVMID string) (*Response, error) {
func (s *DevicesServiceV1) Stop(ctx context.Context, localVMID string) (*Response, error) {
if localVMID == "" {
return nil, ErrEmptyArgument
}
Expand All @@ -219,7 +220,7 @@ func (s *DevicesService) Stop(ctx context.Context, localVMID string) (*Response,

// GetDeviceCreationInfo retrieves a list of available templates, NICs,
// and scripts when creating a new device.
func (s *DevicesService) GetDeviceCreationInfo(ctx context.Context, tenantID, deviceCategory, deviceType string, templateID int) (*DeviceCreationInfo, *Response, error) {
func (s *DevicesServiceV1) GetDeviceCreationInfo(ctx context.Context, tenantID, deviceCategory, deviceType string, templateID int) (*DeviceCreationInfo, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand Down
19 changes: 10 additions & 9 deletions xelon/networks.go → xelon/networks_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

const networkBasePath = "networks"

// NetworksService handles communication with the network related methods of the Xelon API.
type NetworksService service
// NetworksServiceV1 handles communication with the network related methods of the Xelon API.
// Deprecated.
type NetworksServiceV1 service

type Network struct {
ID int `json:"id,omitempty"`
Expand Down Expand Up @@ -104,7 +105,7 @@ type networkRoot struct {
}

// List provides a list of all networks.
func (s *NetworksService) List(ctx context.Context, tenantID string) ([]Network, *Response, error) {
func (s *NetworksServiceV1) List(ctx context.Context, tenantID string) ([]Network, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -126,7 +127,7 @@ func (s *NetworksService) List(ctx context.Context, tenantID string) ([]Network,
}

// Get provides information about a network identified by local id.
func (s *NetworksService) Get(ctx context.Context, tenantID string, networkID int) (*NetworkInfo, *Response, error) {
func (s *NetworksServiceV1) Get(ctx context.Context, tenantID string, networkID int) (*NetworkInfo, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -148,7 +149,7 @@ func (s *NetworksService) Get(ctx context.Context, tenantID string, networkID in
}

// CreateLAN makes a new LAN network with given payload.
func (s *NetworksService) CreateLAN(ctx context.Context, tenantID string, createRequest *NetworkLANCreateRequest) (*APIResponse, *Response, error) {
func (s *NetworksServiceV1) CreateLAN(ctx context.Context, tenantID string, createRequest *NetworkLANCreateRequest) (*APIResponse, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -173,7 +174,7 @@ func (s *NetworksService) CreateLAN(ctx context.Context, tenantID string, create
}

// Update changes the configuration of a network.
func (s *NetworksService) Update(ctx context.Context, networkID int, updateRequest *NetworkUpdateRequest) (*APIResponse, *Response, error) {
func (s *NetworksServiceV1) Update(ctx context.Context, networkID int, updateRequest *NetworkUpdateRequest) (*APIResponse, *Response, error) {
if updateRequest == nil {
return nil, nil, ErrEmptyPayloadNotAllowed
}
Expand All @@ -195,7 +196,7 @@ func (s *NetworksService) Update(ctx context.Context, networkID int, updateReque
}

// Delete removes a network identified by id.
func (s *NetworksService) Delete(ctx context.Context, networkID int) (*Response, error) {
func (s *NetworksServiceV1) Delete(ctx context.Context, networkID int) (*Response, error) {
path := fmt.Sprintf("%v/%v/destroy", networkBasePath, networkID)

req, err := s.client.NewRequest(http.MethodDelete, path, nil)
Expand All @@ -207,7 +208,7 @@ func (s *NetworksService) Delete(ctx context.Context, networkID int) (*Response,
}

// AddIPAddress adds a new IP address to the specific network.
func (s *NetworksService) AddIPAddress(ctx context.Context, networkID int, addIPRequest *NetworkAddIPRequest) (*APIResponse, *Response, error) {
func (s *NetworksServiceV1) AddIPAddress(ctx context.Context, networkID int, addIPRequest *NetworkAddIPRequest) (*APIResponse, *Response, error) {
if addIPRequest == nil {
return nil, nil, ErrEmptyPayloadNotAllowed
}
Expand All @@ -229,7 +230,7 @@ func (s *NetworksService) AddIPAddress(ctx context.Context, networkID int, addIP
}

// DeleteIPAddress removes an IP from the specific network.
func (s *NetworksService) DeleteIPAddress(ctx context.Context, networkID, ipAddressID int) (*Response, error) {
func (s *NetworksServiceV1) DeleteIPAddress(ctx context.Context, networkID, ipAddressID int) (*Response, error) {
path := fmt.Sprintf("%v/%v/deleteIp?ipid=%v", networkBasePath, networkID, ipAddressID)

req, err := s.client.NewRequest(http.MethodDelete, path, nil)
Expand Down
21 changes: 11 additions & 10 deletions xelon/persistent_storages.go → xelon/persistent_storages_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

const persistentStorageBasePath = "persistentStorage"

// PersistentStoragesService handles communication with the persistent storage related methods of the Xelon API.
type PersistentStoragesService service
// PersistentStoragesServiceV1 handles communication with the persistent storage related methods of the Xelon API.
// Deprecated.
type PersistentStoragesServiceV1 service

type PersistentStorage struct {
AssignedServers []DeviceLocalVMDetails `json:"assigned_servers,omitempty"`
Expand All @@ -36,7 +37,7 @@ type PersistentStorageAttachDetachRequest struct {
ServerID []string `json:"server_id"`
}

func (s *PersistentStoragesService) List(ctx context.Context, tenantID string) ([]PersistentStorage, *Response, error) {
func (s *PersistentStoragesServiceV1) List(ctx context.Context, tenantID string) ([]PersistentStorage, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -56,7 +57,7 @@ func (s *PersistentStoragesService) List(ctx context.Context, tenantID string) (
return persistentStorages, resp, nil
}

func (s *PersistentStoragesService) Get(ctx context.Context, tenantID, localID string) (*PersistentStorage, *Response, error) {
func (s *PersistentStoragesServiceV1) Get(ctx context.Context, tenantID, localID string) (*PersistentStorage, *Response, error) {
if tenantID == "" || localID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -76,7 +77,7 @@ func (s *PersistentStoragesService) Get(ctx context.Context, tenantID, localID s
return persistentStorage, resp, nil
}

func (s *PersistentStoragesService) GetByName(ctx context.Context, tenantID, name string) (*PersistentStorage, *Response, error) {
func (s *PersistentStoragesServiceV1) GetByName(ctx context.Context, tenantID, name string) (*PersistentStorage, *Response, error) {
if tenantID == "" || name == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -96,7 +97,7 @@ func (s *PersistentStoragesService) GetByName(ctx context.Context, tenantID, nam
return persistentStorage, resp, nil
}

func (s *PersistentStoragesService) Create(ctx context.Context, tenantID string, createRequest *PersistentStorageCreateRequest) (*APIResponse, *Response, error) {
func (s *PersistentStoragesServiceV1) Create(ctx context.Context, tenantID string, createRequest *PersistentStorageCreateRequest) (*APIResponse, *Response, error) {
if tenantID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -119,7 +120,7 @@ func (s *PersistentStoragesService) Create(ctx context.Context, tenantID string,
return apiResponse, resp, nil
}

func (s *PersistentStoragesService) Extend(ctx context.Context, localID string, extendRequest *PersistentStorageExtendRequest) (*APIResponse, *Response, error) {
func (s *PersistentStoragesServiceV1) Extend(ctx context.Context, localID string, extendRequest *PersistentStorageExtendRequest) (*APIResponse, *Response, error) {
if localID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -142,7 +143,7 @@ func (s *PersistentStoragesService) Extend(ctx context.Context, localID string,
return apiResponse, resp, nil
}

func (s *PersistentStoragesService) Delete(ctx context.Context, tenantID, localID string) (*Response, error) {
func (s *PersistentStoragesServiceV1) Delete(ctx context.Context, tenantID, localID string) (*Response, error) {
if tenantID == "" || localID == "" {
return nil, ErrEmptyArgument
}
Expand All @@ -156,7 +157,7 @@ func (s *PersistentStoragesService) Delete(ctx context.Context, tenantID, localI
return s.client.Do(ctx, req, nil)
}

func (s *PersistentStoragesService) AttachToDevice(ctx context.Context, tenantID, localID string, attachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) {
func (s *PersistentStoragesServiceV1) AttachToDevice(ctx context.Context, tenantID, localID string, attachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) {
if tenantID == "" || localID == "" {
return nil, nil, ErrEmptyArgument
}
Expand All @@ -178,7 +179,7 @@ func (s *PersistentStoragesService) AttachToDevice(ctx context.Context, tenantID
return apiResponse, resp, nil
}

func (s *PersistentStoragesService) DetachFromDevice(ctx context.Context, tenantID, localID string, detachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) {
func (s *PersistentStoragesServiceV1) DetachFromDevice(ctx context.Context, tenantID, localID string, detachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error) {
if tenantID == "" || localID == "" {
return nil, nil, ErrEmptyArgument
}
Expand Down
11 changes: 6 additions & 5 deletions xelon/ssh_keys.go → xelon/ssh_keys_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

const sshBasePath = "vmlist/ssh"

// SSHKeysService handles communication with the ssh keys related methods of the Xelon API.
type SSHKeysService service
// SSHKeysServiceV1 handles communication with the ssh keys related methods of the Xelon API.
// Deprecated.
type SSHKeysServiceV1 service

// SSHKey represents a Xelon ssh key.
type SSHKey struct {
Expand All @@ -30,7 +31,7 @@ func (v SSHKey) String() string {
}

// List provides a list of all added SSH keys.
func (s *SSHKeysService) List(ctx context.Context) ([]SSHKey, *Response, error) {
func (s *SSHKeysServiceV1) List(ctx context.Context) ([]SSHKey, *Response, error) {
path := "sshKeys/"

req, err := s.client.NewRequest(http.MethodGet, path, nil)
Expand All @@ -48,7 +49,7 @@ func (s *SSHKeysService) List(ctx context.Context) ([]SSHKey, *Response, error)
}

// Create makes a new ssh key with given payload.
func (s *SSHKeysService) Create(ctx context.Context, createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error) {
func (s *SSHKeysServiceV1) Create(ctx context.Context, createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error) {
if createRequest == nil {
return nil, nil, ErrEmptyPayloadNotAllowed
}
Expand All @@ -70,7 +71,7 @@ func (s *SSHKeysService) Create(ctx context.Context, createRequest *SSHKeyCreate
}

// Delete removes a ssh key identified by id.
func (s *SSHKeysService) Delete(ctx context.Context, sshKeyID int) (*Response, error) {
func (s *SSHKeysServiceV1) Delete(ctx context.Context, sshKeyID int) (*Response, error) {
path := fmt.Sprintf("%v/%v/delete", sshBasePath, sshKeyID)
req, err := s.client.NewRequest(http.MethodDelete, path, nil)
if err != nil {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion xelon/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Stringify attempts to create a string representation of Xelon types.
func Stringify(message interface{}) string {
func Stringify(message any) string {
var buf bytes.Buffer
v := reflect.ValueOf(message)
stringifyValue(&buf, v)
Expand Down
Loading

0 comments on commit 6e328bd

Please sign in to comment.