From 12d8b5f68744078604ce095b9c944dd66a4a4f24 Mon Sep 17 00:00:00 2001 From: Thanatat Tamtan Date: Tue, 31 May 2022 16:28:24 +0700 Subject: [PATCH] mirror at 20220531162819 --- api/api.go | 1 + api/billing.go | 3 +- api/client/client.go | 4 ++ api/client/domain.go | 47 +++++++++++++++++++ api/database.go | 2 +- api/deployment.go | 3 +- api/disk.go | 1 - api/domain.go | 101 ++++++++++++++++++++++++++++++++++++++++ api/location.go | 3 +- api/project.go | 3 +- api/pullsecret.go | 7 ++- api/role.go | 1 - api/serviceaccount.go | 5 +- api/workloadidentity.go | 1 - 14 files changed, 163 insertions(+), 19 deletions(-) create mode 100644 api/client/domain.go create mode 100644 api/domain.go diff --git a/api/api.go b/api/api.go index 0baa433..7e36e04 100644 --- a/api/api.go +++ b/api/api.go @@ -7,6 +7,7 @@ type Interface interface { Project() Project Role() Role Deployment() Deployment + Domain() Domain Route() Route Disk() Disk PullSecret() PullSecret diff --git a/api/billing.go b/api/billing.go index 81c9268..8970456 100644 --- a/api/billing.go +++ b/api/billing.go @@ -54,8 +54,7 @@ type BillingCreateResult struct { } type BillingListResult struct { - Items []*BillingItem `json:"items" yaml:"items"` - Billings []*BillingItem `json:"billings" yaml:"billings"` + Items []*BillingItem `json:"items" yaml:"items"` } type BillingDelete struct { diff --git a/api/client/client.go b/api/client/client.go index 5a04d4c..ee74076 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -85,6 +85,10 @@ func (c *Client) Deployment() api.Deployment { return deploymentClient{c} } +func (c *Client) Domain() api.Domain { + return domainClient{c} +} + func (c *Client) Route() api.Route { return routeClient{c} } diff --git a/api/client/domain.go b/api/client/domain.go new file mode 100644 index 0000000..c111074 --- /dev/null +++ b/api/client/domain.go @@ -0,0 +1,47 @@ +package client + +import ( + "context" + + "github.com/deploys-app/deploys/api" +) + +type domainClient struct { + inv invoker +} + +func (c domainClient) Create(ctx context.Context, m *api.DomainCreate) (*api.Empty, error) { + var res api.Empty + err := c.inv.invoke(ctx, "domain.create", m, &res) + if err != nil { + return nil, err + } + return &res, nil +} + +func (c domainClient) Get(ctx context.Context, m *api.DomainGet) (*api.DomainItem, error) { + var res api.DomainItem + err := c.inv.invoke(ctx, "domain.get", m, &res) + if err != nil { + return nil, err + } + return &res, nil +} + +func (c domainClient) List(ctx context.Context, m *api.DomainList) (*api.DomainListResult, error) { + var res api.DomainListResult + err := c.inv.invoke(ctx, "domain.list", m, &res) + if err != nil { + return nil, err + } + return &res, nil +} + +func (c domainClient) Delete(ctx context.Context, m *api.DomainDelete) (*api.Empty, error) { + var res api.Empty + err := c.inv.invoke(ctx, "domain.delete", m, &res) + if err != nil { + return nil, err + } + return &res, nil +} diff --git a/api/database.go b/api/database.go index 21d8548..0002563 100644 --- a/api/database.go +++ b/api/database.go @@ -50,7 +50,7 @@ func (m *DatabaseList) Valid() error { } type DatabaseListResult struct { - List []*DatabaseItem + Items []*DatabaseItem } type DatabaseItem struct { diff --git a/api/deployment.go b/api/deployment.go index 58e6aac..9c6e1de 100644 --- a/api/deployment.go +++ b/api/deployment.go @@ -345,8 +345,7 @@ func (m *DeploymentList) Valid() error { } type DeploymentListResult struct { - Items []*DeploymentItem `json:"items" yaml:"items"` - Deployments []*DeploymentItem `json:"deployments" yaml:"deployments"` + Items []*DeploymentItem `json:"items" yaml:"items"` } func (m *DeploymentListResult) Table() [][]string { diff --git a/api/disk.go b/api/disk.go index af7db2f..bee2a6a 100644 --- a/api/disk.go +++ b/api/disk.go @@ -100,7 +100,6 @@ func (m *DiskList) Valid() error { type DiskListResult struct { Items []*DiskItem `json:"items" yaml:"items"` - List []*DiskItem `json:"list" yaml:"list"` } func (m *DiskListResult) Table() [][]string { diff --git a/api/domain.go b/api/domain.go new file mode 100644 index 0000000..6268765 --- /dev/null +++ b/api/domain.go @@ -0,0 +1,101 @@ +package api + +import ( + "context" + "strings" + + "github.com/asaskevich/govalidator" + "github.com/moonrhythm/validator" +) + +type Domain interface { + Create(ctx context.Context, m *DomainCreate) (*Empty, error) + Get(ctx context.Context, m *DomainGet) (*DomainItem, error) + List(ctx context.Context, m *DomainList) (*DomainListResult, error) + Delete(ctx context.Context, m *DomainDelete) (*Empty, error) +} + +type DomainCreate struct { + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` + Domain string `json:"domain" yaml:"domain"` +} + +func (m *DomainCreate) Valid() error { + v := validator.New() + + v.Must(m.Project != "", "project required") + v.Must(m.Location != "", "location required") + v.Must(govalidator.IsDNSName(m.Domain), "domain invalid") + v.Must(!strings.HasSuffix(m.Domain, ".deploys.app"), "domain invalid") + + return WrapValidate(v) +} + +type DomainGet struct { + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` + Domain string `json:"domain" yaml:"domain"` +} + +func (m *DomainGet) Valid() error { + v := validator.New() + + v.Must(m.Project != "", "project required") + v.Must(m.Location != "", "location required") + v.Must(govalidator.IsDNSName(m.Domain), "domain invalid") + + return WrapValidate(v) +} + +type DomainList struct { + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` +} + +func (m *DomainList) Valid() error { + v := validator.New() + + v.Must(m.Project != "", "project required") + + return WrapValidate(v) +} + +type DomainListResult struct { + Items []*DomainItem `json:"items" yaml:"items"` +} + +func (m *DomainListResult) Table() [][]string { + table := [][]string{ + {"DOMAIN", "LOCATION"}, + } + for _, x := range m.Items { + table = append(table, []string{ + x.Domain, + x.Location, + }) + } + return table +} + +type DomainItem struct { + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` + Domain string `json:"domain" yaml:"domain"` +} + +type DomainDelete struct { + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` + Domain string `json:"domain" yaml:"domain"` +} + +func (m *DomainDelete) Valid() error { + v := validator.New() + + v.Must(m.Project != "", "project required") + v.Must(m.Location != "", "location required") + v.Must(govalidator.IsDNSName(m.Domain), "domain invalid") + + return WrapValidate(v) +} diff --git a/api/location.go b/api/location.go index 805b860..1370431 100644 --- a/api/location.go +++ b/api/location.go @@ -17,8 +17,7 @@ type LocationList struct { } type LocationListResult struct { - Items []*LocationItem `json:"items" yaml:"items"` - Locations []*LocationItem `json:"locations" yaml:"locations"` + Items []*LocationItem `json:"items" yaml:"items"` } func (m *LocationListResult) Table() [][]string { diff --git a/api/project.go b/api/project.go index 71d7016..8dc2b00 100644 --- a/api/project.go +++ b/api/project.go @@ -108,8 +108,7 @@ type ProjectQuota struct { } type ProjectListResult struct { - Items []*ProjectItem `json:"items" yaml:"items"` - Projects []*ProjectItem `json:"projects" yaml:"projects"` + Items []*ProjectItem `json:"items" yaml:"items"` } func (m *ProjectListResult) Table() [][]string { diff --git a/api/pullsecret.go b/api/pullsecret.go index a41ac14..78bd953 100644 --- a/api/pullsecret.go +++ b/api/pullsecret.go @@ -79,10 +79,9 @@ func (m *PullSecretList) Valid() error { } type PullSecretListResult struct { - Project string `json:"project" yaml:"project"` - Location string `json:"location" yaml:"location"` - Items []*PullSecretItem `json:"items" yaml:"items"` - PullSecrets []*PullSecretItem `json:"pullSecrets" yaml:"pullSecrets"` + Project string `json:"project" yaml:"project"` + Location string `json:"location" yaml:"location"` + Items []*PullSecretItem `json:"items" yaml:"items"` } func (m *PullSecretListResult) Table() [][]string { diff --git a/api/role.go b/api/role.go index 6c16149..5d7f4b3 100644 --- a/api/role.go +++ b/api/role.go @@ -141,7 +141,6 @@ type RoleList struct { type RoleListResult struct { Project string `json:"project" yaml:"project"` Items []*RoleListItem `json:"items" yaml:"items"` - Roles []*RoleListItem `json:"roles" yaml:"roles"` // TODO: deprecated } func (m *RoleListResult) Table() [][]string { diff --git a/api/serviceaccount.go b/api/serviceaccount.go index 690c7be..dcd4367 100644 --- a/api/serviceaccount.go +++ b/api/serviceaccount.go @@ -112,9 +112,8 @@ type ServiceAccountListItem struct { } type ServiceAccountListResult struct { - Project string `json:"project" yaml:"project"` - Items []*ServiceAccountListItem `json:"items" yaml:"items"` - ServiceAccounts []*ServiceAccountListItem `json:"serviceAccounts" yaml:"serviceAccounts"` // TODO: deprecated + Project string `json:"project" yaml:"project"` + Items []*ServiceAccountListItem `json:"items" yaml:"items"` } func (m *ServiceAccountListResult) Table() [][]string { diff --git a/api/workloadidentity.go b/api/workloadidentity.go index 1f9a6ef..e38ac92 100644 --- a/api/workloadidentity.go +++ b/api/workloadidentity.go @@ -129,7 +129,6 @@ func (m *WorkloadIdentityItem) Table() [][]string { type WorkloadIdentityListResult struct { Items []*WorkloadIdentityItem `json:"items" yaml:"items"` - List []*WorkloadIdentityItem `json:"list" yaml:"list"` // TODO: deprecated } func (m *WorkloadIdentityListResult) Table() [][]string {