Skip to content

Commit

Permalink
mirror at 20220531162819
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed May 31, 2022
1 parent ea534f8 commit 12d8b5f
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 19 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Interface interface {
Project() Project
Role() Role
Deployment() Deployment
Domain() Domain
Route() Route
Disk() Disk
PullSecret() PullSecret
Expand Down
3 changes: 1 addition & 2 deletions api/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
47 changes: 47 additions & 0 deletions api/client/domain.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion api/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m *DatabaseList) Valid() error {
}

type DatabaseListResult struct {
List []*DatabaseItem
Items []*DatabaseItem
}

type DatabaseItem struct {
Expand Down
3 changes: 1 addition & 2 deletions api/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion api/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
101 changes: 101 additions & 0 deletions api/domain.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 1 addition & 2 deletions api/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions api/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions api/pullsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion api/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions api/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion api/workloadidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 12d8b5f

Please sign in to comment.