@@ -322,9 +322,9 @@ spec:
|
||||
type: string
|
||||
ui:field: RepoUrlPicker
|
||||
ui:options:
|
||||
# here's the new option you can pass to the RepoUrlPicker
|
||||
# Here's the option you can pass to the RepoUrlPicker
|
||||
requestUserCredentials:
|
||||
resultSecretsKey: USER_OAUTH_TOKEN
|
||||
secretsKey: USER_OAUTH_TOKEN
|
||||
additionalScopes:
|
||||
github:
|
||||
- workflow:write
|
||||
|
||||
@@ -166,7 +166,7 @@ export interface RepoUrlPickerUiOptions {
|
||||
allowedOwners?: string[];
|
||||
// (undocumented)
|
||||
requestUserCredentials?: {
|
||||
resultSecretsKey: string;
|
||||
secretsKey: string;
|
||||
additionalScopes?: {
|
||||
github?: string[];
|
||||
gitlab?: string[];
|
||||
@@ -329,7 +329,7 @@ export const TextValuePicker: ({
|
||||
}: FieldProps<string>) => JSX.Element;
|
||||
|
||||
// @public
|
||||
export const useSecretsContext: () => {
|
||||
export const useTemplateSecrets: () => {
|
||||
setSecret: (input: Record<string, string>) => void;
|
||||
};
|
||||
```
|
||||
|
||||
@@ -134,7 +134,7 @@ describe('RepoUrlPicker', () => {
|
||||
'ui:field': 'RepoUrlPicker',
|
||||
'ui:options': {
|
||||
requestUserCredentials: {
|
||||
resultSecretsKey: 'testKey',
|
||||
secretsKey: 'testKey',
|
||||
additionalScopes: { github: ['workflow:write'] },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -28,13 +28,13 @@ import { RepoUrlPickerHost } from './RepoUrlPickerHost';
|
||||
import { parseRepoPickerUrl, serializeRepoPickerUrl } from './utils';
|
||||
import { RepoUrlPickerState } from './types';
|
||||
import useDebounce from 'react-use/lib/useDebounce';
|
||||
import { useSecretsContext } from '../../secrets';
|
||||
import { useTemplateSecrets } from '../../secrets';
|
||||
|
||||
export interface RepoUrlPickerUiOptions {
|
||||
allowedHosts?: string[];
|
||||
allowedOwners?: string[];
|
||||
requestUserCredentials?: {
|
||||
resultSecretsKey: string;
|
||||
secretsKey: string;
|
||||
additionalScopes?: {
|
||||
github?: string[];
|
||||
gitlab?: string[];
|
||||
@@ -53,7 +53,7 @@ export const RepoUrlPicker = (
|
||||
);
|
||||
const integrationApi = useApi(scmIntegrationsApiRef);
|
||||
const scmAuthApi = useApi(scmAuthApiRef);
|
||||
const { setSecret } = useSecretsContext();
|
||||
const { setSecret } = useTemplateSecrets();
|
||||
const allowedHosts = useMemo(
|
||||
() => uiSchema?.['ui:options']?.allowedHosts ?? [],
|
||||
[uiSchema],
|
||||
@@ -104,8 +104,8 @@ export const RepoUrlPicker = (
|
||||
});
|
||||
|
||||
// set the secret using the key provided in the the ui:options for use
|
||||
// in the templating the manifest with ${{ secrets[resultSecretsKey] }}
|
||||
setSecret({ [requestUserCredentials.resultSecretsKey]: token });
|
||||
// in the templating the manifest with ${{ secrets[secretsKey] }}
|
||||
setSecret({ [requestUserCredentials.secretsKey]: token });
|
||||
},
|
||||
500,
|
||||
[state, uiSchema],
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
import React, { useContext } from 'react';
|
||||
import {
|
||||
useSecretsContext,
|
||||
useTemplateSecrets,
|
||||
SecretsContextProvider,
|
||||
SecretsContext,
|
||||
} from './SecretsContext';
|
||||
@@ -25,7 +25,7 @@ describe('SecretsContext', () => {
|
||||
it('should allow the setting of secrets in the context', async () => {
|
||||
const { result } = renderHook(
|
||||
() => ({
|
||||
hook: useSecretsContext(),
|
||||
hook: useTemplateSecrets(),
|
||||
context: useContext(SecretsContext),
|
||||
}),
|
||||
{
|
||||
|
||||
@@ -52,11 +52,11 @@ export const SecretsContextProvider = ({ children }: PropsWithChildren<{}>) => {
|
||||
* Hook to access the secrets context.
|
||||
* @public
|
||||
*/
|
||||
export const useSecretsContext = () => {
|
||||
export const useTemplateSecrets = () => {
|
||||
const value = useContext(SecretsContext);
|
||||
if (!value) {
|
||||
throw new Error(
|
||||
'useSecretsContext must be used within a SecretsContextProvider',
|
||||
'useTemplateSecrets must be used within a SecretsContextProvider',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,4 +13,4 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { useSecretsContext } from './SecretsContext';
|
||||
export { useTemplateSecrets } from './SecretsContext';
|
||||
|
||||
Reference in New Issue
Block a user