Skip to content

Commit

Permalink
Update inbox token api (#481)
Browse files Browse the repository at this point in the history
Signed-off-by: Imtiaz Uddin <[email protected]>
  • Loading branch information
Imtiaz246 authored Sep 17, 2024
1 parent aa8bfca commit bda875e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15,744 deletions.
2,621 changes: 0 additions & 2,621 deletions apis/core/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions apis/identity/v1alpha1/inboxtokenrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ type InboxTokenRequest struct {
type InboxTokenRequestRequest struct{}

type InboxTokenRequestResponse struct {
JmapJWTToken string `json:"jmapJWTToken"`
AdminJWTToken string `json:"adminJWTToken"`
AgentJWTToken string `json:"agentJwtToken"`
}

func init() {
Expand Down
2,632 changes: 2 additions & 2,630 deletions apis/identity/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions apis/management/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions apis/meta/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions apis/node/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions apis/ui/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions pkg/identity/b3.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ func (c *Client) Identify(clusterUID string) (*kmapi.ClusterMetadata, error) {
return &md, nil
}

func (c *Client) GetToken() (string, error) {
func (c *Client) GetToken() (*identityapi.InboxTokenRequestResponse, error) {
u, err := info.APIServerAddress(c.baseURL)
if err != nil {
return "", err
return nil, err
}

id, err := c.GetIdentity()
if err != nil {
return "", err
return nil, err
}

u.Path = path.Join(u.Path, "api/v1/agent", id.Status.Name, id.Status.UID, "token")

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return "", err
return nil, err
}
req.Header.Set("Content-Type", "application/json")
// add authorization header to the req
Expand All @@ -183,14 +183,20 @@ func (c *Client) GetToken() (string, error) {
klog.Errorln(string(encodeCertPEM(cert)))
}
}
return "", err
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
return nil, err
}
return string(body), nil

tokenResponse := &identityapi.InboxTokenRequestResponse{}
if err = json.Unmarshal(body, tokenResponse); err != nil {
return nil, err
}

return tokenResponse, nil
}

const SelfName = "self"
Expand Down

0 comments on commit bda875e

Please sign in to comment.