Skip to content

Commit

Permalink
[GEN-2185]: add API read-token with GraphQL queries and update CLI dr…
Browse files Browse the repository at this point in the history
…awer to display tokens in UI (#2175)

This pull request includes several changes to add support for API
tokens, introduce new icons, and update the frontend components to
reflect these changes. The most important changes include adding API
token support, creating new icon components, and updating the main
header and overview drawers.

API token support:

*
[`frontend/gqlgen.yml`](diffhunk://#diff-53053c2ca35acf8830a765ef72835e81aec5118b5194f0db21cbd80446405a0cR47-R48):
Added `apiTokens` resolver to `ComputePlatform` fields.
*
[`frontend/graph/common.go`](diffhunk://#diff-ffa020f42888de4cce165f880d16fcea61971412669e39abd225c638af94e77dR1-R30):
Implemented `extractJWTPayload` function to decode JWT tokens.
*
[`frontend/graph/model/models_gen.go`](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R57-R63):
Introduced `APIToken` type and added `apiTokens` field to
`ComputePlatform` struct.
[[1]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R57-R63)
[[2]](diffhunk://#diff-642ccd7ed71fdfa394bd7f7fd99c9c33e20ff18c876a91cb989d379a44390469R84)
*
[`frontend/graph/schema.graphqls`](diffhunk://#diff-bc07b91dedd1782d9ddbbb6374ad97c7604f9a267de5174645723d863c732f80R192-R201):
Added `ApiToken` type and `apiTokens` field to `ComputePlatform`.
*
[`frontend/graph/schema.resolvers.go`](diffhunk://#diff-8e6e95029056db2c0301fc338e0ca5a04356ce5d45ee9514bbd167f2d85bae70R22-R67):
Implemented `APITokens` resolver for `ComputePlatform`.

New icon components:

*
[`frontend/webapp/assets/icons/common/copy-icon.tsx`](diffhunk://#diff-d35e120e9fdda5b20903db9d0dfc2838be8d384811933709564d464edf38e73fR1-R16):
Added `CopyIcon` component.
*
[`frontend/webapp/assets/icons/common/key-icon.tsx`](diffhunk://#diff-21611251ee97e59e22133d5c510ba2404aeba805402fc811b875a5d43ad25bbaR1-R16):
Added `KeyIcon` component.
*
[`frontend/webapp/assets/icons/common/terminal-icon.tsx`](diffhunk://#diff-4e3c0134ff5cb358bb022884856d6fa8ae0c059f23cceaab812870fc837e33e0R1-R16):
Added `TerminalIcon` component.
*
[`frontend/webapp/assets/icons/common/index.ts`](diffhunk://#diff-296ed595d55f81134becefd3bd98f603053606a5a1d310efc5ca36c85f2f9506R8):
Exported new icon components.
[[1]](diffhunk://#diff-296ed595d55f81134becefd3bd98f603053606a5a1d310efc5ca36c85f2f9506R8)
[[2]](diffhunk://#diff-296ed595d55f81134becefd3bd98f603053606a5a1d310efc5ca36c85f2f9506R19-R26)

Main header and overview drawers updates:

*
[`frontend/webapp/components/main/header/index.tsx`](diffhunk://#diff-2c96f91ec30d2116981a9c0a562820ff9fd87c8292cb5dca11a45d6fb2ac6c04R2-R9):
Updated main header to include a button for the new CLI drawer.
[[1]](diffhunk://#diff-2c96f91ec30d2116981a9c0a562820ff9fd87c8292cb5dca11a45d6fb2ac6c04R2-R9)
[[2]](diffhunk://#diff-2c96f91ec30d2116981a9c0a562820ff9fd87c8292cb5dca11a45d6fb2ac6c04L37-R38)
[[3]](diffhunk://#diff-2c96f91ec30d2116981a9c0a562820ff9fd87c8292cb5dca11a45d6fb2ac6c04L49-R55)
*
[`frontend/webapp/components/overview/all-drawers/cli-drawer.tsx`](diffhunk://#diff-05c3af50f20a5a1195555bcff0f9a44be51f03ad2f4cd080dff2a3b2ee6ababcR1-R109):
Created a new drawer component for displaying API tokens and Odigos CLI
information.
*
[`frontend/webapp/components/overview/all-drawers/index.tsx`](diffhunk://#diff-bf25245ffa5cb1c7ea54b941a97fc9f53caf28b7154cb4eda9b88c7b6f0944d1R2-L3):
Updated drawer selection logic to include the new CLI drawer.
[[1]](diffhunk://#diff-bf25245ffa5cb1c7ea54b941a97fc9f53caf28b7154cb4eda9b88c7b6f0944d1R2-L3)
[[2]](diffhunk://#diff-bf25245ffa5cb1c7ea54b941a97fc9f53caf28b7154cb4eda9b88c7b6f0944d1L25-R26)
*
[`frontend/webapp/graphql/queries/compute-platform.ts`](diffhunk://#diff-31f9118ffb7e3400a45302bd5f30d621f58adaf33d086beb183bd302b980c521R6-R11):
Updated GraphQL query to fetch `apiTokens`.
*
[`frontend/webapp/hooks/common/index.ts`](diffhunk://#diff-e91dfaad8acf2180d9c3e07b98c4f7d5bdab76542b7ab14d5e84202a42aeba29R2):
Added export for `useCopy` hook.
  • Loading branch information
BenElferink authored Jan 12, 2025
1 parent c567fa9 commit 2ac3bc1
Show file tree
Hide file tree
Showing 27 changed files with 857 additions and 78 deletions.
2 changes: 2 additions & 0 deletions frontend/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ models:

ComputePlatform:
fields:
apiTokens:
resolver: true
k8sActualNamespace:
resolver: true
k8sActualNamespaces:
Expand Down
30 changes: 30 additions & 0 deletions frontend/graph/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package graph

import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)

func extractJWTPayload(token string) (map[string]interface{}, error) {
parts := strings.Split(token, ".")
if len(parts) != 3 {
return nil, fmt.Errorf("invalid JWT token format")
}

// Decode the payload (second part of the JWT)
payloadBytes, err := base64.RawURLEncoding.DecodeString(parts[1])
if err != nil {
return nil, fmt.Errorf("failed to decode JWT payload: %w", err)
}

// Parse the payload as JSON
var payload map[string]interface{}
err = json.Unmarshal(payloadBytes, &payload)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal JWT payload: %w", err)
}

return payload, nil
}
Loading

0 comments on commit 2ac3bc1

Please sign in to comment.