Skip to content

Commit

Permalink
Merge pull request #72 from newrelic/ruairi/gh-token-fix
Browse files Browse the repository at this point in the history
fix: changed ability to see other users GitHub PAT
  • Loading branch information
rudouglas authored May 18, 2021
2 parents 9be345d + 25e0f16 commit 42112ef
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 4 deletions.
2 changes: 2 additions & 0 deletions nerdlets/github-about/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default class GithubAbout extends React.PureComponent {
}

async _deleteUserToken() {
await this._deleteGithubUrl();
const mutation = {
actionType: UserSecretsMutation.ACTION_TYPE.DELETE_SECRET,
name: 'GH_TOKEN'
Expand All @@ -237,6 +238,7 @@ export default class GithubAbout extends React.PureComponent {

async _setRepo(repoUrl) {
repoUrl = formatGithubUrl(repoUrl);
await this._deleteUserToken();
const { entityGuid } = this.props.nerdletUrlState;
const mutation = {
actionType: EntityStorageMutation.ACTION_TYPE.WRITE_DOCUMENT,
Expand Down
33 changes: 31 additions & 2 deletions nerdlets/github-about/setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/* eslint-disable react/no-did-update-set-state */
import React from 'react';
import PropTypes from 'prop-types';
import { TextField, Button, Stack, StackItem, Grid, GridItem } from 'nr1';
import {
TextField,
Button,
Stack,
StackItem,
Grid,
GridItem,
Tooltip,
Badge,
Icon
} from 'nr1';
import isUrl from 'is-url';

const PUBLIC_GITHUB_API = 'https://api.github.com';
Expand Down Expand Up @@ -55,7 +65,12 @@ export default class Setup extends React.PureComponent {

handleSetGithubUrl() {
const { githubUrl } = this.state;
const { setGithubUrl, setActiveTab } = this.props;
const {
setGithubUrl,
setActiveTab,
deleteUserToken,
userToken
} = this.props;
if (githubUrl === '') {
return;
}
Expand All @@ -64,6 +79,10 @@ export default class Setup extends React.PureComponent {
this.setState({ isValidUrl: false });
return;
}
if (userToken) {
deleteUserToken();
return;
}
this.setState({
isValidUrl: true
});
Expand Down Expand Up @@ -239,6 +258,16 @@ export default class Setup extends React.PureComponent {
)}
</StackItem>
<StackItem>
<Tooltip
text="Setting this will delete any Personal Access Token stored for this Entity for Security purposes"
placementType={Tooltip.PLACEMENT_TYPE.BOTTOM}
>
<Badge type={Badge.TYPE.CRITICAL}>
<Icon
type={Icon.TYPE.INTERFACE__SIGN__EXCLAMATION__V_ALTERNATE}
/>
</Badge>
</Tooltip>
<Button
onClick={this.handleSetGithubUrl}
disabled={!isGithubEnterprise || !githubUrl}
Expand Down
179 changes: 177 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42112ef

Please sign in to comment.