-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92d72db
commit d4aed5f
Showing
11 changed files
with
85 additions
and
132 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
import { PeerConfig } from '@/app/peers/create/configuration/types'; | ||
import { DBType, Peer, PostgresConfig } from '@/grpc_generated/peers'; | ||
import { | ||
CreatePeerRequest, | ||
CreatePeerResponse, | ||
CreatePeerStatus, | ||
ValidatePeerRequest, | ||
ValidatePeerResponse, | ||
ValidatePeerStatus, | ||
} from '@/grpc_generated/route'; | ||
import { GetFlowServiceClientFromEnv } from '@/rpc/rpc'; | ||
|
||
export const constructPeer = ( | ||
name: string, | ||
type: string, | ||
config: PeerConfig | ||
): Peer | undefined => { | ||
switch (type) { | ||
case 'POSTGRES': | ||
return { | ||
name, | ||
type: DBType.POSTGRES, | ||
postgresConfig: config as PostgresConfig, | ||
}; | ||
default: | ||
return; | ||
} | ||
}; | ||
|
||
export async function POST(request: Request) { | ||
const body = await request.json(); | ||
const { name, type, config, mode } = body; | ||
const flowServiceClient = GetFlowServiceClientFromEnv(); | ||
const peer = constructPeer(name, type, config); | ||
if (mode === 'validate') { | ||
const validateReq: ValidatePeerRequest = { peer }; | ||
const validateStatus: ValidatePeerResponse = | ||
await flowServiceClient.validatePeer(validateReq); | ||
if (validateStatus.status === ValidatePeerStatus.INVALID) { | ||
return new Response(validateStatus.message); | ||
} else if (validateStatus.status === ValidatePeerStatus.VALID) { | ||
return new Response('valid'); | ||
} | ||
} else if (mode === 'create') { | ||
const req: CreatePeerRequest = { peer }; | ||
const createStatus: CreatePeerResponse = | ||
await flowServiceClient.createPeer(req); | ||
if (createStatus.status === CreatePeerStatus.FAILED) { | ||
return new Response(createStatus.message); | ||
} else if (createStatus.status === CreatePeerStatus.CREATED) { | ||
return new Response('created'); | ||
} else return new Response('status of peer creation is unknown'); | ||
} else return new Response('mode of peer creation is unknown'); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import Joi from 'joi'; | ||
import * as z from 'zod'; | ||
import { PeerConfig } from './types'; | ||
|
||
export const pgSchema = Joi.object({ | ||
host: Joi.string().required(), | ||
port: Joi.number().integer().min(1).max(65535).required(), | ||
database: Joi.string().min(1).max(100).required(), | ||
user: Joi.string().alphanum().min(1).max(64).required(), | ||
password: Joi.string().min(1).max(100).required(), | ||
transactionSnapshot: Joi.string().max(100).allow('').optional(), | ||
const pgSchema = z.object({ | ||
host: z.string().nonempty().max(255), | ||
port: z.number().int().min(1).max(65535), | ||
database: z.string().min(1).max(100), | ||
user: z.string().min(1).max(64), | ||
password: z.string().min(1).max(100), | ||
transactionSnapshot: z.string().max(100).optional(), | ||
}); | ||
|
||
export const checkFormFields = (peerType: string, config: PeerConfig) => { | ||
switch (peerType) { | ||
case 'POSTGRES': | ||
return pgSchema.validate(config); | ||
return pgSchema.safeParse(config); | ||
default: | ||
return { error: { message: 'Peer type not recognized' } }; | ||
return { success: false, error: { message: 'Peer type not recognized' } }; | ||
} | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1410,18 +1410,6 @@ | |
protobufjs "^7.2.4" | ||
yargs "^17.7.2" | ||
|
||
"@hapi/hoek@^9.0.0": | ||
version "9.3.0" | ||
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb" | ||
integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ== | ||
|
||
"@hapi/topo@^5.0.0": | ||
version "5.1.0" | ||
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012" | ||
integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg== | ||
dependencies: | ||
"@hapi/hoek" "^9.0.0" | ||
|
||
"@headlessui/react@^1.7.14": | ||
version "1.7.17" | ||
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.7.17.tgz#a0ec23af21b527c030967245fd99776aa7352bc6" | ||
|
@@ -2189,23 +2177,6 @@ | |
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.3.3.tgz#16ab6c727d8c2020a5b6e4a176a243ecd88d8d69" | ||
integrity sha512-0xd7qez0AQ+MbHatZTlI1gu5vkG8r7MYRUJAHPAHJBmGLs16zpkrpAVLvjQKQOqaXPDUBwOiJzNc00znHSCVBw== | ||
|
||
"@sideway/address@^4.1.3": | ||
version "4.1.4" | ||
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0" | ||
integrity sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw== | ||
dependencies: | ||
"@hapi/hoek" "^9.0.0" | ||
|
||
"@sideway/formula@^3.0.1": | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.1.tgz#80fcbcbaf7ce031e0ef2dd29b1bfc7c3f583611f" | ||
integrity sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg== | ||
|
||
"@sideway/pinpoint@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df" | ||
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ== | ||
|
||
"@sinclair/typebox@^0.27.8": | ||
version "0.27.8" | ||
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" | ||
|
@@ -7325,17 +7296,6 @@ jiti@^1.18.2: | |
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.19.3.tgz#ef554f76465b3c2b222dc077834a71f0d4a37569" | ||
integrity sha512-5eEbBDQT/jF1xg6l36P+mWGGoH9Spuy0PCdSr2dtWRDGC6ph/w9ZCL4lmESW8f8F7MwT3XKescfP0wnZWAKL9w== | ||
|
||
joi@^17.10.2: | ||
version "17.10.2" | ||
resolved "https://registry.yarnpkg.com/joi/-/joi-17.10.2.tgz#4ecc348aa89ede0b48335aad172e0f5591e55b29" | ||
integrity sha512-hcVhjBxRNW/is3nNLdGLIjkgXetkeGc2wyhydhz8KumG23Aerk4HPjU5zaPAMRqXQFc0xNqXTC7+zQjxr0GlKA== | ||
dependencies: | ||
"@hapi/hoek" "^9.0.0" | ||
"@hapi/topo" "^5.0.0" | ||
"@sideway/address" "^4.1.3" | ||
"@sideway/formula" "^3.0.1" | ||
"@sideway/pinpoint" "^2.0.0" | ||
|
||
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" | ||
|
@@ -10797,3 +10757,8 @@ [email protected]: | |
version "3.21.4" | ||
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db" | ||
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw== | ||
|
||
zod@^3.22.2: | ||
version "3.22.2" | ||
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.2.tgz#3add8c682b7077c05ac6f979fea6998b573e157b" | ||
integrity sha512-wvWkphh5WQsJbVk1tbx1l1Ly4yg+XecD+Mq280uBGt9wa5BKSWf4Mhp6GmrkPixhMxmabYY7RbzlwVP32pbGCg== |