Skip to content

Commit

Permalink
Update to use latest swagger (#30)
Browse files Browse the repository at this point in the history
* Update to use latest swagger

This includes the necessary fix for scaling services to zero containers
but also adds recent updates to our API.

* Add embedded database credentials into database response
  • Loading branch information
robertfairhead authored Jan 11, 2021
1 parent 1ce32e2 commit d5eb5e0
Show file tree
Hide file tree
Showing 289 changed files with 10,803 additions and 4,268 deletions.
5 changes: 2 additions & 3 deletions aptible/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ func (c *Client) GetApp(appID int64) (App, error) {
}

func (c *Client) DeployApp(config map[string]interface{}, appID int64) error {
appRequest := models.AppRequest21{}
requestType := "configure"
if _, ok := config["APTIBLE_DOCKER_IMAGE"]; ok {
requestType = "deploy"
}
appRequest = models.AppRequest21{Type: &requestType, Env: config}
appRequest := models.AppRequest22{Type: &requestType, Env: config}
appParams := operations.NewPostAppsAppIDOperationsParams().WithAppID(appID).WithAppRequest(&appRequest)
response, err := c.Client.Operations.PostAppsAppIDOperations(appParams, c.Token)
if err != nil {
Expand All @@ -131,7 +130,7 @@ func (c *Client) DeployApp(config map[string]interface{}, appID int64) error {

func (c *Client) DeleteApp(appID int64) (bool, error) {
requestType := "deprovision"
appRequest := models.AppRequest21{Type: &requestType}
appRequest := models.AppRequest22{Type: &requestType}
appParams := operations.NewPostAppsAppIDOperationsParams().WithAppID(appID).WithAppRequest(&appRequest)
op, err := c.Client.Operations.PostAppsAppIDOperations(appParams, c.Token)
if err != nil {
Expand Down
50 changes: 30 additions & 20 deletions aptible/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
)

type Database struct {
ID int64
ConnectionURL string
ContainerSize int64
DiskSize int64
Deleted bool
Handle string
Type string
EnvironmentID int64
InitializeFromID int64
Service Service
DatabaseImage DatabaseImage
ID int64
DefaultConnection string
ConnectionURLs []string
ContainerSize int64
DiskSize int64
Deleted bool
Handle string
Type string
EnvironmentID int64
InitializeFromID int64
Service Service
DatabaseImage DatabaseImage
}

type DBUpdates struct {
Expand All @@ -37,7 +38,7 @@ type DBCreateAttrs struct {

func (c *Client) CreateDatabase(accountID int64, attrs DBCreateAttrs) (Database, error) {
// creates API object
request := models.AppRequest12{
request := models.AppRequest13{
Handle: attrs.Handle,
Type: attrs.Type,
}
Expand All @@ -54,7 +55,7 @@ func (c *Client) CreateDatabase(accountID int64, attrs DBCreateAttrs) (Database,

// provisions database
requestType := "provision"
provisionRequest := models.AppRequest23{
provisionRequest := models.AppRequest24{
Type: &requestType,
ContainerSize: attrs.ContainerSize,
DiskSize: attrs.DiskSize,
Expand Down Expand Up @@ -98,11 +99,20 @@ func (c *Client) GetDatabase(databaseID int64) (Database, error) {
return Database{}, err
}

connectionUrl := resp.Payload.ConnectionURL
if connectionUrl == nil {
return Database{}, fmt.Errorf("connectionUrl is a nil pointer")
defaultConnection := resp.Payload.ConnectionURL
if defaultConnection == nil {
return Database{}, fmt.Errorf("defaultConnection is a nil pointer")
}
database.DefaultConnection = *defaultConnection

connectionUrls := resp.Payload.Embedded.DatabaseCredentials
for _, u := range connectionUrls {
if u == nil {
continue
}

database.ConnectionURLs = append(database.ConnectionURLs, u.ConnectionURL)
}
database.ConnectionURL = *connectionUrl

databaseType := resp.Payload.Type
if databaseType == nil {
Expand Down Expand Up @@ -170,7 +180,7 @@ func (c *Client) GetDatabase(databaseID int64) (Database, error) {

func (c *Client) UpdateDatabase(databaseID int64, updates DBUpdates) error {
requestType := "restart"
request := models.AppRequest23{
request := models.AppRequest24{
Type: &requestType,
}

Expand Down Expand Up @@ -201,7 +211,7 @@ func (c *Client) UpdateDatabase(databaseID int64, updates DBUpdates) error {

func (c *Client) DeleteDatabase(databaseID int64) error {
requestType := "deprovision"
request := models.AppRequest23{
request := models.AppRequest24{
Type: &requestType,
}
deprovisionParams := operations.NewPostDatabasesDatabaseIDOperationsParams().WithDatabaseID(databaseID).WithAppRequest(&request)
Expand All @@ -214,7 +224,7 @@ func (c *Client) DeleteDatabase(databaseID int64) error {
return err
}

func (c *Client) GetDatabaseOperations(databaseID int64, page int64) (*models.InlineResponse20029, error) {
func (c *Client) GetDatabaseOperations(databaseID int64, page int64) (*models.InlineResponse20031, error) {
params := operations.NewGetDatabasesDatabaseIDOperationsParams().WithDatabaseID(databaseID).WithPage(&page)
resp, err := c.Client.Operations.GetDatabasesDatabaseIDOperations(params, c.Token)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions aptible/database_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ReplicaIdentifiers struct {
func (c *Client) CreateReplica(attrs ReplicateAttrs) (Database, error) {
operationType := "replicate"

req := models.AppRequest23{
req := models.AppRequest24{
Type: &operationType,
Handle: attrs.ReplicaHandle,
ContainerSize: attrs.ContainerSize,
Expand Down Expand Up @@ -84,7 +84,7 @@ func (c *Client) DeleteReplica(replicaID int64) error {
return c.DeleteDatabase(replicaID)
}

func (c *Client) GetReplicaFromHandle(databaseID int64, handle string) (*models.InlineResponse20014EmbeddedDatabases, error) {
func (c *Client) GetReplicaFromHandle(databaseID int64, handle string) (*models.InlineResponse20016EmbeddedDatabases, error) {
params := operations.NewGetDatabasesDatabaseIDDependentsParams().WithDatabaseID(databaseID)
resp, err := c.Client.Operations.GetDatabasesDatabaseIDDependents(params, c.Token)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions aptible/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type EndpointCreateAttrs struct {
// CreateEndpoint() creates Vhost API object + provision operation on the app.
func (c *Client) CreateEndpoint(service Service, attrs EndpointCreateAttrs) (Endpoint, error) {
// Create Vhost API object
request := models.AppRequest33{
request := models.AppRequest34{
Acme: attrs.Acme,
Type: attrs.Type,
Default: attrs.Default,
Expand All @@ -70,7 +70,7 @@ func (c *Client) CreateEndpoint(service Service, attrs EndpointCreateAttrs) (End
payload := resp.Payload
endpointID := *payload.ID
requestType := "provision"
operationRequest := models.AppRequest26{Type: &requestType}
operationRequest := models.AppRequest27{Type: &requestType}
operationParams := operations.NewPostVhostsVhostIDOperationsParams().WithVhostID(endpointID).WithAppRequest(&operationRequest)
operationResponse, err := c.Client.Operations.PostVhostsVhostIDOperations(operationParams, c.Token)
if err != nil {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (c *Client) GetEndpoint(endpointID int64) (Endpoint, error) {

// UpdateEndpoint() takes in an endpointID and updates needed, and updates the endpoint.
func (c *Client) UpdateEndpoint(endpointID int64, up EndpointUpdates) error {
appRequest := models.AppRequest34{
appRequest := models.AppRequest35{
ContainerPort: up.ContainerPort,
IPWhitelist: up.IPWhitelist,
Platform: up.Platform,
Expand All @@ -204,7 +204,7 @@ func (c *Client) UpdateEndpoint(endpointID int64, up EndpointUpdates) error {
// DeleteEndpoint() deletes the endpoint.
func (c *Client) DeleteEndpoint(endpointID int64) error {
requestType := "deprovision"
operationRequest := models.AppRequest26{Type: &requestType}
operationRequest := models.AppRequest27{Type: &requestType}
operationParams := operations.NewPostVhostsVhostIDOperationsParams().WithVhostID(endpointID).WithAppRequest(&operationRequest)
op, err := c.Client.Operations.PostVhostsVhostIDOperations(operationParams, c.Token)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion aptible/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Client) GetService(serviceID int64) (Service, error) {

func (c *Client) ScaleService(serviceID int64, containerCount int64, memoryLimit int64) error {
requestType := "scale"
request := models.AppRequest25{
request := models.AppRequest26{
Type: &requestType,
ContainerSize: memoryLimit,
ContainerCount: containerCount,
Expand Down
137 changes: 137 additions & 0 deletions client/operations/delete_backup_retention_policies_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5eb5e0

Please sign in to comment.