Skip to content

Commit

Permalink
feat: fetch endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
j0g3sc committed Nov 21, 2023
1 parent 8fa158d commit 6a4a39a
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

const (
apiRoot = "/api"
loginEndpoint = "/api/login"
apiMeshObjectsRoot = "/api/meshobjects"
loginEndpoint = "/api/login"

ERROR_AUTHENTICATION_FAILURE = "not authorized. check api key and secret."
ERROR_ENDPOINT_LOOKUP = "could not fetch endpoints for meshStack."
Expand All @@ -29,7 +29,7 @@ type MeshStackProviderClient struct {
}

type endpoints struct {
buildingBlocks string
BuildingBlocks string `json:"meshbuildingblocks"`
}

type loginResponse struct {
Expand Down Expand Up @@ -104,8 +104,36 @@ func (c *MeshStackProviderClient) lookUpEndpoints() error {
return errors.New(ERROR_AUTHENTICATION_FAILURE)
}

// TODO
return errors.New("not implemented")
meshObjectsPath, err := url.JoinPath(c.url.String(), apiMeshObjectsRoot)
if err != nil {
return err
}
meshObjects, _ := url.Parse(meshObjectsPath)

res, _ := c.httpClient.Do(
&http.Request{
URL: meshObjects,
Method: "GET",
Header: http.Header{
"Authorization": {c.token},
},
},
)
defer res.Body.Close()

if err != nil || res.StatusCode != 200 {
return errors.New(ERROR_AUTHENTICATION_FAILURE)
}

data, err := io.ReadAll(res.Body)
if err != nil {
return err
}
var endpoints endpoints
json.Unmarshal(data, &endpoints)
c.endpoints = endpoints

return nil
}

// TODO
Expand Down

0 comments on commit 6a4a39a

Please sign in to comment.