From 7b72e8257c07d4a0bf1dbb8dccec93c64117d6b8 Mon Sep 17 00:00:00 2001 From: Chris Prather Date: Wed, 2 Oct 2019 21:01:17 +0000 Subject: [PATCH 1/2] set a temporary version in the Makefile so our builds work with v3 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 675be55..260711c 100644 --- a/Makefile +++ b/Makefile @@ -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 From fb9af34c1b1ff11d5836347742707ded6b024abd Mon Sep 17 00:00:00 2001 From: Chris Prather Date: Wed, 2 Oct 2019 20:52:21 +0000 Subject: [PATCH 2/2] Update the various endpoints to work with the new schemas from v3. --- hardware.go | 33 +++++++++++++++++++-------------- relays.go | 1 + user.go | 6 ++++-- workspaces.go | 4 ++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/hardware.go b/hardware.go index 5d3d3ee..8c99d77 100644 --- a/hardware.go +++ b/hardware.go @@ -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"` @@ -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 } diff --git a/relays.go b/relays.go index b5a5c2a..37f1159 100644 --- a/relays.go +++ b/relays.go @@ -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 { diff --git a/user.go b/user.go index 3373be9..b689bed 100644 --- a/user.go +++ b/user.go @@ -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" ) @@ -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 { @@ -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) diff --git a/workspaces.go b/workspaces.go index 0778486..f24f244 100644 --- a/workspaces.go +++ b/workspaces.go @@ -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" ) @@ -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"`