-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add HCP Vault Secrets API docs #2050
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
5 commits
Select commit
Hold shift + click to select a range
0224b51
feat: add HCP Vault Secrets API docs
zchsh 2275f81
chore: allow empty serviceData.name for Vault Secrets
zchsh 0c5e64d
docs: add comment on path truncation
zchsh 955ae4b
style: use cleaner serviceData.name check
zchsh 3c8fbd5
Merge branch 'main' into zs.hcp-vault-secrets-api-docs
zchsh 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
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,121 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| // View | ||
| import ApiDocsView from 'views/api-docs-view' | ||
| import { | ||
| getApiDocsStaticProps, | ||
| getApiDocsStaticPaths, | ||
| ApiDocsParams, | ||
| } from 'views/api-docs-view/server' | ||
| import { buildApiDocsBreadcrumbs } from 'views/api-docs-view/server/get-api-docs-static-props/utils' | ||
| import { fetchCloudApiVersionData } from 'views/api-docs-view/utils' | ||
| // Components | ||
| import { | ||
| PathTruncationAside, | ||
| truncateVaultSecretsOperationPath, | ||
| } from 'views/api-docs-view/components' | ||
| // Types | ||
| import type { OperationObjectType } from 'components/open-api-page/types' | ||
| import type { ApiDocsViewProps } from 'views/api-docs-view/types' | ||
| import type { GetStaticPaths, GetStaticProps } from 'next' | ||
| import { isDeployPreview } from 'lib/env-checks' | ||
|
|
||
| /** | ||
| * The product slug is used to fetch product data for the layout. | ||
| */ | ||
| const PRODUCT_SLUG = 'hcp' | ||
|
|
||
| /** | ||
| * The baseUrl is used to generate | ||
| * breadcrumb links, sidebar nav levels, and version switcher links. | ||
| */ | ||
| const BASE_URL = '/hcp/api-docs/vault-secrets' | ||
|
|
||
| /** | ||
| * We source version data from a directory in the `hcp-specs` repo. | ||
| * See `fetchCloudApiVersionData` for details. | ||
| */ | ||
| const GITHUB_SOURCE_DIRECTORY = { | ||
| owner: 'hashicorp', | ||
| repo: 'hcp-specs', | ||
| path: 'specs/cloud-vault-secrets', | ||
| ref: 'main', | ||
| } | ||
|
|
||
| /** | ||
| * Render `<ApiDocsView />` with custom operation path truncation | ||
| * for HCP Vault secrets. | ||
| */ | ||
| function HcpVaultSecretsApiDocsView(props: ApiDocsViewProps) { | ||
| return ( | ||
| <ApiDocsView | ||
| {...props} | ||
| massagePathFn={truncateVaultSecretsOperationPath} | ||
| renderOperationIntro={({ data }: { data: OperationObjectType }) => ( | ||
| <PathTruncationAside path={data.__path} /> | ||
| )} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Get static paths, using `versionData` fetched from GitHub. | ||
| */ | ||
| export const getStaticPaths: GetStaticPaths<ApiDocsParams> = async () => { | ||
| // If we are in a deploy preview, don't pre-render any paths | ||
| if (isDeployPreview()) { | ||
| return { paths: [], fallback: 'blocking' } | ||
| } | ||
| // Otherwise, fetch version data, and use that to generate paths | ||
| const versionData = await fetchCloudApiVersionData(GITHUB_SOURCE_DIRECTORY) | ||
| return await getApiDocsStaticPaths({ productSlug: PRODUCT_SLUG, versionData }) | ||
| } | ||
|
|
||
| /** | ||
| * Get static props, using `versionData` fetched from GitHub. | ||
| * | ||
| * We need all version data for the version selector, | ||
| * and of course we need specific data for the current version. | ||
| */ | ||
| export const getStaticProps: GetStaticProps< | ||
| ApiDocsViewProps, | ||
| ApiDocsParams | ||
| > = async ({ params }: { params: ApiDocsParams }) => { | ||
| // Fetch all version data, based on remote `stable` & `preview` subfolders | ||
| const versionData = await fetchCloudApiVersionData(GITHUB_SOURCE_DIRECTORY) | ||
| // If we can't find any version data at all, render a 404 page. | ||
| if (!versionData) { | ||
| return { notFound: true } | ||
| } | ||
| // Return static props | ||
| const staticPropsResult = await getApiDocsStaticProps({ | ||
| productSlug: PRODUCT_SLUG, | ||
| baseUrl: BASE_URL, | ||
| pathParts: params.page, | ||
| versionData, | ||
| buildCustomBreadcrumbs: ({ productData, serviceData, versionId }) => { | ||
| return buildApiDocsBreadcrumbs({ | ||
| productData, | ||
| // HCP API docs at `/api-docs` are not linkable, so we pass url=null | ||
| apiDocs: { name: 'API', url: null }, | ||
| serviceData, | ||
| versionId, | ||
| }) | ||
| }, | ||
| }) | ||
| /** | ||
| * Shims specific to HCP Vault Secrets | ||
| */ | ||
| if (!('props' in staticPropsResult)) { | ||
| return staticPropsResult | ||
| } | ||
| // We shim in the removal of the service name, as it's redundant. | ||
| staticPropsResult.props.serviceData.name = '' | ||
| // Return the static props results with shimmed modifications | ||
| return staticPropsResult | ||
| } | ||
|
|
||
| export default HcpVaultSecretsApiDocsView |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
βοΈ Could we add a bit more clarity as to what the regex should match on in the comment?
Uh oh!
There was an error while loading. Please reload this page.
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.
π Great call! Added in a comment on this regex matching a standard prefix π