Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from joyent/perigrin/initial-v3-fixes
Browse files Browse the repository at this point in the history
Initial V3 Fixes
  • Loading branch information
perigrin authored Oct 2, 2019
2 parents f16b0e5 + fb9af34 commit a39c329
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= v0.0.0
VERSION ?= v3.0.0-a1
#VERSION ?= $(shell git describe --tags --abbrev=0 | sed 's/^v//')

build: vendor clean test all ## Test and build binaries for local architecture
Expand Down
33 changes: 19 additions & 14 deletions hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type HardwareProduct struct {
Alias string `json:"alias"`
Prefix string `json:"prefix,omitempty"`
HardwareVendorID uuid.UUID `json:"hardware_vendor_id"`
GenerationName string `json:"generate_name,omitempty"`
GenerationName string `json:"generation_name,omitempty"`
LegacyProductName string `json:"legacy_product_name,omitempty"`
SKU string `json:"sku,omitempty"`
Specification string `json:"specification,omitempty"`
Expand All @@ -95,27 +95,32 @@ func (h *Hardware) GetProduct(id uuid.UUID) (hp HardwareProduct) {
return hp
}

// There are three string identifiers currently accepted by the API: name,
// alias, sku. The calls all look exactly the same where we stick the string in
// the url and hope for the best.
func (h *Hardware) GetProductByString(wat string) (hp HardwareProduct) {
uri := fmt.Sprintf("/hardware_product/%s", url.PathEscape(wat))
func (h *Hardware) GetProductByName(name string) (hp HardwareProduct) {
uri := fmt.Sprintf("/hardware_product/name=%s", url.PathEscape(name))
res := h.Do(h.Sling().New().Get(uri))
if ok := res.Parse(&hp); !ok {
panic(res)
panic(fmt.Sprintf("%v", res))
}

return hp
}

func (h *Hardware) GetProductByName(name string) HardwareProduct {
return h.GetProductByString(name)
}
func (h *Hardware) GetProductByAlias(alias string) (hp HardwareProduct) {
uri := fmt.Sprintf("/hardware_product/alias=%s", url.PathEscape(alias))
res := h.Do(h.Sling().New().Get(uri))
if ok := res.Parse(&hp); !ok {
panic(fmt.Sprintf("%v", res))
}

func (h *Hardware) GetProductByAlias(alias string) HardwareProduct {
return h.GetProductByString(alias)
return hp
}

func (h *Hardware) GetProductBySku(sku string) HardwareProduct {
return h.GetProductByString(sku)
func (h *Hardware) GetProductBySku(sku string) (hp HardwareProduct) {
uri := fmt.Sprintf("/hardware_product/sku=%s", url.PathEscape(sku))
res := h.Do(h.Sling().New().Get(uri))
if ok := res.Parse(&hp); !ok {
panic(fmt.Sprintf("%v", res))
}

return hp
}
1 change: 1 addition & 0 deletions relays.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Relay struct {
SshPort int `json:"ssh_port"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
LastSeen time.Time `json:"last_seen,omitempty"`
}

func (r Relay) String() string {
Expand Down
6 changes: 4 additions & 2 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"time"

"github.com/gofrs/uuid"
"github.com/jawher/mow.cli"
cli "github.com/jawher/mow.cli"
"github.com/olekukonko/tablewriter"
)

Expand All @@ -39,10 +39,12 @@ type DetailedUser struct {
Email string `json:"email"`
Created time.Time `json:"created"`
LastLogin time.Time `json:"last_login,omitempty"`
LastSeen time.Time `json:"last_seen,omitempty"`
RefuseSessionAuth bool `json:"refuse_session_auth"`
ForcePasswordChange bool `json:"force_password_change"`
IsAdmin bool `json:"is_admin"`
Workspaces WorkspaceAndRoles `json:"workspaces"`
Organizations interface{} `json:"organizations"`
}

func (u DetailedUser) String() string {
Expand Down Expand Up @@ -81,7 +83,7 @@ func (u DetailedUsers) Less(i, j int) bool {
func (u *Users) Me() (user DetailedUser) {
res := u.Do(u.Sling().Get("/user/me"))
if ok := res.Parse(&user); !ok {
panic(res)
panic(fmt.Sprintf("%v", res))
}
ret := make(WorkspaceAndRoles, 0)
cache := make(map[uuid.UUID]string)
Expand Down
4 changes: 2 additions & 2 deletions workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"time"

"github.com/gofrs/uuid"
"github.com/jawher/mow.cli"
cli "github.com/jawher/mow.cli"
"github.com/olekukonko/tablewriter"
)

Expand Down Expand Up @@ -52,7 +52,7 @@ type WorkspaceAndRole struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
ParentID uuid.UUID `json:"parent_id,omitempty"`
ParentID uuid.UUID `json:"parent_workspace_id,omitempty"`
Role string `json:"role"`
RoleVia uuid.UUID `json:"role_via"`

Expand Down

0 comments on commit a39c329

Please sign in to comment.