-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enclave manager indexer client (#1643)
## Description: This PR adds a typed indexer client into the new enclave manager code. This client will be used to generate the forms for configuring enclaves and eventually for listing the catalog. Additionally this PR: * refactors the current kurtosis client into `client/enclaveManager`. * uses the `check` endpoint in `KurtosisClient` to perform a basic connectivity check when `KurtosisClientContext` starts up. I chose not to extend the `KurtosisClient` from the `KurtosisPackageIndexerClient` as whilst that would have been convenient, they have different responsibilities. ## Is this change user facing? NO (the new enclave manager is not live) ## References (if applicable): This PR is based on #1639
- Loading branch information
Showing
54 changed files
with
2,573 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
REACT_APP_KURTOSIS_DEFAULT_HOST=localhost | ||
REACT_APP_KURTOSIS_DEFAULT_PORT=8081 | ||
|
||
REACT_APP_KURTOSIS_CLOUD_URL=https://cloud.kurtosis.com:9770 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/client/AuthenticatedKurtosisClient.ts → ...aveManager/AuthenticatedKurtosisClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ger/web/src/client/LocalKurtosisClient.ts → ...ent/enclaveManager/LocalKurtosisClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
enclave-manager/web/src/client/packageIndexer/KurtosisPackageIndexerClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createPromiseClient, PromiseClient } from "@connectrpc/connect"; | ||
import { createConnectTransport } from "@connectrpc/connect-web"; | ||
import { asyncResult } from "../../utils"; | ||
import { KURTOSIS_CLOUD_URL } from "../constants"; | ||
import { KurtosisPackageIndexer } from "./api/kurtosis_package_indexer_connect"; | ||
import { ReadPackageRequest } from "./api/kurtosis_package_indexer_pb"; | ||
|
||
export class KurtosisPackageIndexerClient { | ||
private client: PromiseClient<typeof KurtosisPackageIndexer>; | ||
|
||
constructor() { | ||
this.client = createPromiseClient(KurtosisPackageIndexer, createConnectTransport({ baseUrl: KURTOSIS_CLOUD_URL })); | ||
} | ||
|
||
getPackages = async () => { | ||
return asyncResult(() => { | ||
return this.client.getPackages({}); | ||
}); | ||
}; | ||
|
||
readPackage = async (packageUrl: string) => { | ||
return asyncResult(() => { | ||
const components = packageUrl.split("/"); | ||
if (components.length < 3) { | ||
throw Error(`Illegal url, invalid number of components: ${packageUrl}`); | ||
} | ||
if (components[1].length < 1 || components[2].length < 1) { | ||
throw Error(`Illegal url, empty components: ${packageUrl}`); | ||
} | ||
return this.client.readPackage( | ||
new ReadPackageRequest({ | ||
repositoryMetadata: { | ||
baseUrl: "github.com", | ||
owner: components[1], | ||
name: components[2], | ||
}, | ||
}), | ||
); | ||
}); | ||
}; | ||
} |
58 changes: 58 additions & 0 deletions
58
enclave-manager/web/src/client/packageIndexer/KurtosisPackageIndexerClientContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useToast } from "@chakra-ui/react"; | ||
import { createContext, PropsWithChildren, useContext, useMemo } from "react"; | ||
import { assertDefined } from "../../utils"; | ||
import { KurtosisPackageIndexerClient } from "./KurtosisPackageIndexerClient"; | ||
|
||
type KurtosisPackageIndexerClientContextState = { | ||
client: KurtosisPackageIndexerClient | null; | ||
}; | ||
|
||
const KurtosisPackageIndexerClientContext = createContext<KurtosisPackageIndexerClientContextState>({ client: null }); | ||
|
||
export const KurtosisPackageIndexerProvider = ({ children }: PropsWithChildren) => { | ||
const toast = useToast(); | ||
|
||
const errorHandlingClient = useMemo(() => { | ||
return new Proxy(new KurtosisPackageIndexerClient(), { | ||
get(target, prop: string | symbol) { | ||
if (prop === "getPackages" || prop === "readPackage") { | ||
return new Proxy(target[prop], { | ||
apply: (target, thisArg, argumentsList) => { | ||
const methodResult = Reflect.apply(target, thisArg, argumentsList) as ReturnType<typeof target>; | ||
return methodResult.then((r) => { | ||
if (r.isErr) { | ||
toast({ | ||
title: "Error", | ||
description: r.error.message, | ||
status: "error", | ||
variant: "solid", | ||
}); | ||
} | ||
return r; | ||
}); | ||
}, | ||
}); | ||
} else { | ||
return Reflect.get(target, prop); | ||
} | ||
}, | ||
}); | ||
}, [toast]); | ||
|
||
return ( | ||
<KurtosisPackageIndexerClientContext.Provider value={{ client: errorHandlingClient }}> | ||
{children} | ||
</KurtosisPackageIndexerClientContext.Provider> | ||
); | ||
}; | ||
|
||
export const useKurtosisPackageIndexerClient = (): KurtosisPackageIndexerClient => { | ||
const { client } = useContext(KurtosisPackageIndexerClientContext); | ||
|
||
assertDefined( | ||
client, | ||
`useKurtosisPackageIndexerClient used incorrectly - KurtosisPackageIndexerClient is not currently available.`, | ||
); | ||
|
||
return client; | ||
}; |
52 changes: 52 additions & 0 deletions
52
enclave-manager/web/src/client/packageIndexer/api/kurtosis_package_indexer_connect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @generated by protoc-gen-connect-es v0.13.2 with parameter "target=ts" | ||
// @generated from file kurtosis_package_indexer.proto (package kurtosis_package_indexer, syntax proto3) | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
|
||
import { Empty, MethodKind } from "@bufbuild/protobuf"; | ||
import { GetPackagesResponse, ReadPackageRequest, ReadPackageResponse } from "./kurtosis_package_indexer_pb"; | ||
|
||
/** | ||
* @generated from service kurtosis_package_indexer.KurtosisPackageIndexer | ||
*/ | ||
export const KurtosisPackageIndexer = { | ||
typeName: "kurtosis_package_indexer.KurtosisPackageIndexer", | ||
methods: { | ||
/** | ||
* @generated from rpc kurtosis_package_indexer.KurtosisPackageIndexer.IsAvailable | ||
*/ | ||
isAvailable: { | ||
name: "IsAvailable", | ||
I: Empty, | ||
O: Empty, | ||
kind: MethodKind.Unary, | ||
}, | ||
/** | ||
* @generated from rpc kurtosis_package_indexer.KurtosisPackageIndexer.GetPackages | ||
*/ | ||
getPackages: { | ||
name: "GetPackages", | ||
I: Empty, | ||
O: GetPackagesResponse, | ||
kind: MethodKind.Unary, | ||
}, | ||
/** | ||
* @generated from rpc kurtosis_package_indexer.KurtosisPackageIndexer.Reindex | ||
*/ | ||
reindex: { | ||
name: "Reindex", | ||
I: Empty, | ||
O: Empty, | ||
kind: MethodKind.Unary, | ||
}, | ||
/** | ||
* @generated from rpc kurtosis_package_indexer.KurtosisPackageIndexer.ReadPackage | ||
*/ | ||
readPackage: { | ||
name: "ReadPackage", | ||
I: ReadPackageRequest, | ||
O: ReadPackageResponse, | ||
kind: MethodKind.Unary, | ||
}, | ||
}, | ||
} as const; |
Oops, something went wrong.