-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
163 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters