Skip to content

Commit

Permalink
Merge pull request #93 from trickest/update/fleet-info-endpoint
Browse files Browse the repository at this point in the history
Update fleet endpoint
  • Loading branch information
mhmdiaa authored Oct 30, 2023
2 parents d50139b + 147e2b5 commit 478985a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ type VaultInfo struct {
ModifiedDate time.Time `json:"modified_date"`
}

type Fleets struct {
Next string `json:"next"`
Previous string `json:"previous"`
Page int `json:"page"`
Last int `json:"last"`
Count int `json:"count"`
Results []Fleet `json:"results"`
}

type Fleet struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Expand Down
27 changes: 25 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,38 @@ func GetMe() *types.User {
}

func GetFleetInfo() *types.Fleet {
resp := request.Trickest.Get().DoF("fleet/%s", GetVault())
fleet := GetFleetInfoLegacy()
if fleet != nil {
return fleet
}
resp := request.Trickest.Get().DoF("fleet/?vault=%s", GetVault())
if resp == nil || resp.Status() != http.StatusOK {
request.ProcessUnexpectedResponse(resp)
}

var fleets types.Fleets
err := json.Unmarshal(resp.Body(), &fleets)
if err != nil {
fmt.Println("Error unmarshalling fleet response!")
return nil
}

if len(fleets.Results) == 0 {
fmt.Println("Error: Couldn't find any active fleets")
}

return &fleets.Results[0]
}

func GetFleetInfoLegacy() *types.Fleet {
resp := request.Trickest.Get().DoF("fleet/%s", GetVault())
if resp == nil || resp.Status() != http.StatusOK {
return nil
}

var fleet types.Fleet
err := json.Unmarshal(resp.Body(), &fleet)
if err != nil {
fmt.Println("Error unmarshalling fleet response!")
return nil
}

Expand Down

0 comments on commit 478985a

Please sign in to comment.