Skip to content

Commit

Permalink
Features/release checklist (#56)
Browse files Browse the repository at this point in the history
* ✨ Added resource-watcher utility with websocket.

* ✨ Added cli queries
  • Loading branch information
abdheshnayak authored Dec 23, 2023
1 parent e7a4b0a commit 5aaf6a3
Show file tree
Hide file tree
Showing 14 changed files with 857 additions and 603 deletions.
104 changes: 67 additions & 37 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,6 @@ query consoleListVpnDevices($clusterName: String, $search: SearchVPNDevices, $pq
spec {
accountName
clusterName
dns
ports {
port
targetPort
Expand Down Expand Up @@ -1516,7 +1515,6 @@ query consoleGetVpnDevice($clusterName: String!, $name: String!) {
spec {
accountName
clusterName
dns
ports {
port
targetPort
Expand Down Expand Up @@ -1617,7 +1615,7 @@ mutation consoleRejectInvitation($accountName: String!, $inviteToken: String!) {
accounts_rejectInvitation(accountName: $accountName, inviteToken: $inviteToken)
}

mutation consoleUpdateAccountMembership($accountName: String!, $memberId: ID!, $role: Kloudlite__io___apps___iam___types__Role!) {
mutation consoleUpdateAccountMembership($accountName: String!, $memberId: ID!, $role: Github__com___kloudlite___api___apps___iam___types__Role!) {
accounts_updateAccountMembership(
accountName: $accountName
memberId: $memberId
Expand Down Expand Up @@ -1763,21 +1761,10 @@ query consoleGetManagedService($project: ProjectId!, $scope: WorkspaceOrEnvId!,
}
recordVersion
spec {
inputs {
RawMessage
}
msvcKind {
serviceTemplate {
apiVersion
kind
}
nodeSelector
region
tolerations {
effect
key
operator
tolerationSeconds
value
spec
}
}
status {
Expand Down Expand Up @@ -1841,21 +1828,10 @@ query consoleListManagedServices($project: ProjectId!, $scope: WorkspaceOrEnvId!
}
recordVersion
spec {
inputs {
RawMessage
}
msvcKind {
serviceTemplate {
apiVersion
kind
}
nodeSelector
region
tolerations {
effect
key
operator
tolerationSeconds
value
spec
}
}
status {
Expand Down Expand Up @@ -1931,16 +1907,15 @@ query consoleGetManagedResource($project: ProjectId!, $scope: WorkspaceOrEnvId!,
}
recordVersion
spec {
inputs {
RawMessage
}
mresKind {
kind
}
msvcRef {
resourceTemplate {
apiVersion
kind
name
msvcRef {
name
kind
apiVersion
}
spec
}
}
status {
Expand Down Expand Up @@ -2703,6 +2678,61 @@ query consoleGetBuildRun($repoName: String!, $buildRunName: String!) {
}
}

query authCli_getKubeConfig($name: String!) {
infra_getCluster(name: $name) {
adminKubeconfig {
encoding
value
}
}
}

query authCli_listClusters($pagination: CursorPaginationIn) {
infra_listClusters(pagination: $pagination) {
edges {
node {
displayName
metadata {
name
}
}
}
}
}

query authCli_listAccounts {
accounts_listAccounts {
id
metadata {
name
}
displayName
}
}

query authCli_getCurrentUser {
auth_me {
id
email
name
}
}

mutation authCli_createRemoteLogin($secret: String) {
auth_createRemoteLogin(secret: $secret)
}

query authCli_getRemoteLogin($loginId: String!, $secret: String!) {
auth_getRemoteLogin(loginId: $loginId, secret: $secret) {
authHeader
status
}
}

mutation authSetRemoteAuthHeader($loginId: String!, $authHeader: String) {
auth_setRemoteAuthHeader(loginId: $loginId, authHeader: $authHeader)
}

query authCheckOauthEnabled {
auth_listOAuthProviders {
enabled
Expand Down
3 changes: 3 additions & 0 deletions lib/server/helpers/minimal-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const minimalAuth = async (ctx: IExtRemixCtx) => {
headers: ctx.request?.headers,
}).whoAmI();

console.log('whoAmI', whoAmI);

if (
whoAmI.errors &&
whoAmI.errors[0].message === 'input: auth_me user not logged in'
Expand All @@ -32,6 +34,7 @@ export const minimalAuth = async (ctx: IExtRemixCtx) => {
}

if (!(whoAmI.data && whoAmI.data)) {
console.log('whoAmI', whoAmI, 'red');
if (new URL(ctx.request.url).host === new URL(consoleBaseUrl).host) {
const { pathname } = new URL(ctx.request.url);
const history = cookie.get('url_history');
Expand Down
8 changes: 7 additions & 1 deletion lib/server/helpers/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ export const withRPC = (
try {
if (!req.body.method) throw new Error('Handler Method not found');

const method = req.body.method.split('.').reduce((acc: any, item) => {
const dt = req.body.method.split('.');

const method = dt.reduce((acc: any, item) => {
return acc[item];
}, handler);

if (!method)
throw new Error(`Handler Method not found ${req.body.method}`);

const response = await method(...(req.body.args || []));
res.json(response);
} catch (err) {
console.log('here');
next(err as Error);
}
};
Expand Down
26 changes: 26 additions & 0 deletions src/apps/auth/routes/_a.cli-logged-in.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getCookie } from '~/root/lib/app-setup/cookies';
import withContext from '~/root/lib/app-setup/with-contxt';
import { IExtRemixCtx } from '~/root/lib/types/common';

const cliLoggedIn = () => {
return (
<div className="flex min-h-screen justify-center items-center">
<div className="flex flex-col items-center justify-center gap-5">
<h1 className="text-5xl text-center font-bold text-black">
<span className="text-primary-600">Logged in</span> Successfully
</h1>
<div className="font-medium w-full text-center text-2xl text-black tracking-wide">
Visit your terminal.
</div>
</div>
</div>
);
};

export const loader = (ctx: IExtRemixCtx) => {
const cookie = getCookie(ctx);
cookie.remove('cliLogin');
return withContext(ctx, {});
};

export default cliLoggedIn;
147 changes: 147 additions & 0 deletions src/apps/auth/routes/_auth.cli-login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { Button, IconButton } from '~/components/atoms/button';
import { IExtRemixCtx } from '~/root/lib/types/common';
import getQueries from '~/root/lib/server/helpers/get-queries';
import { getCookie } from '~/root/lib/app-setup/cookies';
import withContext from '~/root/lib/app-setup/with-contxt';
import { useLoaderData, useLocation, useNavigate } from '@remix-run/react';
import md5 from '~/root/lib/client/helpers/md5';
import { Avatar } from '~/components/atoms/avatar';
import { cn } from '~/components/utils';
import { Power } from '@jengaicons/react';
import { GQLServerHandler } from '../server/gql/saved-queries';

function CliLogin() {
const { loginId, user } = useLoaderData();

const location = useLocation();
const navigate = useNavigate();

const onAuthenticate = () => {
if (!loginId) return;
const cookie = getCookie();
cookie.set('cliLogin', loginId);
navigate('/');
};

if (!loginId) {
return (
<div className="flex min-h-screen justify-center items-center">
<div className="flex flex-col items-center justify-center gap-5">
<h1 className="text-5xl text-center font-bold text-black">
<span className="text-primary-600">Login id</span> not provided
</h1>
<div className="font-medium w-full text-center text-2xl text-black tracking-wide">
Please wait try again.
</div>
</div>
</div>
);
}

const { avatar, email, name } = user || {};

const profile = () => {
return (
<div className="flex items-center gap-2 text-sm px-4 py-4 min-w-[15rem]">
<div className="w-12 h-12 border border-secondary-400 p-0.5 rounded-full">
{/* eslint-disable-next-line no-nested-ternary */}
{avatar ? (
<img
alt="profile"
src={avatar}
className="rounded-full object-cover"
/>
) : email ? (
<img
className="rounded-full"
alt={email}
src={`https://www.gravatar.com/avatar/${md5(email)}?d=identicon`}
/>
) : (
<Avatar size="lg" image={email} />
)}
</div>
<div className="flex flex-col items-start">
<span className="text-neutral-600 font-medium text-lg">
{name || email}
</span>
<span className="text-primary-400 text-sm">
{/* {role.replace('-', ' ')} */}
{email}
</span>
</div>
</div>
);
};

const logOut = async () => {
navigate(
`${
location.pathname +
location.search +
(location.search.trim() ? '&' : '?')
}logout=yes`,
{ replace: true }
);
};

return (
<div className="flex min-h-screen justify-center items-center">
<div className="flex flex-col items-center justify-center gap-12">
<h1 className="text-5xl text-center font-bold text-black">
Login to <span className="text-primary-600">Kloudlite CLI</span>
</h1>
<div
className={cn(
'font-medium w-full text-center text-2xl text-black tracking-wide px-6',
{
'bg-white border border-neutral-200 rounded-md ': user,
}
)}
>
{user ? (
<div className="flex gap-6 justify-center items-center">
<div>{profile()}</div>

<Button
variant="primary-outline"
onClick={onAuthenticate}
content="Authenticate"
/>

<IconButton onClick={logOut} icon={<Power />} />
</div>
) : (
<Button
size="lg"
onClick={onAuthenticate}
content="Login to Kloudlite"
/>
)}
</div>
</div>
</div>
);
}

export const loader = async (ctx: IExtRemixCtx) => {
const { loginId, logout } = await getQueries(ctx);
if (logout) {
const cookie = getCookie(ctx);

Object.keys(cookie.getAll()).forEach((key) => {
cookie.remove(key);
});

return withContext(ctx, { loginId });
}

const { data } = await GQLServerHandler(ctx.request).whoAmI();

return {
loginId: loginId || null,
user: data || null,
};
};

export default CliLogin;
6 changes: 4 additions & 2 deletions src/apps/auth/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import { getCookie } from '~/root/lib/app-setup/cookies';
import { IExtRemixCtx } from '~/root/lib/types/common';
import { GQLServerHandler } from '../server/gql/saved-queries';

// @ts-ignore
const restActions = async (ctx: IExtRemixCtx) => {
const cookie = getCookie(ctx);
if (cookie.get('cliLogin')) {
try {
console.log('here', 'lskdfjsldfj');

const { data, errors } = await GQLServerHandler(
ctx.request
// @ts-ignore
).setRemoteAuthHeader({
loginId: cookie.get('cliLogin'),
authHeader: ctx?.request?.headers?.get('cookie'),
});

logger.log(data, 'loggedin');
if (errors) {
console.log('here', errors);
throw errors[0];
}

Expand Down
Loading

0 comments on commit 5aaf6a3

Please sign in to comment.