-
Notifications
You must be signed in to change notification settings - Fork 105
feat: add atlas-create-free-cluster atlas-inspect-cluster tools #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4efb5cf
feat: add atlas-create-free-cluster atlas-inspect-cluster tools
fmenezes 376b555
fix: styles
fmenezes 9097962
ci: check build
fmenezes a0eec19
fix: remove debug lines
fmenezes e22d4bd
refactor: generate in bash
fmenezes 5033797
fix: styles
fmenezes 10dd98b
fix: styles on generate
fmenezes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,56 @@ | ||
import { OpenAPIV3_1 } from "openapi-types"; | ||
|
||
async function readStdin() { | ||
return new Promise<string>((resolve, reject) => { | ||
let data = ""; | ||
process.stdin.setEncoding("utf8"); | ||
process.stdin.on("error", (err) => { | ||
reject(err); | ||
}); | ||
process.stdin.on("data", (chunk) => { | ||
data += chunk; | ||
}); | ||
process.stdin.on("end", () => { | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
|
||
function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document { | ||
const allowedOperations = [ | ||
"listProjects", | ||
"getProject", | ||
"createProject", | ||
"listClusters", | ||
"createCluster", | ||
"listClustersForAllProjects", | ||
]; | ||
|
||
const filteredPaths = {}; | ||
|
||
for (const path in openapi.paths) { | ||
const filteredMethods = {} as OpenAPIV3_1.PathItemObject; | ||
for (const method in openapi.paths[path]) { | ||
if (allowedOperations.includes(openapi.paths[path][method].operationId)) { | ||
filteredMethods[method] = openapi.paths[path][method]; | ||
} | ||
} | ||
if (Object.keys(filteredMethods).length > 0) { | ||
filteredPaths[path] = filteredMethods; | ||
} | ||
} | ||
|
||
return { ...openapi, paths: filteredPaths }; | ||
} | ||
|
||
async function main() { | ||
const openapiText = await readStdin(); | ||
const openapi = JSON.parse(openapiText) as OpenAPIV3_1.Document; | ||
const filteredOpenapi = filterOpenapi(openapi); | ||
console.log(JSON.stringify(filteredOpenapi)); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error("Error:", error); | ||
process.exit(1); | ||
}); |
This file contains hidden or 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,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeou pipefail | ||
|
||
curl -Lo ./scripts/spec.json https://github.com/mongodb/openapi/raw/refs/heads/main/openapi/v2/openapi-2025-03-12.json | ||
tsx ./scripts/filter.ts > ./scripts/filteredSpec.json < ./scripts/spec.json | ||
redocly bundle --ext json --remove-unused-components ./scripts/filteredSpec.json --output ./scripts/bundledSpec.json | ||
openapi-typescript ./scripts/bundledSpec.json --root-types-no-schema-prefix --root-types --output ./src/common/atlas/openapi.d.ts | ||
prettier --write ./src/common/atlas/openapi.d.ts | ||
rm -rf ./scripts/bundledSpec.json ./scripts/filteredSpec.json ./scripts/spec.json |
This file contains hidden or 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,32 @@ | ||
import { ApiClient } from "./client"; | ||
import { State } from "../../state"; | ||
|
||
export async function ensureAuthenticated(state: State, apiClient: ApiClient): Promise<void> { | ||
if (!(await isAuthenticated(state, apiClient))) { | ||
throw new Error("Not authenticated"); | ||
} | ||
} | ||
|
||
export async function isAuthenticated(state: State, apiClient: ApiClient): Promise<boolean> { | ||
switch (state.auth.status) { | ||
case "not_auth": | ||
return false; | ||
case "requested": | ||
try { | ||
if (!state.auth.code) { | ||
return false; | ||
} | ||
await apiClient.retrieveToken(state.auth.code.device_code); | ||
return !!state.auth.token; | ||
} catch { | ||
return false; | ||
} | ||
case "issued": | ||
if (!state.auth.token) { | ||
return false; | ||
} | ||
return await apiClient.validateToken(); | ||
default: | ||
throw new Error("Unknown authentication status"); | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nirinchev I'm adding build here, I've seen some weird bug where the source was not compiling but the styles were passing 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sounds good. I was thinking of adding a build step on CI anyway, but that's also fine. Our project builds fairly quickly still, so I'm not really worried about the extra couple of seconds it adds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be a follow-up PR- we should update our readme with the right commands to run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now
npm run check
should check everything