package ionrollerapi /** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.0.0 * apibuilder 0.15.11 app.apibuilder.io/gilt/ionroller-api/1.0.0/go_1_5_client */ import ( "bytes" "encoding/json" "errors" "fmt" "html" "io" "net/http" "net/url" "strconv" "strings" ) const BaseUrl = "http://ionroller.gilt.com" const UserAgent = "apibuilder 0.15.11 app.apibuilder.io/gilt/ionroller-api/1.0.0/go_1_5_client" const Version = "1.0.0" const VersionMajor = 1 type Client struct { HttpClient *http.Client Username string Password string BaseUrl string } type ClientRequestBody struct { contentType string bytes io.Reader } /** * Elastic Beanstalk configuration including deployment bucket, stack name and * option settings */ type EbConfig struct { DeploymentBucket string `json:"deployment_bucket"` Stack string `json:"stack,omitempty"` Settings []OptionSetting `json:"settings"` Resources map[string]interface{} `json:"resources,omitempty"` Packages map[string]interface{} `json:"packages,omitempty"` Sources map[string]interface{} `json:"sources,omitempty"` Files map[string]interface{} `json:"files,omitempty"` Users map[string]interface{} `json:"users,omitempty"` Groups map[string]interface{} `json:"groups,omitempty"` Commands map[string]interface{} `json:"commands,omitempty"` ContainerCommands map[string]interface{} `json:"container_commands,omitempty"` Services map[string]interface{} `json:"services,omitempty"` } func EbConfigFromMap(data interface{}) EbConfig { b, err := json.Marshal(data) if err == nil { return EbConfigFromJson(bytes.NewReader(b)) } else { panic(err) } } func EbConfigFromJson(bytes io.Reader) EbConfig { var ebConfig EbConfig json.NewDecoder(bytes).Decode(&ebConfig) return ebConfig } /** * Settings for external ELB */ type ElbSettings struct { Name string `json:"name"` SecurityGroup string `json:"security_group"` RolloutDelayMinutes int32 `json:"rollout_delay_minutes"` } func ElbSettingsFromMap(data interface{}) ElbSettings { b, err := json.Marshal(data) if err == nil { return ElbSettingsFromJson(bytes.NewReader(b)) } else { panic(err) } } func ElbSettingsFromJson(bytes io.Reader) ElbSettings { var elbSettings ElbSettings json.NewDecoder(bytes).Decode(&elbSettings) return elbSettings } /** * Elastic Beanstalk Environment running in AWS */ type Environment struct { Release Release `json:"release"` Health string `json:"health"` } func EnvironmentFromMap(data interface{}) Environment { b, err := json.Marshal(data) if err == nil { return EnvironmentFromJson(bytes.NewReader(b)) } else { panic(err) } } func EnvironmentFromJson(bytes io.Reader) Environment { var environment Environment json.NewDecoder(bytes).Decode(&environment) return environment } /** * Elastic Beanstalk configuration option setting */ type OptionSetting struct { Namespace string OptionName string Value string } func OptionSettingFromMap(data interface{}) OptionSetting { b, err := json.Marshal(data) if err == nil { return OptionSettingFromJson(bytes.NewReader(b)) } else { panic(err) } } func OptionSettingFromJson(bytes io.Reader) OptionSetting { var optionSetting OptionSetting json.NewDecoder(bytes).Decode(&optionSetting) return optionSetting } /** * Mapping from port in Docker container to external host port */ type PortMapping struct { Internal int32 `json:"internal"` External int32 `json:"external"` } func PortMappingFromMap(data interface{}) PortMapping { b, err := json.Marshal(data) if err == nil { return PortMappingFromJson(bytes.NewReader(b)) } else { panic(err) } } func PortMappingFromJson(bytes io.Reader) PortMapping { var portMapping PortMapping json.NewDecoder(bytes).Decode(&portMapping) return portMapping } /** * A release of a particular tag of a Docker image */ type Release struct { Image string `json:"image"` Tag string `json:"tag"` Config string `json:"config"` RolloutStatus RolloutStatus `json:"rollout_status,omitempty"` } func ReleaseFromMap(data interface{}) Release { b, err := json.Marshal(data) if err == nil { return ReleaseFromJson(bytes.NewReader(b)) } else { panic(err) } } func ReleaseFromJson(bytes io.Reader) Release { var release Release json.NewDecoder(bytes).Decode(&release) return release } /** * Current rollout status for release */ type RolloutStatus struct { NumInstances int32 `json:"num_instances,omitempty"` CompletedAt string `json:"completed_at,omitempty"` } func RolloutStatusFromMap(data interface{}) RolloutStatus { b, err := json.Marshal(data) if err == nil { return RolloutStatusFromJson(bytes.NewReader(b)) } else { panic(err) } } func RolloutStatusFromJson(bytes io.Reader) RolloutStatus { var rolloutStatus RolloutStatus json.NewDecoder(bytes).Decode(&rolloutStatus) return rolloutStatus } type Service struct { Name string `json:"name"` State ServiceState `json:"state"` } func ServiceFromMap(data interface{}) Service { b, err := json.Marshal(data) if err == nil { return ServiceFromJson(bytes.NewReader(b)) } else { panic(err) } } func ServiceFromJson(bytes io.Reader) Service { var service Service json.NewDecoder(bytes).Decode(&service) return service } /** * Configuration used by a service */ type ServiceConfig struct { Url string `json:"url"` HostedZoneId string `json:"hosted_zone_id"` AwsAccountId string `json:"aws_account_id"` ExternalElb ElbSettings `json:"external_elb,omitempty"` ServiceRole string `json:"service_role"` Image string `json:"image"` PortMappings []PortMapping `json:"port_mappings"` VolumeMappings []VolumeMapping `json:"volume_mappings,omitempty"` RunArgs []string `json:"run_args"` Eb EbConfig `json:"eb"` RemoveUnusedAfterMinutes int64 `json:"remove_unused_after_minutes,omitempty"` Timestamp string `json:"timestamp,omitempty"` } func ServiceConfigFromMap(data interface{}) ServiceConfig { b, err := json.Marshal(data) if err == nil { return ServiceConfigFromJson(bytes.NewReader(b)) } else { panic(err) } } func ServiceConfigFromJson(bytes io.Reader) ServiceConfig { var serviceConfig ServiceConfig json.NewDecoder(bytes).Decode(&serviceConfig) return serviceConfig } /** * Current state of service environments */ type ServiceCurrentState struct { Environments []Environment `json:"environments"` } func ServiceCurrentStateFromMap(data interface{}) ServiceCurrentState { b, err := json.Marshal(data) if err == nil { return ServiceCurrentStateFromJson(bytes.NewReader(b)) } else { panic(err) } } func ServiceCurrentStateFromJson(bytes io.Reader) ServiceCurrentState { var serviceCurrentState ServiceCurrentState json.NewDecoder(bytes).Decode(&serviceCurrentState) return serviceCurrentState } /** * Desired future state of service */ type ServiceDesiredState struct { Current Release `json:"current,omitempty"` Next Release `json:"next,omitempty"` Future Release `json:"future,omitempty"` } func ServiceDesiredStateFromMap(data interface{}) ServiceDesiredState { b, err := json.Marshal(data) if err == nil { return ServiceDesiredStateFromJson(bytes.NewReader(b)) } else { panic(err) } } func ServiceDesiredStateFromJson(bytes io.Reader) ServiceDesiredState { var serviceDesiredState ServiceDesiredState json.NewDecoder(bytes).Decode(&serviceDesiredState) return serviceDesiredState } /** * State of service environments */ type ServiceState struct { Current ServiceCurrentState `json:"current"` Desired ServiceDesiredState `json:"desired,omitempty"` } func ServiceStateFromMap(data interface{}) ServiceState { b, err := json.Marshal(data) if err == nil { return ServiceStateFromJson(bytes.NewReader(b)) } else { panic(err) } } func ServiceStateFromJson(bytes io.Reader) ServiceState { var serviceState ServiceState json.NewDecoder(bytes).Decode(&serviceState) return serviceState } /** * Mapping from path inside Docker container to external volume */ type VolumeMapping struct { Internal string `json:"internal"` External string `json:"external"` } func VolumeMappingFromMap(data interface{}) VolumeMapping { b, err := json.Marshal(data) if err == nil { return VolumeMappingFromJson(bytes.NewReader(b)) } else { panic(err) } } func VolumeMappingFromJson(bytes io.Reader) VolumeMapping { var volumeMapping VolumeMapping json.NewDecoder(bytes).Decode(&volumeMapping) return volumeMapping } type ServicesGetResponse struct { StatusCode int Response *http.Response Error error Services []Service } func ServicesGet(client Client) ServicesGetResponse { requestUrl := fmt.Sprintf("%s/services", client.BaseUrl) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return ServicesGetResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesGetResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesGetResponse{StatusCode: resp.StatusCode, Response: resp, Services: func() []Service { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []Service for _, el := range tmp { all = append(all, ServiceFromMap(el)) } return all }()} default: return ServicesGetResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesGetByServiceNameResponse struct { StatusCode int Response *http.Response Error error Service Service } func ServicesGetByServiceName(client Client, serviceName string) ServicesGetByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s", client.BaseUrl, html.EscapeString(serviceName)) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return ServicesGetByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesGetByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesGetByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Service: ServiceFromJson(resp.Body)} default: return ServicesGetByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesPutConfigByServiceNameResponse struct { StatusCode int Response *http.Response Error error } func ServicesPutConfigByServiceName(client Client, serviceName string, serviceConfig ServiceConfig) ServicesPutConfigByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/config", client.BaseUrl, html.EscapeString(serviceName)) bodyDocument, err := json.Marshal(serviceConfig) if err != nil { return ServicesPutConfigByServiceNameResponse{Error: err} } body := ClientRequestBody{contentType: "application/json", bytes: bytes.NewReader(bodyDocument)} request, err := buildRequest(client, "PUT", requestUrl, body) if err != nil { return ServicesPutConfigByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesPutConfigByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 204: return ServicesPutConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp} default: return ServicesPutConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesGetConfigsByServiceNameParams struct { From string To string } type ServicesGetConfigsByServiceNameResponse struct { StatusCode int Response *http.Response Error error ServiceConfigs []ServiceConfig } func ServicesGetConfigsByServiceName(client Client, serviceName string, params ServicesGetConfigsByServiceNameParams) ServicesGetConfigsByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/configs", client.BaseUrl, html.EscapeString(serviceName)) urlValues := url.Values{} if "" != params.From { urlValues.Add("from", params.From) } if "" != params.To { urlValues.Add("to", params.To) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return ServicesGetConfigsByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesGetConfigsByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesGetConfigsByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, ServiceConfigs: func() []ServiceConfig { var tmp []interface{} json.NewDecoder(resp.Body).Decode(&tmp) var all []ServiceConfig for _, el := range tmp { all = append(all, ServiceConfigFromMap(el)) } return all }()} default: return ServicesGetConfigsByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesGetConfigByServiceNameResponse struct { StatusCode int Response *http.Response Error error ServiceConfig ServiceConfig } func ServicesGetConfigByServiceName(client Client, serviceName string) ServicesGetConfigByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/config", client.BaseUrl, html.EscapeString(serviceName)) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return ServicesGetConfigByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesGetConfigByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesGetConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, ServiceConfig: ServiceConfigFromJson(resp.Body)} default: return ServicesGetConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesGetConfigsByServiceNameAndTimestampResponse struct { StatusCode int Response *http.Response Error error ServiceConfig ServiceConfig } func ServicesGetConfigsByServiceNameAndTimestamp(client Client, serviceName string, timestamp string) ServicesGetConfigsByServiceNameAndTimestampResponse { requestUrl := fmt.Sprintf("%s/services/%s/configs/%s", client.BaseUrl, html.EscapeString(serviceName), html.EscapeString(timestamp)) request, err := buildRequest(client, "GET", requestUrl, ClientRequestBody{}) if err != nil { return ServicesGetConfigsByServiceNameAndTimestampResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesGetConfigsByServiceNameAndTimestampResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesGetConfigsByServiceNameAndTimestampResponse{StatusCode: resp.StatusCode, Response: resp, ServiceConfig: ServiceConfigFromJson(resp.Body)} default: return ServicesGetConfigsByServiceNameAndTimestampResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesDeleteConfigByServiceNameResponse struct { StatusCode int Response *http.Response Error error } func ServicesDeleteConfigByServiceName(client Client, serviceName string) ServicesDeleteConfigByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/config", client.BaseUrl, html.EscapeString(serviceName)) request, err := buildRequest(client, "DELETE", requestUrl, ClientRequestBody{}) if err != nil { return ServicesDeleteConfigByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesDeleteConfigByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 204: return ServicesDeleteConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp} default: return ServicesDeleteConfigByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesPostReleaseByServiceNameParams struct { Version string Config string } type ServicesPostReleaseByServiceNameResponse struct { StatusCode int Response *http.Response Error error Value int64 } func ServicesPostReleaseByServiceName(client Client, serviceName string, params ServicesPostReleaseByServiceNameParams) ServicesPostReleaseByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/release", client.BaseUrl, html.EscapeString(serviceName)) urlValues := url.Values{} if "" != params.Version { urlValues.Add("version", params.Version) } if "" != params.Config { urlValues.Add("config", params.Config) } body := ClientRequestBody{contentType: "application/x-www-form-urlencoded", bytes: strings.NewReader(urlValues.Encode())} request, err := buildRequest(client, "POST", requestUrl, body) if err != nil { return ServicesPostReleaseByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesPostReleaseByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesPostReleaseByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Value: string(resp.Body)} default: return ServicesPostReleaseByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ServicesPostDropByServiceNameParams struct { Version string Config string Force string } type ServicesPostDropByServiceNameResponse struct { StatusCode int Response *http.Response Error error Value int64 } func ServicesPostDropByServiceName(client Client, serviceName string, params ServicesPostDropByServiceNameParams) ServicesPostDropByServiceNameResponse { requestUrl := fmt.Sprintf("%s/services/%s/drop", client.BaseUrl, html.EscapeString(serviceName)) urlValues := url.Values{} if "" != params.Version { urlValues.Add("version", params.Version) } if "" != params.Config { urlValues.Add("config", params.Config) } if "" == params.Force { urlValues.Add("force", "false") } else { urlValues.Add("force", params.Force) } body := ClientRequestBody{contentType: "application/x-www-form-urlencoded", bytes: strings.NewReader(urlValues.Encode())} request, err := buildRequest(client, "POST", requestUrl, body) if err != nil { return ServicesPostDropByServiceNameResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ServicesPostDropByServiceNameResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ServicesPostDropByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Value: string(resp.Body)} default: return ServicesPostDropByServiceNameResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } func buildRequest(client Client, method, urlStr string, body ClientRequestBody) (*http.Request, error) { request, err := http.NewRequest(method, urlStr, body.bytes) if err != nil { return nil, err } request.Header = map[string][]string{ "User-Agent": {UserAgent}, "X-Apidoc-Version": {Version}, "X-Apidoc-Version-Major": {strconv.Itoa(VersionMajor)}, } if body.contentType != "" { request.Header["Content-type"] = []string{body.contentType} } if client.Username != "" { request.SetBasicAuth(client.Username, client.Password) } return request, nil }