This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #46
- Loading branch information
Showing
420 changed files
with
17,261 additions
and
49,579 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright (c) 2017-2021 Ingram Micro Inc. | ||
|
||
package api | ||
|
||
const ContentTypeApplicationJson = "application/json" | ||
|
||
const WebServiceConfigurationFailed = "web service configuration failed. No data in configuration" | ||
const ConfigurationIsIncomplete = "configuration is incomplete" | ||
|
||
const ( | ||
pathAuditEvents = "/audit/events" | ||
pathAuditSystemEvents = "/audit/system_events" | ||
pathBlueprintAttachment = "/blueprint/attachments/%s" | ||
pathBlueprintAttachmentUploaded = "/blueprint/attachments/%s/uploaded" | ||
pathBlueprintCloudAccountImportFloatingIPs = "/brownfield/cloud_accounts/%s/import_floating_ips" | ||
pathBlueprintCloudAccountImportK8sClusters = "/brownfield/cloud_accounts/%s/import_kubernetes_clusters" | ||
pathBlueprintCloudAccountImportPolicies = "/brownfield/cloud_accounts/%s/import_policies" | ||
pathBlueprintCloudAccountImportServers = "/brownfield/cloud_accounts/%s/import_servers" | ||
pathBlueprintCloudAccountImportVolumes = "/brownfield/cloud_accounts/%s/import_volumes" | ||
pathBlueprintCloudAccountImportVpcs = "/brownfield/cloud_accounts/%s/import_vpcs" | ||
pathBlueprintCookbookVersion = "/blueprint/cookbook_versions/%s" | ||
pathBlueprintCookbookVersionProcess = "/blueprint/cookbook_versions/%s/process" | ||
pathBlueprintCookbookVersions = "/blueprint/cookbook_versions" | ||
pathBlueprintScript = "/blueprint/scripts/%s" | ||
pathBlueprintScriptAttachments = "/blueprint/scripts/%s/attachments" | ||
pathBlueprintScripts = "/blueprint/scripts" | ||
pathBlueprintTemplate = "/blueprint/templates/%s" | ||
pathBlueprintTemplateCompile = "/blueprint/templates/%s/compile" | ||
pathBlueprintTemplates = "/blueprint/templates" | ||
pathBlueprintTemplateScript = "/blueprint/templates/%s/scripts/%s" | ||
pathBlueprintTemplateScripts = "/blueprint/templates/%s/scripts" | ||
pathBlueprintTemplateScriptsReorder = "/blueprint/templates/%s/scripts/reorder" | ||
pathBlueprintTemplateScriptsType = "/blueprint/templates/%s/scripts?type=%s" | ||
pathBlueprintTemplateServers = "/blueprint/templates/%s/servers" | ||
pathBrownfieldCloudAccount = "/brownfield/cloud_accounts/%s" | ||
pathBrownfieldCloudAccounts = "/brownfield/cloud_accounts" | ||
pathCloudCloudProviderClusterPlans = "/cloud/cloud_providers/%s/cluster_plans" | ||
pathCloudCloudProviderLoadBalancerPlans = "/cloud/cloud_providers/%s/load_balancer_plans" | ||
pathCloudCloudProviders = "/cloud/cloud_providers" | ||
pathCloudCloudProviderServerPlans = "/cloud/cloud_providers/%s/server_plans" | ||
pathCloudCloudProviderStoragePlans = "/cloud/cloud_providers/%s/storage_plans" | ||
pathCloudGenericImages = "/cloud/generic_images" | ||
pathCloudProviderRealms = "/cloud/cloud_providers/%s/realms" | ||
pathCloudRealm = "/cloud/realms/%s" | ||
pathCloudRealmNodePoolPlans = "/cloud/realms/%s/node_pool_plans" | ||
pathCloudServer = "/cloud/servers/%s" | ||
pathCloudServerArray = "/cloud/server_arrays/%s" | ||
pathCloudServerArrayBoot = "/cloud/server_arrays/%s/boot" | ||
pathCloudServerArrayEmpty = "/cloud/server_arrays/%s/empty" | ||
pathCloudServerArrays = "/cloud/server_arrays" | ||
pathCloudServerArrayServers = "/cloud/server_arrays/%s/servers" | ||
pathCloudServerArrayShutdown = "/cloud/server_arrays/%s/shutdown" | ||
pathCloudServerBoot = "/cloud/servers/%s/boot" | ||
pathCloudServerEvents = "/cloud/servers/%s/events" | ||
pathCloudServerFloatingIps = "/cloud/servers/%s/floating_ips" | ||
pathCloudServerOperationalScriptExecute = "/cloud/servers/%s/operational_scripts/%s/execute" | ||
pathCloudServerOperationalScripts = "/cloud/servers/%s/operational_scripts" | ||
pathCloudServerOverride = "/cloud/servers/%s/override" | ||
pathCloudServerPlan = "/cloud/server_plans/%s" | ||
pathCloudServerReboot = "/cloud/servers/%s/reboot" | ||
pathCloudServers = "/cloud/servers" | ||
pathCloudServerShutdown = "/cloud/servers/%s/shutdown" | ||
pathCloudServerVolumes = "/cloud/servers/%s/volumes" | ||
pathCloudSshProfile = "/cloud/ssh_profiles/%s" | ||
pathCloudSshProfiles = "/cloud/ssh_profiles" | ||
pathCseDeployment = "/cse/deployments/%s" | ||
pathCseDeployments = "/cse/deployments" | ||
pathCseTemplate = "/cse/templates/%s" | ||
pathCseTemplateDeployments = "/cse/templates/%s/deployments" | ||
pathCseTemplates = "/cse/templates" | ||
pathKubernetesCluster = "/kubernetes/clusters/%s" | ||
pathKubernetesClusterDiscard = "/kubernetes/clusters/%s/discard" | ||
pathKubernetesClusterNodePools = "/kubernetes/clusters/%s/node_pools" | ||
pathKubernetesClusterPlan = "/kubernetes/cluster_plans/%s" | ||
pathKubernetesClusterRetry = "/kubernetes/clusters/%s/retry" | ||
pathKubernetesClusters = "/kubernetes/clusters" | ||
pathKubernetesNodePool = "/kubernetes/node_pools/%s" | ||
pathKubernetesNodePoolPlan = "/kubernetes/node_pool_plans/%s" | ||
pathKubernetesNodePoolRetry = "/kubernetes/node_pools/%s/retry" | ||
pathLabelResource = "/labels/%s/resources/%s/%s" | ||
pathLabelResources = "/labels/%s/resources" | ||
pathLabels = "/labels" | ||
pathNetworkDnsDomain = "/network/dns/domains/%s" | ||
pathNetworkDnsDomainRecords = "/network/dns/domains/%s/records" | ||
pathNetworkDnsDomainRetry = "/network/dns/domains/%s/retry" | ||
pathNetworkDnsDomains = "/network/dns/domains" | ||
pathNetworkDnsRecord = "/network/dns/records/%s" | ||
pathNetworkDnsRecordRetry = "/network/dns/records/%s/retry" | ||
pathNetworkFirewallProfile = "/network/firewall_profiles/%s" | ||
pathNetworkFirewallProfiles = "/network/firewall_profiles" | ||
pathNetworkFloatingIp = "/network/floating_ips/%s" | ||
pathNetworkFloatingIpAttachedServer = "/network/floating_ips/%s/attached_server" | ||
pathNetworkFloatingIpDiscard = "/network/floating_ips/%s/discard" | ||
pathNetworkFloatingIps = "/network/floating_ips" | ||
pathNetworkListener = "/network/listeners/%s" | ||
pathNetworkListenerRetry = "/network/listeners/%s/retry" | ||
pathNetworkListenerRule = "/network/listeners/%s/rules/%s" | ||
pathNetworkListenerRules = "/network/listeners/%s/rules" | ||
pathNetworkLoadBalancer = "/network/load_balancers/%s" | ||
pathNetworkLoadBalancerCertificate = "/network/load_balancers/%s/certificates/%s" | ||
pathNetworkLoadBalancerCertificates = "/network/load_balancers/%s/certificates" | ||
pathNetworkLoadBalancerListeners = "/network/load_balancers/%s/listeners" | ||
pathNetworkLoadBalancerPlan = "/network/load_balancer_plans/%s" | ||
pathNetworkLoadBalancerRetry = "/network/load_balancers/%s/retry" | ||
pathNetworkLoadBalancers = "/network/load_balancers" | ||
pathNetworkLoadBalancerTargetGroups = "/network/load_balancers/%s/target_groups" | ||
pathNetworkSubnet = "/network/subnets/%s" | ||
pathNetworkSubnetServerArrays = "/network/subnets/%s/server_arrays" | ||
pathNetworkSubnetServers = "/network/subnets/%s/servers" | ||
pathNetworkTargetGroup = "/network/target_groups/%s" | ||
pathNetworkTargetGroupRetry = "/network/target_groups/%s/retry" | ||
pathNetworkTargetGroupTarget = "/network/target_groups/%s/targets/%s/%s" | ||
pathNetworkTargetGroupTargets = "/network/target_groups/%s/targets" | ||
pathNetworkVpc = "/network/vpcs/%s" | ||
pathNetworkVpcDiscard = "/network/vpcs/%s/discard" | ||
pathNetworkVpcs = "/network/vpcs" | ||
pathNetworkVpcSubnets = "/network/vpcs/%s/subnets" | ||
pathNetworkVpcVpn = "/network/vpcs/%s/vpn" | ||
pathNetworkVpcVpnPlans = "/network/vpcs/%s/vpn_plans" | ||
pathPluginsToscaCat = "/plugins/tosca/cats/%s" | ||
pathPluginsToscaCatDeploymentTask = "/plugins/tosca/cats/%s/deployment_tasks/%s" | ||
pathPluginsToscaCatDeploymentTasks = "/plugins/tosca/cats/%s/deployment_tasks" | ||
pathPluginsToscaCatParseMetadata = "/plugins/tosca/cats/%s/parse_metadata" | ||
pathPluginsToscaCats = "/plugins/tosca/cats" | ||
pathPluginsToscaDeployment = "/plugins/tosca/deployments/%s" | ||
pathPluginsToscaTemporaryArchiveExport = "/plugins/tosca/temporary_archives/%s/export" | ||
pathPluginsToscaTemporaryArchiveImport = "/plugins/tosca/temporary_archives/%s/import" | ||
pathPluginsToscaTemporaryArchives = "/plugins/tosca/temporary_archives" | ||
pathPluginsToscaTemporaryArchivesExport = "/plugins/tosca/temporary_archives/export" | ||
pathPolicyAssignment = "/policy/assignments/%s" | ||
pathPolicyDefinition = "/policy/definitions/%s" | ||
pathPolicyDefinitionAssignments = "/policy/definitions/%s/assignments" | ||
pathPolicyDefinitions = "/policy/definitions" | ||
pathSettingsCloudAccount = "/settings/cloud_accounts/%s" | ||
pathSettingsCloudAccountPolicyAssignments = "/settings/cloud_accounts/%s/policy_assignments" | ||
pathSettingsCloudAccounts = "/settings/cloud_accounts" | ||
pathStoragePlan = "/storage/plans/%s" | ||
pathStorageVolume = "/storage/volumes/%s" | ||
pathStorageVolumeAttachedServer = "/storage/volumes/%s/attached_server" | ||
pathStorageVolumeDiscard = "/storage/volumes/%s/discard" | ||
pathStorageVolumes = "/storage/volumes" | ||
pathWizardAppDeploy = "/wizard/apps/%s/deploy" | ||
pathWizardApps = "/wizard/apps" | ||
pathWizardCloudProviders = "/wizard/cloud_providers?app_id=%s&location_id=%s" | ||
pathWizardLocations = "/wizard/locations" | ||
pathWizardServerPlans = "/wizard/server_plans?app_id=%s&location_id=%s&cloud_provider_id=%s" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright (c) 2017-2021 Ingram Micro Inc. | ||
|
||
package api | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
"github.com/ingrammicro/cio/configuration" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
// IMCOClient web service manager | ||
type IMCOClient struct { | ||
config *configuration.Config | ||
client *http.Client | ||
} | ||
|
||
// NewIMCOClient creates new http Concerto client based on config | ||
func NewIMCOClient(config *configuration.Config) (ic *IMCOClient, err error) { | ||
if config == nil { | ||
return nil, fmt.Errorf(WebServiceConfigurationFailed) | ||
} | ||
|
||
if !config.IsConfigReady() { | ||
return nil, fmt.Errorf(ConfigurationIsIncomplete) | ||
} | ||
|
||
// creates HTTP Concerto service with config | ||
ic = &IMCOClient{ | ||
config: config, | ||
} | ||
|
||
// Loads CA Certificate | ||
caCert, err := ioutil.ReadFile(ic.config.Certificate.Ca) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot read IMCO CA cert: %v", err) | ||
} | ||
caCertPool := x509.NewCertPool() | ||
caCertPool.AppendCertsFromPEM(caCert) | ||
|
||
// Loads Clients Certificates and creates and 509KeyPair | ||
cert, err := tls.LoadX509KeyPair(ic.config.Certificate.Cert, ic.config.Certificate.Key) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"cannot read IMCO API key (from '%s' and '%s'): %v", | ||
ic.config.Certificate.Cert, | ||
ic.config.Certificate.Key, | ||
err, | ||
) | ||
} | ||
|
||
// Creates a client with specific transport configurations | ||
ic.client = &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
RootCAs: caCertPool, | ||
Certificates: []tls.Certificate{cert}, | ||
}, | ||
}, | ||
} | ||
return ic, nil | ||
} | ||
|
||
// NewIMCOClientWithBrownfieldToken creates new http Concerto client based on config | ||
func NewIMCOClientWithBrownfieldToken(config *configuration.Config) (ic *IMCOClient, err error) { | ||
if config == nil { | ||
return nil, fmt.Errorf(WebServiceConfigurationFailed) | ||
} | ||
|
||
if !config.IsConfigReadyBrownfield() { | ||
return nil, fmt.Errorf(ConfigurationIsIncomplete) | ||
} | ||
|
||
// creates HTTP Concerto service with config | ||
ic = &IMCOClient{ | ||
config: config, | ||
} | ||
// Creates a client with no certificates and insecure option | ||
ic.client = &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
}, | ||
} | ||
return ic, nil | ||
} | ||
|
||
// NewIMCOClientWithCommandPolling creates new http Concerto client based on config | ||
func NewIMCOClientWithCommandPolling(config *configuration.Config) (ic *IMCOClient, err error) { | ||
if config == nil { | ||
return nil, fmt.Errorf(WebServiceConfigurationFailed) | ||
} | ||
|
||
if !config.IsConfigReadyCommandPolling() { | ||
return nil, fmt.Errorf(ConfigurationIsIncomplete) | ||
} | ||
|
||
// creates HTTP Concerto service with config | ||
ic = &IMCOClient{ | ||
config: config, | ||
} | ||
// Creates a client with no certificates and insecure option | ||
ic.client = &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
}, | ||
} | ||
return ic, nil | ||
} |
Oops, something went wrong.