Skip to content

Commit 478985a

Browse files
authored
Merge pull request #93 from trickest/update/fleet-info-endpoint
Update fleet endpoint
2 parents d50139b + 147e2b5 commit 478985a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

types/user.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ type VaultInfo struct {
4444
ModifiedDate time.Time `json:"modified_date"`
4545
}
4646

47+
type Fleets struct {
48+
Next string `json:"next"`
49+
Previous string `json:"previous"`
50+
Page int `json:"page"`
51+
Last int `json:"last"`
52+
Count int `json:"count"`
53+
Results []Fleet `json:"results"`
54+
}
55+
4756
type Fleet struct {
4857
ID uuid.UUID `json:"id"`
4958
Name string `json:"name"`

util/util.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,38 @@ func GetMe() *types.User {
100100
}
101101

102102
func GetFleetInfo() *types.Fleet {
103-
resp := request.Trickest.Get().DoF("fleet/%s", GetVault())
103+
fleet := GetFleetInfoLegacy()
104+
if fleet != nil {
105+
return fleet
106+
}
107+
resp := request.Trickest.Get().DoF("fleet/?vault=%s", GetVault())
104108
if resp == nil || resp.Status() != http.StatusOK {
105109
request.ProcessUnexpectedResponse(resp)
106110
}
107111

112+
var fleets types.Fleets
113+
err := json.Unmarshal(resp.Body(), &fleets)
114+
if err != nil {
115+
fmt.Println("Error unmarshalling fleet response!")
116+
return nil
117+
}
118+
119+
if len(fleets.Results) == 0 {
120+
fmt.Println("Error: Couldn't find any active fleets")
121+
}
122+
123+
return &fleets.Results[0]
124+
}
125+
126+
func GetFleetInfoLegacy() *types.Fleet {
127+
resp := request.Trickest.Get().DoF("fleet/%s", GetVault())
128+
if resp == nil || resp.Status() != http.StatusOK {
129+
return nil
130+
}
131+
108132
var fleet types.Fleet
109133
err := json.Unmarshal(resp.Body(), &fleet)
110134
if err != nil {
111-
fmt.Println("Error unmarshalling fleet response!")
112135
return nil
113136
}
114137

0 commit comments

Comments
 (0)