Skip to content

Commit

Permalink
Update inbox token api (#335)
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 ff3c5de commit 7aeea53
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 13,131 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.29.0
kmodules.xyz/offshoot-api v0.30.1
kmodules.xyz/resource-metadata v0.18.14-0.20240914112451-aa8bfca75970
kmodules.xyz/resource-metadata v0.18.14-0.20240917114603-bda875e59b47
kmodules.xyz/resource-metrics v0.30.4
kmodules.xyz/resource-metrics/utils v0.30.4
kmodules.xyz/sets v0.29.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.30.1 h1:TrulAYO+oBsXe9sZZGTmNWIuI8qD2izMpgcTSPvgAmI=
kmodules.xyz/offshoot-api v0.30.1/go.mod h1:T3mpjR6fui0QzOcmQvIuANytW48fe9ytmy/1cgx6D4g=
kmodules.xyz/resource-metadata v0.18.14-0.20240914112451-aa8bfca75970 h1:ZN/cO28opva5GV1UtwGCjYrmkrr8e69VqETnA1OFGaE=
kmodules.xyz/resource-metadata v0.18.14-0.20240914112451-aa8bfca75970/go.mod h1:6OFjG5wBSIG24xVgN/iOZcAh0fg/YNGYftAmJgF4bjc=
kmodules.xyz/resource-metadata v0.18.14-0.20240917114603-bda875e59b47 h1:+TCtVnnqzTp8EX7CC6IAZlS8V7AmSYs3EQKNTElk7WI=
kmodules.xyz/resource-metadata v0.18.14-0.20240917114603-bda875e59b47/go.mod h1:6OFjG5wBSIG24xVgN/iOZcAh0fg/YNGYftAmJgF4bjc=
kmodules.xyz/resource-metrics v0.30.4 h1:8HBPtYmo9ETY91gsc55JE8Z986+3ZuRq57M0wZ9npqI=
kmodules.xyz/resource-metrics v0.30.4/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ=
kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac=
Expand Down
7 changes: 3 additions & 4 deletions pkg/registry/identity/inboxtokenrequest/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ func (r *Storage) Destroy() {}

func (r *Storage) Create(ctx context.Context, obj runtime.Object, _ rest.ValidateObjectFunc, _ *metav1.CreateOptions) (runtime.Object, error) {
req := obj.(*identityapi.InboxTokenRequest)
token, err := r.bc.GetToken()
resp, err := r.bc.GetToken()
if err != nil {
return nil, err
}
req.Response = &identityapi.InboxTokenRequestResponse{
AdminJWTToken: token,
}
req.Response = resp

return req, nil
}
2,621 changes: 0 additions & 2,621 deletions vendor/kmodules.xyz/resource-metadata/apis/core/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions vendor/kmodules.xyz/resource-metadata/apis/meta/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

2,621 changes: 0 additions & 2,621 deletions vendor/kmodules.xyz/resource-metadata/apis/ui/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions vendor/kmodules.xyz/resource-metadata/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
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ kmodules.xyz/monitoring-agent-api/client
## explicit; go 1.22.0
kmodules.xyz/offshoot-api/api/v1
kmodules.xyz/offshoot-api/api/v2
# kmodules.xyz/resource-metadata v0.18.14-0.20240914112451-aa8bfca75970
# kmodules.xyz/resource-metadata v0.18.14-0.20240917114603-bda875e59b47
## explicit; go 1.22.1
kmodules.xyz/resource-metadata/apis/core/install
kmodules.xyz/resource-metadata/apis/core/v1alpha1
Expand Down

0 comments on commit 7aeea53

Please sign in to comment.