Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit f4ba9be

Browse files
nxtcoder17nxtcoder19karthik1729
authored
add workmachine and workspace api [#394](#394)
Co-authored-by: Piyush Kumar <piyush.acet@gmail.com> Co-authored-by: Karthik Th <karthik@kloudlite.io>
1 parent 3c5a701 commit f4ba9be

84 files changed

Lines changed: 26006 additions & 14736 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.tools/nvim/__http__/infra/cmsvc.graphql.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
---
2+
3+
label: "list helm chart type Cluster msvc"
4+
query: |+
5+
query Infra_listHelmTypeClusterManagedServices {
6+
infra_listHelmTypeClusterManagedServices {
7+
totalCount
8+
edges {
9+
node {
10+
kind
11+
accountName
12+
spec {
13+
msvcSpec {
14+
plugin {
15+
kind
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
variables:
24+
{}
25+
26+
---
27+
28+
label: "list Cluster msvc"
29+
query: |+
30+
query Infra_listClusterManagedServices {
31+
infra_listClusterManagedServices {
32+
totalCount
33+
edges {
34+
node {
35+
accountName
36+
kind
37+
spec {
38+
msvcSpec {
39+
plugin {
40+
kind
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
150
---
251
label: "Clone Cluster Managed Service"
352
query: |+
@@ -17,4 +66,34 @@ variables:
1766
"destinationMsvcName": "msvc-one-clone2",
1867
"displayName": "msvc one clone2"
1968
}
69+
2070
---
71+
72+
label: "list Cluster msvc"
73+
query: |+
74+
query Infra_listClusterManagedServices {
75+
infra_listClusterManagedServices {
76+
totalCount
77+
edges {
78+
node {
79+
accountName
80+
kind
81+
spec {
82+
msvcSpec {
83+
plugin {
84+
kind
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
# variables:
93+
# {
94+
# "projectName": "sample-project",
95+
# "deviceBlueprintName": "sample-device-blueprint",
96+
# }
97+
98+
99+
---
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
label: "Create Workmachine"
3+
query: |+
4+
mutation Infra_createWorkMachine($clusterName: String!, $workmachine: WorkmachineIn!) {
5+
infra_createWorkMachine(clusterName: $clusterName, workmachine: $workmachine) {
6+
accountName
7+
}
8+
}
9+
variables:
10+
{
11+
"clusterName": "ttt",
12+
"workmachine": {
13+
"displayName": "tt",
14+
"metadata": {
15+
"name": "tt"
16+
}
17+
}
18+
}
19+
20+
---
21+
22+
label: "update Workmachine"
23+
query: |+
24+
mutation Infra_updateWorkMachine($clusterName: String!, $workmachine: WorkmachineIn!) {
25+
infra_updateWorkMachine(clusterName: $clusterName, workmachine: $workmachine) {
26+
accountName
27+
}
28+
}
29+
variables:
30+
{
31+
"clusterName": "ttt",
32+
"workmachine": {
33+
"displayName": "mm",
34+
"metadata": {
35+
"name": "tt"
36+
}
37+
}
38+
}
39+
40+
---
41+
42+
label: "update Workmachine Status"
43+
query: |+
44+
mutation Infra_updateWorkMachineStatus($clusterName: String!, $status: Boolean!, $name: String!) {
45+
infra_updateWorkMachineStatus(clusterName: $clusterName, status: $status, name: $name)
46+
}
47+
variables:
48+
{
49+
"clusterName": "test-clus",
50+
"status": true,
51+
"name": "test-wm1"
52+
}
53+
54+
---
55+
56+
label: "get workmachine"
57+
query: |+
58+
query Infra_getWorkmachine($clusterName: String!, $name: String!) {
59+
infra_getWorkmachine(clusterName: $clusterName, name: $name) {
60+
accountName
61+
}
62+
}
63+
variables:
64+
{
65+
"clusterName": "test-clus",
66+
"name": "test-wm1"
67+
}
68+
69+
---
70+
71+
label: "list App"
72+
query: |+
73+
query Iot_listApps($projectName: String!, $deviceBlueprintName: String!) {
74+
iot_listApps(projectName: $projectName, deviceBlueprintName: $deviceBlueprintName) {
75+
totalCount
76+
edges {
77+
node {
78+
displayName
79+
id
80+
}
81+
}
82+
}
83+
}
84+
variables:
85+
{
86+
"projectName": "sample-project",
87+
"deviceBlueprintName": "sample-device-blueprint",
88+
}
89+
90+
---
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
label: "Create workspace"
3+
query: |+
4+
mutation Infra_createWorkspace($workspace: WorkspaceIn!, $clusterName: String!) {
5+
infra_createWorkspace(workspace: $workspace, clusterName: $clusterName) {
6+
accountName
7+
}
8+
}
9+
variables:
10+
{
11+
"workspace": {
12+
"metadata": {
13+
"name": "test-ws1"
14+
},
15+
"displayName": "test ws1"
16+
},
17+
"clusterName": "test-clus"
18+
}
19+
20+
---
21+
22+
label: "update workspace"
23+
query: |+
24+
mutation Infra_updateWorkspace($clusterName: String!, $workspace: WorkspaceIn!) {
25+
infra_updateWorkspace(clusterName: $clusterName, workspace: $workspace) {
26+
accountName
27+
}
28+
}
29+
variables:
30+
{
31+
"workspace": {
32+
"metadata": {
33+
"name": "test-ws1"
34+
},
35+
"displayName": "test wss1"
36+
},
37+
"clusterName": "test-clus"
38+
}
39+
40+
---
41+
42+
label: "delete Workspace"
43+
query: |+
44+
mutation Infra_deleteWorkspace($clusterName: String!, $name: String!) {
45+
infra_deleteWorkspace(clusterName: $clusterName, name: $name)
46+
}
47+
variables:
48+
{
49+
"clusterName": "test-clus",
50+
"name": "test-ws1"
51+
}
52+
53+
---
54+
55+
label: "get workspace"
56+
query: |+
57+
query Infra_getWorkspace($clusterName: String!, $name: String!) {
58+
infra_getWorkspace(clusterName: $clusterName, name: $name) {
59+
accountName
60+
}
61+
}
62+
variables:
63+
{
64+
"clusterName": "test-clus",
65+
"name": "test-ws1"
66+
}
67+
68+
---
69+
70+
label: "list workspace"
71+
query: |+
72+
query Infra_listWorkspaces($clusterName: String!) {
73+
infra_listWorkspaces(clusterName: $clusterName) {
74+
totalCount
75+
}
76+
}
77+
variables:
78+
{
79+
"clusterName": "test-clus",
80+
}
81+
82+
---

.tools/taskfiles/docker.Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ tasks:
2222
echo "image exists, but overridden"
2323
fi
2424
25-
docker buildx build -t {{.image}} --output=type=image,compression=zstd,force-compression=true,compression-level=12,push={{.push_image}} {{.args}}
25+
DOCKER_BUILDKIT=1 docker buildx build -t {{.image}} --output=type=image,compression=zstd,force-compression=true,compression-level=12,push={{.push_image}} {{.args}}

.vscode/launch.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Console",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "debug",
12+
"program": "${workspaceFolder}/apps/console/main.go",
13+
"args": [
14+
"--dev"
15+
],
16+
"envFile": "${workspaceFolder}/apps/console/.secrets/env",
17+
},
18+
{
19+
"name": "Infra",
20+
"type": "go",
21+
"request": "launch",
22+
"mode": "debug",
23+
"program": "${workspaceFolder}/apps/infra/main.go",
24+
"args": [
25+
"--dev"
26+
],
27+
"envFile": "${workspaceFolder}/apps/infra/.secrets/env",
28+
},
29+
{
30+
"name": "Auth",
31+
"type": "go",
32+
"request": "launch",
33+
"mode": "debug",
34+
"program": "${workspaceFolder}/apps/auth/main.go",
35+
"args": [
36+
"--dev"
37+
],
38+
"envFile": "${workspaceFolder}/apps/auth/.secrets/env",
39+
}
40+
]
41+
}

apps/auth/Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ tasks:
4242

4343
- task: docker:build-and-push
4444
vars:
45-
args: "--platform linux/amd64,linux/arm64 --build-arg BINARY={{.binary}} ."
45+
args: "--platform linux/amd64 --build-arg BINARY={{.binary}} ."
4646
image: "{{.image}}"
4747

apps/auth/internal/app/grpc-server.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package app
22

33
import (
44
"context"
5+
56
"github.com/kloudlite/api/apps/auth/internal/entities"
7+
"github.com/kloudlite/api/common"
8+
"github.com/kloudlite/api/pkg/kv"
69
"github.com/kloudlite/api/pkg/repos"
710

811
"github.com/kloudlite/api/apps/auth/internal/domain"
@@ -12,7 +15,41 @@ import (
1215

1316
type authGrpcServer struct {
1417
auth.UnimplementedAuthServer
15-
d domain.Domain
18+
d domain.Domain
19+
sessionRepo kv.Repo[*common.AuthSession]
20+
}
21+
22+
// GenerateMachineSession implements auth.AuthServer.
23+
func (a *authGrpcServer) GenerateMachineSession(ctx context.Context, in *auth.GenerateMachineSessionIn) (*auth.GenerateMachineSessionOut, error) {
24+
session, err := a.d.MachineLogin(ctx, in.UserId, in.MachineId, in.Cluster)
25+
if err != nil {
26+
return nil, errors.NewE(err)
27+
}
28+
err = a.sessionRepo.Set(ctx, string(session.Id), session)
29+
if err != nil {
30+
return nil, errors.NewE(err)
31+
}
32+
if session == nil {
33+
return nil, errors.Newf("session is nil")
34+
}
35+
return &auth.GenerateMachineSessionOut{
36+
SessionId: string(session.Id),
37+
}, nil
38+
}
39+
40+
// ClearMachineSessionByMachine implements auth.AuthServer.
41+
func (a *authGrpcServer) ClearMachineSessionByMachine(context.Context, *auth.ClearMachineSessionByMachineIn) (*auth.ClearMachineSessionByMachineOut, error) {
42+
panic("unimplemented")
43+
}
44+
45+
// ClearMachineSessionByTeam implements auth.AuthServer.
46+
func (a *authGrpcServer) ClearMachineSessionByTeam(context.Context, *auth.ClearMachineSessionByTeamIn) (*auth.ClearMachineSessionByTeamOut, error) {
47+
panic("unimplemented")
48+
}
49+
50+
// ClearMachineSessionByUser implements auth.AuthServer.
51+
func (a *authGrpcServer) ClearMachineSessionByUser(context.Context, *auth.ClearMachineSessionByUserIn) (*auth.ClearMachineSessionByUserOut, error) {
52+
panic("unimplemented")
1653
}
1754

1855
func (a *authGrpcServer) GetUser(ctx context.Context, in *auth.GetUserIn) (*auth.GetUserOut, error) {
@@ -72,8 +109,9 @@ func (a *authGrpcServer) GetAccessToken(ctx context.Context, in *auth.GetAccessT
72109
return a.FromAccToken(*token), nil
73110
}
74111

75-
func fxRPCServer(d domain.Domain) auth.AuthServer {
112+
func fxRPCServer(d domain.Domain, sessionRepo kv.Repo[*common.AuthSession]) auth.AuthServer {
76113
return &authGrpcServer{
77-
d: d,
114+
d: d,
115+
sessionRepo: sessionRepo,
78116
}
79117
}

apps/auth/internal/domain/domain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Domain interface {
1414
CreateRemoteLogin(ctx context.Context, secret string) (repos.ID, error)
1515

1616
Login(ctx context.Context, email string, password string) (*common.AuthSession, error)
17+
MachineLogin(ctx context.Context, userId string, machineId string, cluster string) (*common.AuthSession, error)
1718
SignUp(ctx context.Context, name string, email string, password string, captchaToken string) (*common.AuthSession, error)
1819
EnsureUserByEmail(ctx context.Context, email string) (*entities.User, error)
1920
GetUserById(ctx context.Context, id repos.ID) (*entities.User, error)

0 commit comments

Comments
 (0)