Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update inbox token api #481

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading