Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated paas #136

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x, 1.17.x, 1.18.x]
go-version: [1.17.x, 1.18.x]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
135 changes: 77 additions & 58 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,52 @@ import (
"github.com/civo/civogo/utils"
)

// ProcInfo is the struct for process information
type ProcInfo struct {
ProcessType string `json:"process_type,omitempty"`
ProcessCount int `json:"process_count,omitempty"`

// Currently, command and Args are only applicable for when container image is provided, not when git repo is provided
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
}

// Application is the struct for the Application model
type Application struct {
Name string `json:"name" validate:"required"`
ID string `json:"id"`
NetworkID string `json:"network_id" validate:"required"`
Description string `json:"description"`
Image string `json:"image"`
Size string `json:"size"`
ProcessInfo []ProcessInfo `json:"process_info,omitempty"`
Domains []string `json:"domains,omitempty"`
SSHKeyIDs []string `json:"ssh_key_ids,omitempty"`
Config []EnvVar `json:"config,omitempty"`
// Status can be one of:
// - "building": Implies platform is building
// - "available": Implies platform is available to accept image
// - "ready": Implies app is ready
Status string `json:"status"`
Name string `json:"name" schema:"name"`
ID string `json:"id"`
NetworkID string `json:"network_id" validate:"required" schema:"network_id"`
FirewallID string `json:"firewall_id" schema:"firewall_id"`
Image *string `json:"image,omitempty" schema:"image"`
Size string `json:"size" schema:"size"`
ProcessInfo []ProcInfo `json:"process_info,omitempty"`
GitInfo *GitInfo `json:"git_info,omitempty" schema:"git_info"`
Config ObservedConfig `json:"config,omitempty"`
AppIP string `json:"app_ip,omitempty"`
Domains []string `json:"domains,omitempty"`
PublicIPv4Required bool `json:"public_ipv4_required" schema:"public_ipv4_required"`
Status string `json:"status"`
}

