From 5245428bbc334f48fb7b64535b75fd5a3bbfc676 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 30 Jan 2025 11:01:04 -0500 Subject: [PATCH] chore: add godoc comments includes extensive documentation improvements across multiple files in the `hcx` package. The changes primarily focus on adding detailed Go Doc comments to struct definitions and functions to enhance code readability and maintainability. Signed-off-by: Ryan Johnson --- hcx/activation.go | 14 ++++-- hcx/certificate.go | 5 +- hcx/client.go | 23 ++++++--- hcx/compute_profile.go | 27 +++++++++-- hcx/data_source_network_backing.go | 1 + hcx/jobs.go | 10 ++-- hcx/l2_extension.go | 23 +++++++-- hcx/location.go | 8 +++- hcx/network_profile.go | 26 +++++++++-- hcx/provider.go | 2 + hcx/resource_network_profile.go | 1 + hcx/role_mapping.go | 5 +- hcx/service_mesh.go | 17 ++++++- hcx/site_pairing.go | 21 +++++++-- hcx/sso.go | 21 +++++++-- hcx/utils.go | 75 +++++++++++++++++++++++++----- hcx/vcenter.go | 13 +++++- hcx/vmc.go | 42 ++++++++++++----- main.go | 1 + 19 files changed, 272 insertions(+), 63 deletions(-) diff --git a/hcx/activation.go b/hcx/activation.go index 4d73489..d2e41eb 100644 --- a/hcx/activation.go +++ b/hcx/activation.go @@ -11,25 +11,30 @@ import ( "net/http" ) +// ActivateBody represents the structure of the request body used for activation actions. type ActivateBody struct { Data ActivateData `json:"data"` } +// ActivateData represents the detailed activation data, which includes a list of activation items. type ActivateData struct { Items []ActivateDataItem `json:"items"` } +// ActivateDataItem represents an individual activation item, containing its specific configuration details. type ActivateDataItem struct { Config ActivateDataItemConfig `json:"config"` } +// ActivateDataItemConfig represents the configuration details for a specific activation item. type ActivateDataItemConfig struct { URL string `json:"url"` ActivationKey string `json:"activationKey"` UUID string `json:"UUID,omitempty"` } -// PostActivate ... +// PostActivate sends a request to activate a configuration using the provided body and returns the resulting +// ActivateBody object. Returns an error if the request fails or the response cannot be parsed. func PostActivate(c *Client, body ActivateBody) (ActivateBody, error) { resp := ActivateBody{} @@ -64,7 +69,8 @@ func PostActivate(c *Client, body ActivateBody) (ActivateBody, error) { return resp, nil } -// GetActivate ... +// GetActivate sends a request to retrieve the current activation configuration and returns the resulting ActivateBody +// object. Returns an error if the request fails or the response cannot be parsed. func GetActivate(c *Client) (ActivateBody, error) { resp := ActivateBody{} @@ -92,7 +98,9 @@ func GetActivate(c *Client) (ActivateBody, error) { return resp, nil } -// DeleteActivate ... +// DeleteActivate sends a request to remove the activation configuration using the provided body and returns the +// resulting ActivateBody object. Returns an error if the request fails or the response cannot be parsed. + func DeleteActivate(c *Client, body ActivateBody) (ActivateBody, error) { resp := ActivateBody{} diff --git a/hcx/certificate.go b/hcx/certificate.go index c4e77fb..59d7bc6 100644 --- a/hcx/certificate.go +++ b/hcx/certificate.go @@ -11,16 +11,19 @@ import ( "net/http" ) +// InsertCertificateBody represents the body structure used to insert a certificate. type InsertCertificateBody struct { Certificate string `json:"certificate"` } +// InsertCertificateResult represents the result of inserting a certificate, including success and completion status. type InsertCertificateResult struct { Success bool `json:"success"` Completed bool `json:"completed"` } -// InsertL2Extention ... +// InsertCertificate sends a request to create a new certificate using the provided body and returns an +// InsertCertificateResult object. Returns an error if the request fails or the response cannot be parsed. func InsertCertificate(c *Client, body InsertCertificateBody) (InsertCertificateResult, error) { resp := InsertCertificateResult{} diff --git a/hcx/client.go b/hcx/client.go index a027d5a..9b755f0 100644 --- a/hcx/client.go +++ b/hcx/client.go @@ -16,7 +16,7 @@ import ( "time" ) -// Client - +// Client represents a structure for managing HTTP communication and authentication details. type Client struct { HostURL string HTTPClient *http.Client @@ -30,28 +30,31 @@ type Client struct { AllowUnverifiedSSL bool } -// AuthStruct - +// AuthStruct represents a structure containing username and password for authentication purposes. type AuthStruct struct { Username string `json:"username"` Password string `json:"password"` } -// AuthResponse - +// AuthResponse represents the structure of a response returned after a successful authentication. type AuthResponse struct { UserID int `json:"user_id"` Username string `json:"username"` Token string `json:"token"` } +// Content represents a reusable structure containing a slice of strings, typically used for XML unmarshaling. type Content struct { Strings []string `xml:"string"` } +// Entries represents a collection of content entries, typically used for XML unmarshaling. type Entries struct { Entry []Content `xml:"entry"` } -// HCX Authentication +// HcxConnectorAuthenticate authenticates the client with the HCX service by sending a request with user credentials. +// It retrieves and stores the HCX authorization token required for subsequent requests. func (c *Client) HcxConnectorAuthenticate() error { rb, err := json.Marshal(AuthStruct{ @@ -126,14 +129,15 @@ func (c *Client) HcxConnectorAuthenticate() error { } - // parse response header + // Parse response header. c.Token = resp.Header.Get("x-hm-authorization") return nil } -// NewClient - +// NewClient initializes and returns a new Client instance with the provided configuration, including authentication +// details, HCX URL, and SSL settings. func NewClient(hcx, username *string, password *string, adminUsername *string, adminPassword *string, allowUnverifiedSSL *bool, vmcToken *string) (*Client, error) { c := Client{ HTTPClient: &http.Client{ @@ -152,6 +156,8 @@ func NewClient(hcx, username *string, password *string, adminUsername *string, a return &c, nil } +// doRequest performs an authenticated HTTP request. If the client is not yet authenticated, it performs authentication +// first, then executes the request. Returns the HTTP response, response body, and any encountered error. func (c *Client) doRequest(req *http.Request) (*http.Response, []byte, error) { if !c.IsAuthenticated { @@ -192,6 +198,9 @@ func (c *Client) doRequest(req *http.Request) (*http.Response, []byte, error) { return res, body, err } +// doAdminRequest executes an HTTP request using the admin credentials for Basic Authentication. It supports requests +// that require elevated permissions and optionally skips SSL verification. Returns the response, response body, and any +// encountered error. func (c *Client) doAdminRequest(req *http.Request) (*http.Response, []byte, error) { req.Header.Set("Accept", "application/json") @@ -232,6 +241,8 @@ func (c *Client) doAdminRequest(req *http.Request) (*http.Response, []byte, erro return res, body, err } +// doVmcRequest sends an HTTP request to the VMware Cloud (VMC) service. It uses the HCX token for authorization if +// present and optionally skips SSL verification. Returns the response, response body, and any encountered error. func (c *Client) doVmcRequest(req *http.Request) (*http.Response, []byte, error) { req.Header.Set("Accept", "application/json") diff --git a/hcx/compute_profile.go b/hcx/compute_profile.go index b9cfb1c..5fdef15 100644 --- a/hcx/compute_profile.go +++ b/hcx/compute_profile.go @@ -12,6 +12,7 @@ import ( "net/http" ) +// InsertComputeProfileBody represents the body structure for inserting a compute profile. type InsertComputeProfileBody struct { Computes []Compute `json:"compute"` ComputeProfileID string `json:"computeProfileId"` @@ -23,6 +24,7 @@ type InsertComputeProfileBody struct { Switches []Switch `json:"switches"` } +// Compute represents the compute resource configuration. type Compute struct { ComputeID string `json:"cmpId"` ComputeName string `json:"cmpName"` @@ -32,6 +34,7 @@ type Compute struct { Type string `json:"type"` } +// Storage represents a storage entity in a compute profile configuration. type Storage struct { ComputeID string `json:"cmpId"` ComputeName string `json:"cmpName"` @@ -41,6 +44,7 @@ type Storage struct { Type string `json:"type"` } +// DeploymentContainer represents a container holding deployment configuration. type DeploymentContainer struct { Computes []Compute `json:"compute"` CPUReservation int `json:"cpuReservation"` @@ -48,6 +52,7 @@ type DeploymentContainer struct { Storage []Storage `json:"storage"` } +// Network represents a network entity with associated details. type Network struct { Name string `json:"name"` ID string `json:"id"` @@ -56,14 +61,17 @@ type Network struct { Tags []string `json:"tags"` } +// Status represents the current state of an entity, typically used to indicate its operational or lifecycle state. type Status struct { State string `json:"state"` } +// Service represents a service with a specific name in a system configuration. type Service struct { Name string `json:"name"` } +// Switch represents a network switch with identifiable attributes. type Switch struct { ComputeID string `json:"cmpId"` ID string `json:"id"` @@ -72,19 +80,23 @@ type Switch struct { Type string `json:"type"` } +// InsertComputeProfileResult represents the result of an operation to insert a compute profile. type InsertComputeProfileResult struct { Data InsertComputeProfileResultData `json:"data"` } +// InsertComputeProfileResultData represents the result data for inserting a compute profile. type InsertComputeProfileResultData struct { InterconnectTaskID string `json:"interconnectTaskId"` ComputeProfileID string `json:"computeProfileId"` } +// GetComputeProfileResult represents a collection of compute profile details. type GetComputeProfileResult struct { Items []GetComputeProfileResultItem `json:"items"` } +// GetComputeProfileResultItem represents the details of a compute profile. type GetComputeProfileResultItem struct { ComputeProfileID string `json:"computeProfileId"` Name string `json:"name"` @@ -96,7 +108,8 @@ type GetComputeProfileResultItem struct { Switches []Switch `json:"switches"` } -// InsertComputeProfile ... +// InsertComputeProfile sends a request to create a new compute profile using the provided body and returns an +// InsertComputeProfileResult object. Returns an error if the request fails or the response cannot be parsed. func InsertComputeProfile(c *Client, body InsertComputeProfileBody) (InsertComputeProfileResult, error) { resp := InsertComputeProfileResult{} @@ -131,12 +144,14 @@ func InsertComputeProfile(c *Client, body InsertComputeProfileBody) (InsertCompu return resp, nil } -// DeleteComputeProfile ... -func DeleteComputeProfile(c *Client, computeprofileID string) (InsertComputeProfileResult, error) { +// DeleteComputeProfile sends a request to delete a specific compute profile identified by computeProfileID and an +// InsertComputeProfileResult object indicating the result of the operation. Returns an error if the request fails or +// the response cannot be parsed. +func DeleteComputeProfile(c *Client, computeProfileID string) (InsertComputeProfileResult, error) { resp := InsertComputeProfileResult{} - req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/hybridity/api/interconnect/computeProfiles/%s", c.HostURL, computeprofileID), nil) + req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/hybridity/api/interconnect/computeProfiles/%s", c.HostURL, computeProfileID), nil) if err != nil { fmt.Println(err) return resp, err @@ -159,7 +174,9 @@ func DeleteComputeProfile(c *Client, computeprofileID string) (InsertComputeProf return resp, nil } -// GetComputeProfile ... +// GetComputeProfile retrieves the details of a compute profile using the provided endpointID and computeProfileName, +// returning a GetComputeProfileResultItem object for the matching profile. Returns an error if the request fails, the +// response cannot be parsed, or no matching profile is found. func GetComputeProfile(c *Client, endpointID string, computeProfileName string) (GetComputeProfileResultItem, error) { resp := GetComputeProfileResult{} diff --git a/hcx/data_source_network_backing.go b/hcx/data_source_network_backing.go index 848c993..828546b 100644 --- a/hcx/data_source_network_backing.go +++ b/hcx/data_source_network_backing.go @@ -6,6 +6,7 @@ package hcx import ( "context" + "fmt" "github.com/vmware/terraform-provider-hcx/hcx/constants" "github.com/vmware/terraform-provider-hcx/hcx/validators" diff --git a/hcx/jobs.go b/hcx/jobs.go index 141858f..2384793 100644 --- a/hcx/jobs.go +++ b/hcx/jobs.go @@ -10,11 +10,13 @@ import ( "net/http" ) +// AppEngineStartStopResult represents the result of an App Engine start or stop operation. type AppEngineStartStopResult struct { Result string `json:"result"` } -// AppEngineStart ... +// AppEngineStart sends a request to start the App Engine component and returns the resulting AppEngineStartStopResult +// object. Returns an error if the request fails or the response cannot be parsed. func AppEngineStart(c *Client) (AppEngineStartStopResult, error) { resp := AppEngineStartStopResult{} @@ -42,7 +44,8 @@ func AppEngineStart(c *Client) (AppEngineStartStopResult, error) { return resp, nil } -// AppEngineStop ... +// AppEngineStop sends a request to stop the App Engine component and returns the resulting AppEngineStartStopResult +// object. Returns an error if the request fails or the response cannot be parsed. func AppEngineStop(c *Client) (AppEngineStartStopResult, error) { resp := AppEngineStartStopResult{} @@ -70,7 +73,8 @@ func AppEngineStop(c *Client) (AppEngineStartStopResult, error) { return resp, nil } -// GetAppEngineStatus ... +// GetAppEngineStatus sends a GET request to retrieve the current status of the App Engine component and returns the +// resulting AppEngineStartStopResult object. Returns an error if the request fails or the response cannot be parsed. func GetAppEngineStatus(c *Client) (AppEngineStartStopResult, error) { resp := AppEngineStartStopResult{} diff --git a/hcx/l2_extension.go b/hcx/l2_extension.go index 4a89e10..5cae1fb 100644 --- a/hcx/l2_extension.go +++ b/hcx/l2_extension.go @@ -12,6 +12,7 @@ import ( "net/http" ) +// InsertL2ExtensionBody represents the request body structure for creating a Layer 2 extension. type InsertL2ExtensionBody struct { VcGUID string `json:"vcGuid"` Gateway string `json:"gateway"` @@ -24,10 +25,13 @@ type InsertL2ExtensionBody struct { SourceNetwork SourceNetwork `json:"sourceNetwork"` } +// DestinationNetwork represents the configuration for a destination network in a Layer 2 extension setup. type DestinationNetwork struct { GatewayID string `json:"gatewayId"` } +// Destination represents the primary structure for encapsulating endpoint and resource details in a network extension +// setup. type Destination struct { EndpointID string `json:"endpointId"` EndpointName string `json:"endpointName"` @@ -37,44 +41,54 @@ type Destination struct { ResourceType string `json:"resourceType"` } +// Features defines a struct for enabling specific configurations such as egress optimization and mobility-optimized +// networking. type Features struct { EgressOptimization bool `json:"egressOptimization"` Mon bool `json:"mobilityOptimizedNetworking"` } +// SourceAppliance represents the source appliance information in a Layer 2 network extension configuration. type SourceAppliance struct { ApplianceID string `json:"applianceId"` } +// SourceNetwork represents the details of a network within a Layer 2 extension configuration. type SourceNetwork struct { NetworkID string `json:"networkId"` NetworkName string `json:"networkName"` NetworkType string `json:"networkType"` } +// InsertL2ExtensionResult represents the result of an InsertL2Extension operation. type InsertL2ExtensionResult struct { ID string `json:"id"` } +// GetL2ExtensionsResult represents the result of a request for fetching Layer 2 extensions information. type GetL2ExtensionsResult struct { Items []GetL2ExtensionsResultItem `json:"items"` } +// GetL2ExtensionsResultItem represents an item in the result of a Layer 2 extensions request. type GetL2ExtensionsResultItem struct { StretchID string `json:"stretchId"` OperationStatus OperationStatus `json:"operationStatus"` SourceNetwork SourceNetwork `json:"sourceNetwork"` } +// OperationStatus represents the status of an operation. type OperationStatus struct { State string `json:"state"` } +// DeleteL2ExtensionResult represents the result of a successful deletion of an L2 extension. type DeleteL2ExtensionResult struct { ID string `json:"id"` } -// InsertL2Extention ... +// InsertL2Extension sends a POST request to create a new L2 extension using the provided body and returns the resulting +// InsertL2ExtensionResult object. Returns an error if the request fails or the response cannot be parsed. func InsertL2Extension(c *Client, body InsertL2ExtensionBody) (InsertL2ExtensionResult, error) { resp := InsertL2ExtensionResult{} @@ -109,7 +123,9 @@ func InsertL2Extension(c *Client, body InsertL2ExtensionBody) (InsertL2Extension return resp, nil } -// GetL2Extensions ... +// GetL2Extensions sends a GET request to retrieve a list of L2 extensions and returns the resulting +// GetL2ExtensionsResultItem object matching the given networkName. Returns an error if the request fails, the response +// cannot be parsed, or no matching L2 extension is found. func GetL2Extensions(c *Client, networkName string) (GetL2ExtensionsResultItem, error) { resp := GetL2ExtensionsResult{} @@ -143,7 +159,8 @@ func GetL2Extensions(c *Client, networkName string) (GetL2ExtensionsResultItem, return GetL2ExtensionsResultItem{}, errors.New("cant find compute L2 extension") } -// DeleteL2Extension ... +// DeleteL2Extension sends a DELETE request to remove an L2 extension with the provided stretchID and returns the +// resulting DeleteL2ExtensionResult object. Returns an error if the request fails or the response cannot be parsed. func DeleteL2Extension(c *Client, stretchID string) (DeleteL2ExtensionResult, error) { resp := DeleteL2ExtensionResult{} diff --git a/hcx/location.go b/hcx/location.go index ae15897..92a59f8 100644 --- a/hcx/location.go +++ b/hcx/location.go @@ -11,6 +11,7 @@ import ( "net/http" ) +// SetLocationBody represents a structured request body for configuring location data in a system. type SetLocationBody struct { City string `json:"city"` Country string `json:"country"` @@ -20,6 +21,7 @@ type SetLocationBody struct { Longitude float64 `json:"longitude"` } +// GetLocationResult represents the response structure for location details fetched from an external service. type GetLocationResult struct { City string `json:"city"` Country string `json:"country"` @@ -29,7 +31,8 @@ type GetLocationResult struct { Longitude float64 `json:"longitude"` } -// SetLocation ... +// SetLocation sends request to update the location configuration using the provided body. Returns an error if the +// request fails or cannot be sent. func SetLocation(c *Client, body SetLocationBody) error { var buf bytes.Buffer @@ -54,7 +57,8 @@ func SetLocation(c *Client, body SetLocationBody) error { return nil } -// GetLocation ... +// GetLocation sends a request to retrieve the current location configuration and returns the resulting +// GetLocationResult object. Returns an error if the request fails or the response cannot be parsed. func GetLocation(c *Client) (GetLocationResult, error) { resp := GetLocationResult{} diff --git a/hcx/network_profile.go b/hcx/network_profile.go index 1f0ee7d..aab6476 100644 --- a/hcx/network_profile.go +++ b/hcx/network_profile.go @@ -12,6 +12,7 @@ import ( "net/http" ) +// NetworkProfileBody defines the structure for a network profile. type NetworkProfileBody struct { Backings []Backing `json:"backings"` Description string `json:"description"` @@ -24,15 +25,18 @@ type NetworkProfileBody struct { ObjectID string `json:"objectId,omitempty"` } +// Filter defines properties for filtering network profiles or interfaces based on system ownership and trunking. type Filter struct { OwnedBySystem bool `json:"ownedBySystem"` AllowTrunkInterfaces bool `json:"allowTrunkInterfaces"` } +// NetworkFilter represents a network filtering structure containing filter criteria to query network profiles. type NetworkFilter struct { Filter Filter `json:"filter"` } +// Backing represents a network backing configuration used in network profiles. type Backing struct { BackingID string `json:"backingId"` BackingName string `json:"backingName"` @@ -41,6 +45,7 @@ type Backing struct { VCenterName string `json:"vCenterName,omitempty"` } +// IPScope defines the IP scope configuration for a network. type IPScope struct { DNSSuffix string `json:"dnsSuffix,omitempty"` Gateway string `json:"gateway,omitempty"` @@ -51,11 +56,13 @@ type IPScope struct { PoolID string `json:"poolId"` } +// NetworkIPRange represents an IP range with a start and end address in a network configuration. type NetworkIPRange struct { EndAddress string `json:"endAddress"` StartAddress string `json:"startAddress"` } +// NetworkProfileResult represents the result of a network profile operation, containing its outcome and related data. type NetworkProfileResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -63,12 +70,14 @@ type NetworkProfileResult struct { Data NetworkProfileData `json:"data"` } +// NetworkProfileData represents network profile-related metadata with a Job ID and an Object ID. type NetworkProfileData struct { JobID string `json:"jobId"` ObjectID string `json:"objectId"` } -// InsertNetworkProfile ... +// InsertNetworkProfile sends a request to create a new network profile using the provided body and returns the +// resulting NetworkProfileResult object. Returns an error if the request fails or the response cannot be parsed. func InsertNetworkProfile(c *Client, body NetworkProfileBody) (NetworkProfileResult, error) { resp := NetworkProfileResult{} @@ -103,7 +112,9 @@ func InsertNetworkProfile(c *Client, body NetworkProfileBody) (NetworkProfileRes return resp, nil } -// GetNetworkProfile ... +// GetNetworkProfile sends a request to query the list of network profiles and returns the NetworkProfileBody object +// matching the specified name. Returns an error if the request fails, the response cannot be parsed, or no profile is +// found with the given name. func GetNetworkProfile(c *Client, name string) (NetworkProfileBody, error) { resp := []NetworkProfileBody{} @@ -150,7 +161,9 @@ func GetNetworkProfile(c *Client, name string) (NetworkProfileBody, error) { return NetworkProfileBody{}, errors.New("cannot find network profile") } -// GetNetworkProfileByID ... +// GetNetworkProfileByID sends a request to query the list of network profiles and returns the NetworkProfileBody object +// matching the specified ID. Returns an error if the request fails, the response cannot be parsed, or no profile is +// found with the given ID. func GetNetworkProfileByID(c *Client, id string) (NetworkProfileBody, error) { resp := []NetworkProfileBody{} @@ -197,7 +210,9 @@ func GetNetworkProfileByID(c *Client, id string) (NetworkProfileBody, error) { return NetworkProfileBody{}, errors.New("cannot find network profile") } -// DeleteNetworkProfile ... +// DeleteNetworkProfile sends a DELETE request to remove a network profile identified by the provided networkID and +// returns the resulting NetworkProfileResult object. Returns an error if the request fails or the response cannot be +// parsed. func DeleteNetworkProfile(c *Client, networkID string) (NetworkProfileResult, error) { resp := NetworkProfileResult{} @@ -225,7 +240,8 @@ func DeleteNetworkProfile(c *Client, networkID string) (NetworkProfileResult, er return resp, nil } -// UpdateNetworkProfile ... +// UpdateNetworkProfile sends a request to update a network profile using the provided body and returns the resulting +// NetworkProfileResult object. Returns an error if the request fails or the response cannot be parsed. func UpdateNetworkProfile(c *Client, body NetworkProfileBody) (NetworkProfileResult, error) { resp := NetworkProfileResult{} diff --git a/hcx/provider.go b/hcx/provider.go index 411222f..9b22244 100644 --- a/hcx/provider.go +++ b/hcx/provider.go @@ -83,6 +83,8 @@ func Provider() *schema.Provider { } } +// providerConfigure initializes and configures the provider client with the provided schema parameters and context. +// Returns the initialized client interface and diagnostics for any issues encountered during configuration. func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { var diags diag.Diagnostics diff --git a/hcx/resource_network_profile.go b/hcx/resource_network_profile.go index 6ce2306..3ac1653 100644 --- a/hcx/resource_network_profile.go +++ b/hcx/resource_network_profile.go @@ -6,6 +6,7 @@ package hcx import ( "context" + "fmt" "time" "github.com/vmware/terraform-provider-hcx/hcx/constants" diff --git a/hcx/role_mapping.go b/hcx/role_mapping.go index 107f387..5e8389a 100644 --- a/hcx/role_mapping.go +++ b/hcx/role_mapping.go @@ -11,18 +11,21 @@ import ( "net/http" ) +// RoleMapping represents the association between a role and a list of user groups. type RoleMapping struct { Role string `json:"role"` UserGroups []string `json:"userGroups"` } +// RoleMappingResult represents the result of a role mapping operation. type RoleMappingResult struct { IsSuccess bool `json:"isSuccess"` Message string `json:"message"` HTTPStatusCode int `json:"httpStatusCode"` } -// PostActivate ... +// PutRoleMapping sends a PUT request to update role mappings using the provided body and returns the resulting +// RoleMappingResult object. Returns an error if the request fails or the response cannot be parsed. func PutRoleMapping(c *Client, body []RoleMapping) (RoleMappingResult, error) { resp := RoleMappingResult{} diff --git a/hcx/service_mesh.go b/hcx/service_mesh.go index 9281e4d..53c7dc1 100644 --- a/hcx/service_mesh.go +++ b/hcx/service_mesh.go @@ -11,6 +11,7 @@ import ( "net/http" ) +// ComputeProfile represents a configuration profile for a specific compute endpoint. type ComputeProfile struct { ComputeProfileID string `json:"computeProfileId"` ComputeProfileName string `json:"computeProfileName"` @@ -18,20 +19,24 @@ type ComputeProfile struct { EndpointName string `json:"endpointName"` } +// WanoptConfig represents WAN optimization configuration with uplink maximum bandwidth properties. type WanoptConfig struct { UplinkMaxBandwidth int `json:"uplinkMaxBandwidth"` } +// TrafficEnggCfg represents the configuration for traffic engineering settings. type TrafficEnggCfg struct { IsAppPathResiliencyEnabled bool `json:"isAppPathResiliencyEnabled"` IsTCPFlowConditioningEnabled bool `json:"isTcpFlowConditioningEnabled"` } +// SwitchPairCount represents a pairing of switches with a count of Layer 2 appliances in a network configuration. type SwitchPairCount struct { Switches []Switch `json:"switches"` L2cApplianceCount int `json:"l2cApplianceCount"` } +// InsertServiceMeshBody represents the body structure required to insert a service mesh configuration. type InsertServiceMeshBody struct { Name string `json:"name"` ComputeProfiles []ComputeProfile `json:"computeProfiles"` @@ -41,25 +46,31 @@ type InsertServiceMeshBody struct { SwitchPairCount []SwitchPairCount `json:"switchPairCount"` } +// InsertServiceMeshResult represents the result returned after inserting a service mesh configuration. It contains the +// data defining the created service mesh. type InsertServiceMeshResult struct { Data InsertServiceMeshData `json:"data"` } +// InsertServiceMeshData represents the structure for storing information about a service mesh insertion task. type InsertServiceMeshData struct { InterconnectID string `json:"interconnectTaskId"` ServiceMeshID string `json:"serviceMeshId"` } +// DeleteServiceMeshResult represents the result obtained after attempting to delete a service mesh. type DeleteServiceMeshResult struct { Data DeleteServiceMeshData `json:"data"` } +// DeleteServiceMeshData represents the payload required to request the deletion of a service mesh. type DeleteServiceMeshData struct { InterconnectTaskID string `json:"interconnectTaskId"` ServiceMeshID string `json:"serviceMeshId"` } -// InsertServiceMesh ... +// InsertServiceMesh sends a request to create a new service mesh using the provided body and returns the resulting +// InsertServiceMeshResult object. Returns an error if the request fails or the response cannot be parsed. func InsertServiceMesh(c *Client, body InsertServiceMeshBody) (InsertServiceMeshResult, error) { resp := InsertServiceMeshResult{} @@ -94,7 +105,9 @@ func InsertServiceMesh(c *Client, body InsertServiceMeshBody) (InsertServiceMesh return resp, nil } -// DeleteServiceMesh ... +// DeleteServiceMesh sends a request to remove a service mesh identified by the serviceMeshID. The force parameter +// determines whether to forcibly delete it. Returns the resulting DeleteServiceMeshResult object or an error if the +// request fails or the response cannot be parsed. func DeleteServiceMesh(c *Client, serviceMeshID string, force bool) (DeleteServiceMeshResult, error) { resp := DeleteServiceMeshResult{} diff --git a/hcx/site_pairing.go b/hcx/site_pairing.go index 396e3f7..cd2e7d1 100644 --- a/hcx/site_pairing.go +++ b/hcx/site_pairing.go @@ -11,6 +11,7 @@ import ( "net/http" ) +// RemoteData represents the structure required for remote connection configurations. type RemoteData struct { Username string `json:"username"` Password string `json:"password"` @@ -19,14 +20,19 @@ type RemoteData struct { CloudType string `json:"cloudType,omitempty"` } +// RemoteCloudConfigBody represents the request body for configuring remote cloud connections. type RemoteCloudConfigBody struct { Remote RemoteData `json:"remote"` } +// PostRemoteCloudConfigResultData represents the result data containing the job identifier for a remote cloud +// configuration task. type PostRemoteCloudConfigResultData struct { JobID string `json:"jobId"` } +// PostRemoteCloudConfigResult represents the result of posting a remote cloud configuration, including metadata and +// outcomes. type PostRemoteCloudConfigResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -36,12 +42,14 @@ type PostRemoteCloudConfigResult struct { Errors []PostRemoteCloudConfigResultError `json:"errors"` } +// PostRemoteCloudConfigResultError represents an error from posting a remote cloud configuration. type PostRemoteCloudConfigResultError struct { Error string `json:"error"` Text string `json:"text"` Data []map[string]interface{} `json:"data"` } +// GetRemoteCloudConfigResult represents the result of retrieving remote cloud configuration data. type GetRemoteCloudConfigResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -50,17 +58,21 @@ type GetRemoteCloudConfigResult struct { Data GetRemoteCloudConfigResultData `json:"data"` } +// GetRemoteCloudConfigResultData represents the result data containing remote cloud configuration items. type GetRemoteCloudConfigResultData struct { Items []RemoteData `json:"items"` } +// DeleteRemoteCloudConfigResult represents the outcome of a request to delete a remote cloud configuration. +// It includes success status, completion status, and the time of the operation as a Unix timestamp. type DeleteRemoteCloudConfigResult struct { Success bool `json:"success"` Completed bool `json:"completed"` Time int64 `json:"time"` } -// InsertSitePairing ... +// InsertSitePairing sends a request to create a new site pairing using the provided body and returns the resulting +// PostRemoteCloudConfigResult object. Returns an error if the request fails or the response cannot be parsed. func InsertSitePairing(c *Client, body RemoteCloudConfigBody) (PostRemoteCloudConfigResult, error) { resp := PostRemoteCloudConfigResult{} @@ -95,7 +107,8 @@ func InsertSitePairing(c *Client, body RemoteCloudConfigBody) (PostRemoteCloudCo return resp, nil } -// GetSitePairings ... +// GetSitePairings sends a GET request to retrieve all existing site pairings and returns the resulting +// GetRemoteCloudConfigResult object. Returns an error if the request fails or the response cannot be parsed. func GetSitePairings(c *Client) (GetRemoteCloudConfigResult, error) { resp := GetRemoteCloudConfigResult{} @@ -123,7 +136,9 @@ func GetSitePairings(c *Client) (GetRemoteCloudConfigResult, error) { return resp, nil } -// DeleteSitePairings ... +// DeleteSitePairings sends a DELETE request to remove a site pairing identified by the provided endpointID and returns +// the resulting DeleteRemoteCloudConfigResult object. Returns an error if the request fails or the response cannot be +// parsed. func DeleteSitePairings(c *Client, endpointID string) (DeleteRemoteCloudConfigResult, error) { resp := DeleteRemoteCloudConfigResult{} diff --git a/hcx/sso.go b/hcx/sso.go index 7f47bf4..33fbee9 100644 --- a/hcx/sso.go +++ b/hcx/sso.go @@ -11,37 +11,47 @@ import ( "net/http" ) +// InsertSSOBody represents the structure required for inserting Single Sign-On configurations with associated data. type InsertSSOBody struct { Data InsertSSOData `json:"data"` } +// InsertSSOData represents the structure for inserting Single Sign-On configuration data, containing a list of +// configuration items. type InsertSSOData struct { Items []InsertSSODataItem `json:"items"` } +// InsertSSODataItem represents a single Single Sign-On data configuration item containing its associated configuration +// details. type InsertSSODataItem struct { Config InsertSSODataItemConfig `json:"config"` } +// InsertSSODataItemConfig represents the configuration for a Single Sign-On data item. type InsertSSODataItemConfig struct { LookupServiceURL string `json:"lookupServiceUrl"` ProviderType string `json:"providerType"` UUID string `json:"UUID,omitempty"` } +// InsertSSOResult represents the result of an operation to insert a Single Sign-On configuration data. type InsertSSOResult struct { InsertSSOData InsertSSOData `json:"data"` } +// DeleteSSOResult represents the result of a delete operation for Single Sign-On. type DeleteSSOResult struct { InsertSSOData InsertSSOData `json:"data"` } +// GetSSOResult represents the result of retrieving the current Single Sign-On configuration. type GetSSOResult struct { InsertSSOData InsertSSOData `json:"data"` } -// GetSSO ... +// GetSSO sends a GET request to retrieve the current SSO configuration and returns the resulting GetSSOResult object. +// Returns an error if the request fails or the response cannot be parsed. func GetSSO(c *Client) (GetSSOResult, error) { resp := GetSSOResult{} @@ -69,7 +79,8 @@ func GetSSO(c *Client) (GetSSOResult, error) { return resp, nil } -// InsertSSO ... +// InsertSSO sends a POST request to create a new SSO configuration using the provided body and returns the resulting +// InsertSSOResult object. Returns an error if the request fails or the response cannot be parsed. func InsertSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) { resp := InsertSSOResult{} @@ -104,7 +115,8 @@ func InsertSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) { return resp, nil } -// UpdateSSO ... +// UpdateSSO sends a POST request to update the existing SSO configuration using the provided body. It returns the +// resulting InsertSSOResult object or an error if the request fails or the response cannot be parsed. func UpdateSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) { resp := InsertSSOResult{} @@ -139,7 +151,8 @@ func UpdateSSO(c *Client, body InsertSSOBody) (InsertSSOResult, error) { return resp, nil } -// DeleteSSO ... +// DeleteSSO sends a DELETE request to remove the SSO configuration identified by the provided SSOUUID and returns the +// resulting DeleteSSOResult object. Returns an error if the request fails or the response cannot be parsed. func DeleteSSO(c *Client, SSOUUID string) (DeleteSSOResult, error) { resp := DeleteSSOResult{} diff --git a/hcx/utils.go b/hcx/utils.go index 432ac78..10a48dc 100644 --- a/hcx/utils.go +++ b/hcx/utils.go @@ -13,6 +13,7 @@ import ( "net/http" ) +// JobResult represents the result of a job execution, including its status, timing, and completion details. type JobResult struct { JobID string `json:"jobId"` Enterprise string `json:"enterprise"` @@ -31,24 +32,29 @@ type JobResult struct { TimeToExecute int64 `json:"timeToExecute"` } +// TaskResult represents the result of a run. type TaskResult struct { InterconnectTaskID string `json:"interconnectTaskId"` Status string `json:"status"` } +// ResourceContainerListFilterCloud defines a filter structure for categorizing resource containers as local or remote. type ResourceContainerListFilterCloud struct { Local bool `json:"local"` Remote bool `json:"remote"` } +// ResourceContainerListFilter defines a structure for filtering resource containers based on cloud characteristics. type ResourceContainerListFilter struct { Cloud ResourceContainerListFilterCloud `json:"cloud"` } +// PostResourceContainerListBody defines the request body for retrieving a filtered list of resource containers. type PostResourceContainerListBody struct { Filter ResourceContainerListFilter `json:"filter"` } +// PostResourceContainerListResult represents the result of a resource container list request, including success status. type PostResourceContainerListResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -56,10 +62,13 @@ type PostResourceContainerListResult struct { Data PostResourceContainerListResultData `json:"data"` } +// PostResourceContainerListResultData represents the data structure for a container list result containing resource +// items. type PostResourceContainerListResultData struct { Items []PostResourceContainerListResultDataItem `json:"items"` } +// PostResourceContainerListResultDataItem defines a structure representing a single resource container in the list. type PostResourceContainerListResultDataItem struct { URL string `json:"url"` VcUUID string `json:"vcuuid"` @@ -85,28 +94,34 @@ type PostNetworkBackingBodyFilter struct { //BackingTypes []string `json:"backingTypes"` } +// PostNetworkBackingResult represents the structure for the response of a network backing operation, containing data. type PostNetworkBackingResult struct { Data PostNetworkBackingResultData `json:"data"` } +// PostNetworkBackingResultData represents the response containing a list of distributed port groups. type PostNetworkBackingResultData struct { Items []Dvpg `json:"items"` } +// Dvpg represents a distributed port group with associated metadata. type Dvpg struct { EntityID string `json:"entity_id"` Name string `json:"name"` EntityType string `json:"entityType"` } +// GetVcInventoryResult represents the structure for the vCenter inventory result containing data about inventory items. type GetVcInventoryResult struct { Data GetVcInventoryResultData `json:"data"` } +// GetVcInventoryResultData represents the structure containing a list of vCenter instance inventory result data items. type GetVcInventoryResultData struct { Items []GetVcInventoryResultDataItem `json:"items"` } +// GetVcInventoryResultDataItem represents an inventory item in a vCenter instance including its children and metadata. type GetVcInventoryResultDataItem struct { VCenterInstanceID string `json:"vcenter_instanceId"` EntityID string `json:"entity_id"` @@ -115,6 +130,8 @@ type GetVcInventoryResultDataItem struct { EntityType string `json:"entityType"` } +// GetVcInventoryResultDataItemChildren represents an inventory item in vCenter instance with nested children and +// metadata. type GetVcInventoryResultDataItemChildren struct { VCenterInstanceID string `json:"vcenter_instanceId"` EntityID string `json:"entity_id"` @@ -123,6 +140,7 @@ type GetVcInventoryResultDataItemChildren struct { EntityType string `json:"entityType"` } +// GetVcInventoryResultDataItemChildrenChildren represents nested child items in a vCenter instance inventory structure. type GetVcInventoryResultDataItemChildrenChildren struct { VCenterInstanceID string `json:"vcenter_instanceId"` EntityID string `json:"entity_id"` @@ -131,6 +149,7 @@ type GetVcInventoryResultDataItemChildrenChildren struct { // Datastores } +// GetVcDatastoreResult represents the result of a query for vCenter instance datastore information. type GetVcDatastoreResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -138,26 +157,32 @@ type GetVcDatastoreResult struct { Data GetVcDatastoreResultData `json:"data"` } +// GetVcDatastoreResultData represents a collection of datastore result items retrieved from a vCenter instance. type GetVcDatastoreResultData struct { Items []GetVcDatastoreResultDataItem `json:"items"` } +// GetVcDatastoreResultDataItem represents a single datastore entity retrieved from the vCenter instance. type GetVcDatastoreResultDataItem struct { ID string `json:"id"` Name string `json:"name"` EntityType string `json:"entity_type"` } +// GetVcDatastoreBody represents the body of the request for querying vCenter instance datastores using specified +// filters. type GetVcDatastoreBody struct { Filter GetVcDatastoreFilter `json:"filter"` } +// GetVcDatastoreFilter defines a filter for querying vCenter instance datastoress. type GetVcDatastoreFilter struct { ComputeType string `json:"computeType"` VCenterInstanceID string `json:"vcenter_instanceId"` ComputeIDs []string `json:"computeIds"` } +// GetVcDvsResult represents the result of querying a distributed switch in a vCenter instance. type GetVcDvsResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -165,10 +190,12 @@ type GetVcDvsResult struct { Data GetVcDvsResultData `json:"data"` } +// GetVcDvsResultData represents a collection of distributed switch data retrieved from a vCenter instance. type GetVcDvsResultData struct { Items []GetVcDvsResultDataItem `json:"items"` } +// GetVcDvsResultDataItem represents an individual distributed virtual switch retrieved from a vCenter instance. type GetVcDvsResultDataItem struct { ID string `json:"id"` Name string `json:"name"` @@ -176,25 +203,30 @@ type GetVcDvsResultDataItem struct { MaxMTU int `json:"maxMtu"` } +// GetVcDvsBody represents the request body containing parameters to query a distributed switch. type GetVcDvsBody struct { Filter GetVcDvsFilter `json:"filter"` } +// GetVcDvsFilter represents the filter criteria for querying distributed switches in a vCenter instance. type GetVcDvsFilter struct { ComputeType string `json:"computeType"` VCenterInstanceID string `json:"vcenter_instanceId"` ComputeIDs []string `json:"computeIds"` } +// PostCloudListFilter is a struct used to filter cloud list requests based on "local" or "remote" cloud availability. type PostCloudListFilter struct { Local bool `json:"local"` Remote bool `json:"remote"` } +// PostCloudListBody represents the body of a request to retrieve a filtered list of clouds. type PostCloudListBody struct { Filter PostCloudListFilter `json:"filter"` } +// PostCloudListResult contains the structure for response data from a cloud list request. type PostCloudListResult struct { Success bool `json:"success"` Completed bool `json:"completed"` @@ -202,10 +234,12 @@ type PostCloudListResult struct { Data PostCloudListResultData `json:"data"` } +// PostCloudListResultData represents a collection of cloud endpoint data items in a response. type PostCloudListResultData struct { Items []PostCloudListResultDataItem `json:"items"` } +// PostCloudListResultDataItem represents a single cloud endpoint in the response data. type PostCloudListResultDataItem struct { EndpointID string `json:"endpointId,omitempty"` Name string `json:"name,omitempty"` @@ -213,27 +247,32 @@ type PostCloudListResultDataItem struct { EndpointType string `json:"endpointType,omitempty"` } +// GetApplianceBody represents the request body structure for querying appliances based on filters. type GetApplianceBody struct { Filter GetApplianceBodyFilter `json:"filter"` } +// GetApplianceBodyFilter defines the structure for filtering appliance queries. type GetApplianceBodyFilter struct { ApplianceType string `json:"applianceType"` EndpointID string `json:"endpointId"` ServiceMeshID string `json:"serviceMeshId,omitempty"` } +// GetApplianceResult represents the result of querying appliances. type GetApplianceResult struct { Items []GetApplianceResultItem `json:"items"` } +// GetApplianceResultItem represents an appliance query result. type GetApplianceResultItem struct { ApplianceID string `json:"applianceId"` ServiceMeshID string `json:"serviceMeshId"` NetworkExtensionCount int `json:"networkExtensionCount"` } -// GetJobResult ... +// GetJobResult sends a request to retrieve the result of a job identified by the provided jobID, returning a JobResult +// object. Returns an error if the request fails or the response cannot be parsed. func GetJobResult(c *Client, jobID string) (JobResult, error) { resp := JobResult{} @@ -261,7 +300,8 @@ func GetJobResult(c *Client, jobID string) (JobResult, error) { return resp, nil } -// GetTaskResult ... +// GetTaskResult sends a request to retrieve the result of a task identified by the provided taskID, returning a +// TaskResult object. Returns an error if the request fails or the response cannot be parsed. func GetTaskResult(c *Client, taskID string) (TaskResult, error) { resp := TaskResult{} @@ -289,7 +329,8 @@ func GetTaskResult(c *Client, taskID string) (TaskResult, error) { return resp, nil } -// GetLocalConatainer ... +// GetLocalContainer sends a request to retrieve the local resource container list and returns the first item as a +// PostResourceContainerListResultDataItem. Returns an error if the request fails or the response cannot be parsed. func GetLocalContainer(c *Client) (PostResourceContainerListResultDataItem, error) { body := PostResourceContainerListBody{ @@ -333,7 +374,8 @@ func GetLocalContainer(c *Client) (PostResourceContainerListResultDataItem, erro return resp.Data.Items[0], nil } -// GetLocalConatainer ... +// GetRemoteContainer sends a request to retrieve the remote resource container list and returns the first item as a +// PostResourceContainerListResultDataItem. Returns an error if the request fails or the response cannot be parsed. func GetRemoteContainer(c *Client) (PostResourceContainerListResultDataItem, error) { body := PostResourceContainerListBody{ @@ -377,7 +419,8 @@ func GetRemoteContainer(c *Client) (PostResourceContainerListResultDataItem, err return resp.Data.Items[0], nil } -// GetNetworkBacking ... +// GetNetworkBacking sends a request to retrieve a network's backing information by matching the given endpointID, +// network, and networkType. Returns a Dvpg object or an error if it cannot find the network info. func GetNetworkBacking(c *Client, endpointID string, network string, networkType string) (Dvpg, error) { body := PostNetworkBackingBody{ @@ -430,7 +473,8 @@ func GetNetworkBacking(c *Client, endpointID string, network string, networkType return Dvpg{}, errors.New("cannot find network info") } -// GetVcInventory ... +// GetVcInventory sends a request to retrieve the inventory of vCenter resources and returns the first item as a +// GetVcInventoryResultDataItem. Returns an error if the request fails or the response cannot be parsed. func GetVcInventory(c *Client) (GetVcInventoryResultDataItem, error) { var jsonBody = []byte("{}") @@ -461,7 +505,8 @@ func GetVcInventory(c *Client) (GetVcInventoryResultDataItem, error) { return resp.Data.Items[0], nil } -// GetVcDatastore ... +// GetVcDatastore sends a request to query the vCenter datastore, matching the given datastoreName, vcuuid, and cluster. +// Returns the matching GetVcDatastoreResultDataItem or an error if the datastore cannot be found. func GetVcDatastore(c *Client, datastoreName string, vcuuid string, cluster string) (GetVcDatastoreResultDataItem, error) { body := GetVcDatastoreBody{ @@ -510,7 +555,8 @@ func GetVcDatastore(c *Client, datastoreName string, vcuuid string, cluster stri return GetVcDatastoreResultDataItem{}, errors.New("cannot find datastore") } -// GetVcDvs ... +// GetVcDvs sends a request to query a distributed switch matching the given dvsName, vcuuid, and cluster. Returns the +// matching GetVcDvsResultDataItem or an error if the DVS cannot be found. func GetVcDvs(c *Client, dvsName string, vcuuid string, cluster string) (GetVcDvsResultDataItem, error) { body := GetVcDvsBody{ @@ -559,7 +605,8 @@ func GetVcDvs(c *Client, dvsName string, vcuuid string, cluster string) (GetVcDv return GetVcDvsResultDataItem{}, errors.New("cannot find datastore") } -// GetRemoteCloudList ... +// GetRemoteCloudList sends a request to retrieve a list of remote clouds and returns the resulting PostCloudListResult +// object. Returns an error if the request fails or the response cannot be parsed. func GetRemoteCloudList(c *Client) (PostCloudListResult, error) { body := PostCloudListBody{ @@ -600,7 +647,8 @@ func GetRemoteCloudList(c *Client) (PostCloudListResult, error) { return resp, nil } -// GetRemoteCloudList ... +// GetLocalCloudList sends a request to retrieve a list of local clouds and returns the resulting PostCloudListResult +// object. Returns an error if the request fails or the response cannot be parsed. func GetLocalCloudList(c *Client) (PostCloudListResult, error) { body := PostCloudListBody{ @@ -641,7 +689,9 @@ func GetLocalCloudList(c *Client) (PostCloudListResult, error) { return resp, nil } -// GetRemoteCloudList ... +// GetAppliance sends a request to query appliances based on the given endpointID and serviceMeshID. It returns a +// matching GetApplianceResultItem (with a network extension count less than 9) or the first item in the response. +// Returns an error if the request fails or no matching item is found. func GetAppliance(c *Client, endpointID string, serviceMeshID string) (GetApplianceResultItem, error) { body := GetApplianceBody{ @@ -689,7 +739,8 @@ func GetAppliance(c *Client, endpointID string, serviceMeshID string) (GetApplia return resp.Items[0], nil } -// GetRemoteCloudList ... +// GetAppliances sends a request to retrieve all appliances matching the given endpointID and serviceMeshID. Returns a +// slice of GetApplianceResultItem objects or an error if the request fails or the response cannot be parsed. func GetAppliances(c *Client, endpointID string, serviceMeshID string) ([]GetApplianceResultItem, error) { body := GetApplianceBody{ diff --git a/hcx/vcenter.go b/hcx/vcenter.go index d77d564..d0765a9 100644 --- a/hcx/vcenter.go +++ b/hcx/vcenter.go @@ -11,18 +11,22 @@ import ( "net/http" ) +// InsertvCenterBody represents the request body for adding a new vCenter instance configuration. type InsertvCenterBody struct { Data InsertvCenterData `json:"data"` } +// InsertvCenterData represents a collection of vCenter data items required for configuration or operations. type InsertvCenterData struct { Items []InsertvCenterDataItem `json:"items"` } +// InsertvCenterDataItem represents a single item containing configuration details for a vCenter instance. type InsertvCenterDataItem struct { Config InsertvCenterDataItemConfig `json:"config"` } +// InsertvCenterDataItemConfig represents the configuration details for connecting to a vCenter instance. type InsertvCenterDataItemConfig struct { URL string `json:"url"` Username string `json:"userName"` @@ -31,15 +35,18 @@ type InsertvCenterDataItemConfig struct { UUID string `json:"UUID,omitempty"` } +// InsertvCenterResult represents the result returned after inserting a vCenter configuration. type InsertvCenterResult struct { InsertvCenterData InsertvCenterData `json:"data"` } +// DeletevCenterResult represents the result returned after a vCenter instance is deleted, containing related data. type DeletevCenterResult struct { InsertvCenterData InsertvCenterData `json:"data"` } -// InsertvCenter ... +// InsertvCenter sends a request to add a new vCenter instance configuration using the provided body and returns the +// resulting InsertvCenterResult object. Returns an error if the request fails or the response cannot be parsed. func InsertvCenter(c *Client, body InsertvCenterBody) (InsertvCenterResult, error) { resp := InsertvCenterResult{} @@ -74,7 +81,9 @@ func InsertvCenter(c *Client, body InsertvCenterBody) (InsertvCenterResult, erro return resp, nil } -// DeletevCenter ... +// DeletevCenter sends a request to remove a vCenter instance configuration identified by the provided vCenterUUID and +// returns the resulting DeletevCenterResult object. Returns an error if the request fails or the response cannot be +// parsed. func DeletevCenter(c *Client, vCenterUUID string) (DeletevCenterResult, error) { resp := DeletevCenterResult{} diff --git a/hcx/vmc.go b/hcx/vmc.go index cc6cb3d..303c3c0 100644 --- a/hcx/vmc.go +++ b/hcx/vmc.go @@ -16,6 +16,7 @@ import ( "github.com/vmware/terraform-provider-hcx/hcx/constants" ) +// SDDC defines the properties of a Software-Defined Data Center. type SDDC struct { ID string `json:"id"` Name string `json:"name"` @@ -30,10 +31,12 @@ type SDDC struct { State string `json:"state"` } +// GetSddcsResults represents the structure containing a list of Software-Defined Data Centers. type GetSddcsResults struct { SDDCs []SDDC `json:"sddcs"` } +// VmcAccessToken represents a structure for storing VMware Cloud API authentication tokens and token metadata. type VmcAccessToken struct { AccessToken string `json:"access_token"` IDToken string `json:"id_token"` @@ -42,18 +45,23 @@ type VmcAccessToken struct { RefreshToken string `json:"refreshToken"` } +// CloudAuthorizationBody represents the JSON payload containing the authorization token for cloud authentication. type CloudAuthorizationBody struct { Token string `json:"token"` } +// ActivateHcxOnSDDCResults represents the result of activating HCX on a Software-Defined Data Center. type ActivateHcxOnSDDCResults struct { JobID string `json:"jobId"` } +// DeactivateHcxOnSDDCResults represents the result of deactivating HCX on a Software-Defined Data Center. type DeactivateHcxOnSDDCResults struct { JobID string `json:"jobId"` } +// VmcAuthenticate sends a request to authenticate with the VMware Cloud (VMC) API using the provided token. It returns +// an access token as a string or an error if the request fails or the response cannot be parsed. func VmcAuthenticate(token string) (string, error) { c := Client{ @@ -79,7 +87,7 @@ func VmcAuthenticate(token string) (string, error) { return "", err } - // parse response header + // Parse response header. log.Printf("**************************") log.Printf("[Access token] = %+v", resp.AccessToken) @@ -89,6 +97,9 @@ func VmcAuthenticate(token string) (string, error) { } +// CloudAuthenticate sends a request to authenticate to the HCX cloud service using the provided token. On successful +// authentication, it sets the HcxToken field of the provided Client. Returns an error if the request fails, the +// response is invalid, or the token cannot be retrieved. func CloudAuthenticate(client *Client, token string) error { c := Client{ @@ -122,18 +133,16 @@ func CloudAuthenticate(client *Client, token string) error { return errors.New("cannot authorize hcx cloud") } - // parse response header + // Parse response header. client.HcxToken = auth - // parse response header - - log.Printf("**************************") - log.Printf("[Hcx token] = %+v", client.HcxToken) - log.Printf("**************************") return nil } +// GetSddcByName sends a request to retrieve a list of SDDCs (Software-Defined Data Centers) and searches for an SDDC +// with the specified sddcName. It returns the matching SDDC object or an error if the request fails, the response +// cannot be parsed, or the SDDC is not found. func GetSddcByName(client *Client, sddcName string) (SDDC, error) { c := Client{ @@ -153,6 +162,7 @@ func GetSddcByName(client *Client, sddcName string) (SDDC, error) { } resp := GetSddcsResults{} + // Parse response body. err = json.Unmarshal(r, &resp) if err != nil { @@ -166,11 +176,14 @@ func GetSddcByName(client *Client, sddcName string) (SDDC, error) { } } - // parse response header + // Parse response header. return SDDC{}, errors.New("cant find the sddc") } +// GetSddcByID sends a request to retrieve a list of SDDCs (Software-Defined Data Centers) and searches for an SDDC with +// the specified sddcID. It returns the matching SDDC object or an error if the request fails, the response cannot be +// parsed, or the SDDC is not found. func GetSddcByID(client *Client, sddcID string) (SDDC, error) { c := Client{ @@ -190,6 +203,7 @@ func GetSddcByID(client *Client, sddcID string) (SDDC, error) { } resp := GetSddcsResults{} + // Parse response body. err = json.Unmarshal(r, &resp) if err != nil { @@ -203,11 +217,14 @@ func GetSddcByID(client *Client, sddcID string) (SDDC, error) { } } - // parse response header + // Parse response header. return SDDC{}, errors.New("cant find the sddc") } +// ActivateHcxOnSDDC sends a request to activate HCX on the specified SDDC (Software-Defined Data Center) identified by +// the provided sddcID. It returns the resulting ActivateHcxOnSDDCResults object or an error if the request fails or the +// response cannot be parsed. func ActivateHcxOnSDDC(client *Client, sddcID string) (ActivateHcxOnSDDCResults, error) { resp := ActivateHcxOnSDDCResults{} @@ -235,11 +252,14 @@ func ActivateHcxOnSDDC(client *Client, sddcID string) (ActivateHcxOnSDDCResults, return resp, err } - // parse response header + // Parse response header. return resp, nil } +// DeactivateHcxOnSDDC sends a POST request to deactivate HCX on the specified SDDC (Software-Defined Data Center) +// identified by the provided sddcID. It returns the resulting DeactivateHcxOnSDDCResults object or an error if the +// request fails or the response cannot be parsed. func DeactivateHcxOnSDDC(client *Client, sddcID string) (DeactivateHcxOnSDDCResults, error) { resp := DeactivateHcxOnSDDCResults{} @@ -267,7 +287,7 @@ func DeactivateHcxOnSDDC(client *Client, sddcID string) (DeactivateHcxOnSDDCResu return resp, err } - // parse response header + // Parse response header. return resp, nil } diff --git a/main.go b/main.go index 3e8fcac..3f5d4a2 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "github.com/vmware/terraform-provider-hcx/hcx" ) +// main initializes and starts the plugin service for the provider with optional debugging support. func main() { var debugMode bool flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")