Skip to content
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

78113 allow regenerate deploy key and secret (#272) #274

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 71 additions & 11 deletions src/components/configure-application-github/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import Button from '../button';
import Code from '../code';
Expand All @@ -14,21 +14,34 @@ import configHandler from '../../utils/config';

import './style.css';
import externalUrls from '../../externalUrls';
import requestStates from '../../state/state-utils/request-states';
import Spinner from '../spinner';
import Alert from '../alert';
import useRegenerateDeployKeyAndSecret from '../page-configuration/use-regenerate-deploy-key-and-secret';

const imageDeployKey = require('./deploy-key02.png').default;
const imageWebhook = require('./webhook02.png').default;

const radixZoneDNS = configHandler.getConfig(configKeys.RADIX_CLUSTER_BASE);
const webhookURL = `https://webhook.${radixZoneDNS}/events/github`;

export const ConfigureApplicationGithub = ({
app,
startVisible,
deployKeyTitle,
webhookTitle,
useOtherCiToolOptionVisible,
}) => {
export const ConfigureApplicationGithub = (props) => {
const {
app,
startVisible,
deployKeyTitle,
webhookTitle,
useOtherCiToolOptionVisible,
onDeployKeyChange,
} = props;
const [useOtherCiTool, setUseOtherCiTool] = useState(false);
const [deployKey, setDeployKey] = useState(app.publicKey);
const [sharedSecret, setSharedSecret] = useState(app.sharedSecret);
const [savedDeployKey, setSavedDeployKey] = useState(deployKey);
const [savedSharedSecret, setSavedSharedSecret] = useState(sharedSecret);
const [saveState, saveFunc, resetSaveState] = useRegenerateDeployKeyAndSecret(
app.name
);
const deployOnlyHelp = (
<span>
Select this option if your project is hosted on multiple repositories
Expand All @@ -47,6 +60,28 @@ export const ConfigureApplicationGithub = ({
</span>
);

useEffect(() => {
setDeployKey(savedDeployKey);
}, [savedDeployKey]);

useEffect(() => {
setSharedSecret(savedSharedSecret);
}, [savedSharedSecret]);

useEffect(() => {
if (saveState.status !== requestStates.SUCCESS) {
return;
}
setSavedDeployKey(saveState.data.publicDeployKey);
setSavedSharedSecret(saveState.data.sharedSecret);
resetSaveState();
onDeployKeyChange(app.name);
}, [saveState, resetSaveState, onDeployKeyChange]);

const saveDeployKeySetting = () => {
saveFunc();
};

return (
<div className="configure-application-github">
<p>To integrate with GitHub you must add a deploy key and a webhook</p>
Expand Down Expand Up @@ -74,12 +109,37 @@ export const ConfigureApplicationGithub = ({
<li>
Copy and paste this key:
<Code copy wrap>
{app.publicKey}
{deployKey}
</Code>
</li>
<li>Press "Add key"</li>
</ol>
</div>
<div className="o-body-text">
<div className="o-action-bar">
{saveState.status === requestStates.IN_PROGRESS && (
<Spinner>Regenerating…</Spinner>
)}
{saveState.status === requestStates.FAILURE && (
<Alert type="danger">
Failed to regenerate deploy key and webhook secret.
{saveState.error}
</Alert>
)}
{
<Button
onClick={() => saveDeployKeySetting()}
btnType="danger"
disabled={
savedDeployKey !== deployKey ||
saveState.status === requestStates.IN_PROGRESS
}
>
Regenerate deploy key and webhook secret
</Button>
}
</div>
</div>
</Toggler>
</Panel>
<Panel>
Expand Down Expand Up @@ -135,9 +195,9 @@ export const ConfigureApplicationGithub = ({
</li>
<li>
The Shared Secret for this application is{' '}
<code>{app.sharedSecret}</code>{' '}
<code>{sharedSecret}</code>{' '}
<Button
onClick={() => copyToClipboard(app.sharedSecret)}
onClick={() => copyToClipboard(sharedSecret)}
btnType={['default', 'tiny']}
>
Copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const ChangeMachineUserForm = (props) => {
props.appName
);

useEffect(() => setMachineUser(props.machineUser), [props.machineUser]);
useEffect(() => {
setMachineUser(props.machineUser);
}, [props.machineUser]);

useEffect(() => {
if (saveState.status === requestStates.SUCCESS) {
Expand Down
1 change: 1 addition & 0 deletions src/components/page-configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PageConfiguration extends React.Component {
startCollapsed
deployKeyTitle="Deploy key"
webhookTitle="Webhook"
onDeployKeyChange={refreshApp}
/>
</section>
<section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { usePostJson } from '../../effects';
var phraseit = require('phraseit');

const useRegenerateDeployKeyAndSecret = (appName) => {
const path = `/applications/${appName}/regenerate-deploy-key`;
var sharedSecret = phraseit.make('{{an_adjective}} {{adjective}} {{noun}}');
return usePostJson(path, () => {
return {
sharedSecret: sharedSecret,
};
});
};

export default useRegenerateDeployKeyAndSecret;