Skip to content

Commit

Permalink
Merge pull request #101 from Cloud-Temple/feature/100
Browse files Browse the repository at this point in the history
Removed  from every URL used by the provider to make it more dynamic and reliable
  • Loading branch information
Benjitul authored Nov 10, 2023
2 parents 7bb19c7 + e0804db commit d01efa2
Show file tree
Hide file tree
Showing 38 changed files with 115 additions and 100 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ provider "cloudtemple" {
### Optional

- `address` (String) The HTTP address to connect to the API. Defaults to `shiva.cloud-temple.com`. Can also be specified with the environment variable `CLOUDTEMPLE_HTTP_ADDR`.
- `api_suffix` (Boolean) Specify whether it is necessary to use an /api suffix after the address. (Used for development purpose only)
- `client_id` (String) The client ID to login to the API with. Can also be specified with the environment variable `CLOUDTEMPLE_CLIENT_ID`.
- `scheme` (String) The URL scheme to used to connect to the API. Default to `https`. Can also be specified with the environment variable `CLOUDTEMPLE_HTTP_SCHEME`.
- `secret_id` (String, Sensitive) The secret ID to login to the API with. Can also be specified with the environment variable `CLOUDTEMPLE_SECRET_ID`.
Expand Down
4 changes: 2 additions & 2 deletions internal/client/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ActivityConcernedItem struct {
}

func (c *ActivityClient) List(ctx context.Context, filter *struct{}) ([]*Activity, error) {
r := c.c.newRequest("GET", "/api/activity/v1/activities")
r := c.c.newRequest("GET", "/activity/v1/activities")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -61,7 +61,7 @@ func (c *ActivityClient) List(ctx context.Context, filter *struct{}) ([]*Activit
}

func (c *ActivityClient) Read(ctx context.Context, id string) (*Activity, error) {
r := c.c.newRequest("GET", "/api/activity/v1/activities/%s", id)
r := c.c.newRequest("GET", "/activity/v1/activities/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion internal/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
type Config struct {
Address string

ApiSuffix bool

Scheme string

HttpClient *http.Client
Expand Down Expand Up @@ -119,6 +121,10 @@ type request struct {
}

func (c *Client) newRequest(method, path string, args ...interface{}) *request {
if c.config.ApiSuffix {
path = "/api" + path
}

r := &request{
config: &c.config,
method: method,
Expand Down Expand Up @@ -208,7 +214,7 @@ func (c *Client) token(ctx context.Context) (*jwt.Token, error) {
}
}

r := c.newRequest("POST", "/api/iam/v2/auth/personal_access_token")
r := c.newRequest("POST", "/iam/v2/auth/personal_access_token")
r.obj = map[string]interface{}{
"id": c.config.ClientID,
"secret": c.config.SecretID,
Expand Down
6 changes: 3 additions & 3 deletions internal/client/backup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type BackupJobFilter struct {
}

func (c *BackupJobClient) List(ctx context.Context, filter *BackupJobFilter) ([]*BackupJob, error) {
r := c.c.newRequest("GET", "/api/backup/v1/jobs")
r := c.c.newRequest("GET", "/backup/v1/jobs")
if filter != nil && filter.Type != "" {
r.params.Add("type", filter.Type)
}
Expand All @@ -52,7 +52,7 @@ func (c *BackupJobClient) List(ctx context.Context, filter *BackupJobFilter) ([]
}

func (c *BackupJobClient) Read(ctx context.Context, id string) (*BackupJob, error) {
r := c.c.newRequest("GET", "/api/backup/v1/jobs/%s", id)
r := c.c.newRequest("GET", "/backup/v1/jobs/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -77,7 +77,7 @@ type BackupJobRunRequest struct {
}

func (c *BackupJobClient) Run(ctx context.Context, req *BackupJobRunRequest) (string, error) {
r := c.c.newRequest("POST", "/api/backup/v1/jobs/run")
r := c.c.newRequest("POST", "/backup/v1/jobs/run")
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/backup_job_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type BackupSLAPolicyStub struct {
}

func (c *BackupJobSessionClient) List(ctx context.Context, filter *struct{}) ([]*BackupJobSession, error) {
r := c.c.newRequest("GET", "/api/backup/v1/jobs/session")
r := c.c.newRequest("GET", "/backup/v1/jobs/session")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions internal/client/backup_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type BackupMetricsHistory struct {
}

func (c *BackupMetricsClient) History(ctx context.Context, rang int) (*BackupMetricsHistory, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/backup/history")
r := c.c.newRequest("GET", "/backup/v1/metrics/backup/history")
r.params.Add("range", strconv.Itoa(rang))
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand Down Expand Up @@ -51,7 +51,7 @@ type BackupMetricsCoverage struct {
}

func (c *BackupMetricsClient) Coverage(ctx context.Context) (*BackupMetricsCoverage, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/coverage")
r := c.c.newRequest("GET", "/backup/v1/metrics/coverage")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -79,7 +79,7 @@ type BackupMetricsVirtualMachines struct {
}

func (c *BackupMetricsClient) VirtualMachines(ctx context.Context) (*BackupMetricsVirtualMachines, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/vm")
r := c.c.newRequest("GET", "/backup/v1/metrics/vm")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -104,7 +104,7 @@ type BackupMetricsPolicies struct {
}

func (c *BackupMetricsClient) Policies(ctx context.Context) ([]*BackupMetricsPolicies, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/policies")
r := c.c.newRequest("GET", "/backup/v1/metrics/policies")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -132,7 +132,7 @@ type BackupMetricsPlatform struct {
}

func (c *BackupMetricsClient) Platform(ctx context.Context) (*BackupMetricsPlatform, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/plateform")
r := c.c.newRequest("GET", "/backup/v1/metrics/plateform")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -155,7 +155,7 @@ type BackupMetricsPlatformCPU struct {
}

func (c *BackupMetricsClient) PlatformCPU(ctx context.Context) (*BackupMetricsPlatformCPU, error) {
r := c.c.newRequest("GET", "/api/backup/v1/metrics/plateform/cpu")
r := c.c.newRequest("GET", "/backup/v1/metrics/plateform/cpu")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/client/backup_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type BackupSite struct {
}

func (c *BackupSiteClient) List(ctx context.Context) ([]*BackupSite, error) {
r := c.c.newRequest("GET", "/api/backup/v1/sites")
r := c.c.newRequest("GET", "/backup/v1/sites")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions internal/client/backup_sla_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type BackupSLAPolicyFilter struct {
}

func (c *BackupSLAPolicyClient) List(ctx context.Context, filter *BackupSLAPolicyFilter) ([]*BackupSLAPolicy, error) {
r := c.c.newRequest("GET", "/api/backup/v1/policies")
r := c.c.newRequest("GET", "/backup/v1/policies")
r.addFilter(filter)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -69,7 +69,7 @@ func (c *BackupSLAPolicyClient) List(ctx context.Context, filter *BackupSLAPolic
}

func (c *BackupSLAPolicyClient) Read(ctx context.Context, id string) (*BackupSLAPolicy, error) {
r := c.c.newRequest("GET", "/api/backup/v1/policies/%s", id)
r := c.c.newRequest("GET", "/backup/v1/policies/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -94,7 +94,7 @@ type BackupAssignVirtualMachineRequest struct {
}

func (c *BackupSLAPolicyClient) AssignVirtualMachine(ctx context.Context, req *BackupAssignVirtualMachineRequest) (string, error) {
r := c.c.newRequest("POST", "/api/backup/v1/policies/assign/virtual_machine")
r := c.c.newRequest("POST", "/backup/v1/policies/assign/virtual_machine")
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}
Expand All @@ -105,7 +105,7 @@ type BackupAssignVirtualDiskRequest struct {
}

func (c *BackupSLAPolicyClient) AssignVirtualDisk(ctx context.Context, req *BackupAssignVirtualDiskRequest) (string, error) {
r := c.c.newRequest("POST", "/api/backup/v1/policies/assign/virtual_disk")
r := c.c.newRequest("POST", "/backup/v1/policies/assign/virtual_disk")
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}
4 changes: 2 additions & 2 deletions internal/client/backup_spp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BackupSPPServer struct {
}

func (c *BackupSPPServerClient) List(ctx context.Context, tenantId string) ([]*BackupSPPServer, error) {
r := c.c.newRequest("GET", "/api/backup/v1/spp_servers")
r := c.c.newRequest("GET", "/backup/v1/spp_servers")
r.params.Add("tenantId", tenantId)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -37,7 +37,7 @@ func (c *BackupSPPServerClient) List(ctx context.Context, tenantId string) ([]*B
}

func (c *BackupSPPServerClient) Read(ctx context.Context, id string) (*BackupSPPServer, error) {
r := c.c.newRequest("GET", "/api/backup/v1/spp_servers/%s", id)
r := c.c.newRequest("GET", "/backup/v1/spp_servers/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/client/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type BackupStorageCapacity struct {
}

func (c *BackupStorageClient) List(ctx context.Context) ([]*BackupStorage, error) {
r := c.c.newRequest("GET", "/api/backup/v1/storages")
r := c.c.newRequest("GET", "/backup/v1/storages")
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/client/backup_vcenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type BackupVCenter struct {
}

func (c *BackupVCenterClient) List(ctx context.Context, sppServerId string) ([]*BackupVCenter, error) {
r := c.c.newRequest("GET", "/api/backup/v1/vcenters")
r := c.c.newRequest("GET", "/backup/v1/vcenters")
r.params.Add("sppServerId", sppServerId)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/backup_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type BackupVirtualMachine struct {
}

func (c *BackupVirtualMachineClient) Read(ctx context.Context, id string) (*BackupVirtualMachine, error) {
r := c.c.newRequest("GET", "/api/backup/v1/virtual_machines/%s", id)
r := c.c.newRequest("GET", "/backup/v1/virtual_machines/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions internal/client/compute_content_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ContentLibraryFilter struct {
}

func (c *ContentLibraryClient) List(ctx context.Context, filter *ContentLibraryFilter) ([]*ContentLibrary, error) {
r := c.c.newRequest("GET", "/api/compute/v1/vcenters/content_libraries")
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries")
r.addFilter(filter)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -52,7 +52,7 @@ func (c *ContentLibraryClient) List(ctx context.Context, filter *ContentLibraryF
}

func (c *ContentLibraryClient) Read(ctx context.Context, id string) (*ContentLibrary, error) {
r := c.c.newRequest("GET", "/api/compute/v1/vcenters/content_libraries/%s", id)
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s", id)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -90,7 +90,7 @@ type ContentLibraryItemFilter struct {
}

func (c *ContentLibraryClient) ListItems(ctx context.Context, filter *ContentLibraryItemFilter) ([]*ContentLibraryItem, error) {
r := c.c.newRequest("GET", "/api/compute/v1/vcenters/content_libraries/%s/items", filter.ContentLibraryId)
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s/items", filter.ContentLibraryId)
r.addFilter(filter)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -111,7 +111,7 @@ func (c *ContentLibraryClient) ListItems(ctx context.Context, filter *ContentLib
}

func (c *ContentLibraryClient) ReadItem(ctx context.Context, contentLibraryId, contentLibraryItemId string) (*ContentLibraryItem, error) {
r := c.c.newRequest("GET", "/api/compute/v1/vcenters/content_libraries/%s/items/%s", contentLibraryId, contentLibraryItemId)
r := c.c.newRequest("GET", "/compute/v1/vcenters/content_libraries/%s/items/%s", contentLibraryId, contentLibraryItemId)
resp, err := c.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -155,7 +155,7 @@ type NetworkData struct {
}

func (c *ContentLibraryClient) Deploy(ctx context.Context, req *ComputeContentLibraryItemDeployRequest) (string, error) {
r := c.c.newRequest("POST", "/api/compute/v1/vcenters/content_libraries/%s/items", req.ContentLibraryId)
r := c.c.newRequest("POST", "/compute/v1/vcenters/content_libraries/%s/items", req.ContentLibraryId)
r.obj = req
return c.c.doRequestAndReturnActivity(ctx, r)
}
4 changes: 2 additions & 2 deletions internal/client/compute_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (d *DatastoreClient) List(
filter *DatastoreFilter) ([]*Datastore, error) {

// TODO: filters
r := d.c.newRequest("GET", "/api/compute/v1/vcenters/datastores")
r := d.c.newRequest("GET", "/compute/v1/vcenters/datastores")
r.addFilter(filter)
resp, err := d.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -61,7 +61,7 @@ func (d *DatastoreClient) List(
}

func (d *DatastoreClient) Read(ctx context.Context, id string) (*Datastore, error) {
r := d.c.newRequest("GET", "/api/compute/v1/vcenters/datastores/%s", id)
r := d.c.newRequest("GET", "/compute/v1/vcenters/datastores/%s", id)
resp, err := d.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/client/compute_datastore_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type DatastoreClusterMetrics struct {

func (d *DatastoreClusterClient) List(ctx context.Context, filter *DatastoreClusterFilter) ([]*DatastoreCluster, error) {
// TODO: filters
r := d.c.newRequest("GET", "/api/compute/v1/vcenters/datastore_clusters")
r := d.c.newRequest("GET", "/compute/v1/vcenters/datastore_clusters")
r.addFilter(filter)
resp, err := d.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -65,7 +65,7 @@ func (d *DatastoreClusterClient) List(ctx context.Context, filter *DatastoreClus
}

func (d *DatastoreClusterClient) Read(ctx context.Context, id string) (*DatastoreCluster, error) {
r := d.c.newRequest("GET", "/api/compute/v1/vcenters/datastore_clusters/%s", id)
r := d.c.newRequest("GET", "/compute/v1/vcenters/datastore_clusters/%s", id)
resp, err := d.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/client/compute_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (f *FolderClient) List(
datacenterId string) ([]*Folder, error) {

// TODO: filters
r := f.c.newRequest("GET", "/api/compute/v1/vcenters/folders")
r := f.c.newRequest("GET", "/compute/v1/vcenters/folders")
resp, err := f.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -41,7 +41,7 @@ func (f *FolderClient) List(
}

func (f *FolderClient) Read(ctx context.Context, id string) (*Folder, error) {
r := f.c.newRequest("GET", "/api/compute/v1/vcenters/folders/%s", id)
r := f.c.newRequest("GET", "/compute/v1/vcenters/folders/%s", id)
resp, err := f.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/client/compute_guest_operating_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (g *GuestOperatingSystemClient) List(
osFamily string) ([]*GuestOperatingSystem, error) {

// TODO: filters
r := g.c.newRequest("GET", "/api/compute/v1/vcenters/guest_operating_systems")
r := g.c.newRequest("GET", "/compute/v1/vcenters/guest_operating_systems")
r.params.Add("machineManagerId", machineManagerId)
resp, err := g.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -45,7 +45,7 @@ func (g *GuestOperatingSystemClient) List(
}

func (g *GuestOperatingSystemClient) Read(ctx context.Context, machineManagerId string, moref string) (*GuestOperatingSystem, error) {
r := g.c.newRequest("GET", "/api/compute/v1/vcenters/guest_operating_systems/%s", moref)
r := g.c.newRequest("GET", "/compute/v1/vcenters/guest_operating_systems/%s", moref)
r.params.Add("machineManagerId", machineManagerId)
resp, err := g.c.doRequest(ctx, r)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/client/compute_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (h *HostClient) List(
datastoreID string) ([]*Host, error) {

// TODO: filters
r := h.c.newRequest("GET", "/api/compute/v1/vcenters/hosts")
r := h.c.newRequest("GET", "/compute/v1/vcenters/hosts")
resp, err := h.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand All @@ -78,7 +78,7 @@ func (h *HostClient) List(
}

func (h *HostClient) Read(ctx context.Context, id string) (*Host, error) {
r := h.c.newRequest("GET", "/api/compute/v1/vcenters/hosts/%s", id)
r := h.c.newRequest("GET", "/compute/v1/vcenters/hosts/%s", id)
resp, err := h.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/client/compute_host_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *HostClusterClient) List(
filter *HostClusterFilter) ([]*HostCluster, error) {

// TODO: filters
r := h.c.newRequest("GET", "/api/compute/v1/vcenters/host_clusters")
r := h.c.newRequest("GET", "/compute/v1/vcenters/host_clusters")
r.addFilter(filter)
resp, err := h.c.doRequest(ctx, r)
if err != nil {
Expand All @@ -66,7 +66,7 @@ func (h *HostClusterClient) List(
}

func (h *HostClusterClient) Read(ctx context.Context, id string) (*HostCluster, error) {
r := h.c.newRequest("GET", "/api/compute/v1/vcenters/host_clusters/%s", id)
r := h.c.newRequest("GET", "/compute/v1/vcenters/host_clusters/%s", id)
resp, err := h.c.doRequest(ctx, r)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit d01efa2

Please sign in to comment.