// ApplicationConfig describes the parameters for a new CivoApp
type ApplicationConfig struct {
Name string `json:"name" validate:"required"`
NetworkID string `json:"network_id" validate:"required"`
Description string `json:"description"`
Size string `json:"size"`
SSHKeyIDs []string `json:"ssh_key_ids,omitempty"`
// GitInfo holds the git information for the application
type GitInfo struct {
GitURL string `json:"url" schema:"url"`
GitToken string `json:"token" schema:"token"`
PullPreference *PullPreference `json:"pull_preferences,omitempty" schema:"pull_preferences"`
}

// UpdateApplicationRequest is the struct for the UpdateApplication request
type UpdateApplicationRequest struct {
Name string `json:"name"`
Advanced bool `json:"advanced"`
Image string `json:"image" `
Description string `json:"description"`
ProcessInfo []ProcessInfo `json:"process_info"`
Size string `json:"size" schema:"size"`
SSHKeyIDs []string `json:"ssh_key_ids" `
Config []EnvVar `json:"config"`
Domains []string `json:"domains"`
// PullPreference determines which tag/branch should the image be built from.
// If both are specified, the tag will be used(Tags>Branches)
// If neither is specified, main/master will be used (main > master)
type PullPreference struct {
Tag *string `json:"tag,omitempty" schema:"tag"`
Branch *string `json:"branch,omitempty" schema:"branch"`
}

// PaginatedApplications returns a paginated list of Application object
type PaginatedApplications struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Pages int `json:"pages"`
Items []Application `json:"items"`
// ObservedConfig defines the observed state of EnvVar
type ObservedConfig struct {
Env []EnvVar `json:"env_vars,omitempty"`
LastSyncedAt string `json:"last_sycned_at,omitempty"`
}

// EnvVar holds key-value pairs for an application
Expand All @@ -64,10 +63,42 @@ type EnvVar struct {
Value string `json:"value"`
}

// ProcessInfo contains the information about the process obtained from Procfile
type ProcessInfo struct {
ProcessType string `json:"processType"`
ProcessCount int `json:"processCount"`
// RegistryAuth holds the registry auth for an application
type RegistryAuth struct {
Username string `json:"username"`
Password string `json:"password"`
}

// ApplicationConfig describes the parameters for a new CivoApp
type ApplicationConfig struct {
Name string `json:"name"`
NetworkID string `json:"network_id" validate:"required"`
Size string `json:"size"`
Image *string `json:"image,omitempty"`
GitInfo *GitInfo `json:"git_info,omitempty"`
PublicIPv4Required bool `json:"public_ipv4_required" schema:"public_ipv4_required"`
Region string `json:"region"`
}

// PaginatedApplications returns a paginated list of Application object
type PaginatedApplications struct {
Page int `json:"page"`
PerPage int `json:"per_page"`
Pages int `json:"pages"`
Items []Application `json:"items"`
}

// UpdateApplicationRequest is the struct for the UpdateApplication request
type UpdateApplicationRequest struct {
Name string `json:"name" schema:"name"`
Size string `json:"size" schema:"size"`
ProcessInfo []ProcInfo `json:"process_info" schema:"process_info"`
GitInfo *GitInfo `json:"git_info,omitempty" schema:"git_info"`
EnvVars []EnvVar `json:"env_vars,omitempty" schema:"env_vars"`
FirewallID string `json:"firewall_id" schema:"firewall_id"`
RegistryAuth *RegistryAuth `json:"registry_auth" schema:"registry_auth"`
Image *string `json:"image,omitempty" schema:"image"`
Region string `json:"region"`
}

// ErrAppDomainNotFound is returned when the domain is not found
Expand Down Expand Up @@ -111,11 +142,9 @@ func (c *Client) NewApplicationConfig() (*ApplicationConfig, error) {
}

return &ApplicationConfig{
Name: utils.RandomName(),
NetworkID: network.ID,
Description: "",
Size: "small",
SSHKeyIDs: []string{},
Name: utils.RandomName(),
NetworkID: network.ID,
Size: "small",
}, nil
}

Expand Down Expand Up @@ -192,13 +221,3 @@ func (c *Client) DeleteApplication(id string) (*SimpleResponse, error) {

return c.DecodeSimpleResponse(resp)
}

// GetApplicationLogAuth returns an application log auth
func (c *Client) GetApplicationLogAuth(id string) (string, error) {
resp, err := c.SendGetRequest(fmt.Sprintf("/v2/applications/%s/log_auth", id))
if err != nil {
return "", decodeError(err)
}

return string(resp), nil
}
50 changes: 8 additions & 42 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,8 @@ func TestListApplications(t *testing.T) {
"name": "your-app-name",
"status": "ACTIVE",
"account_id": "12345",
"network_id": "34567",
"description": "this is a test app",
"process_info": [
{
"processType": "web",
"processCount": 1
}],
"domains": [
"your-app-name.example.com"
],
"ssh_key_ids": [
"12345"
],
"config": [
{
"name": "PORT",
"value": "80"
}]
}]}`,
"network_id": "34567"
}]}`,
})

defer server.Close()
Expand All @@ -46,25 +29,10 @@ func TestListApplications(t *testing.T) {
Pages: 1,
Items: []Application{
{
ID: "69a23478-a89e-41d2-97b1-6f4c341cee70",
Name: "your-app-name",
Status: "ACTIVE",
NetworkID: "34567",
Description: "this is a test app",
ProcessInfo: []ProcessInfo{
{
ProcessType: "web",
ProcessCount: 1,
},
},
Domains: []string{"your-app-name.example.com"},
SSHKeyIDs: []string{"12345"},
Config: []EnvVar{
{
Name: "PORT",
Value: "80",
},
},
ID: "69a23478-a89e-41d2-97b1-6f4c341cee70",
Name: "your-app-name",
Status: "ACTIVE",
NetworkID: "34567",
},
},
}
Expand All @@ -81,10 +49,8 @@ func TestCreateApplication(t *testing.T) {
defer server.Close()

cfg := &ApplicationConfig{
Name: "test-app",
Description: "test app",
SSHKeyIDs: []string{"12345"},
Size: "small",
Name: "test-app",
Size: "small",
}

got, err := client.CreateApplication(cfg)
Expand Down
12 changes: 11 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
module github.com/civo/civogo

go 1.16
go 1.18

require (
github.com/google/go-querystring v1.1.0
github.com/onsi/gomega v1.19.0
)

require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading