Skip to content
Merged
1 change: 1 addition & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ interface AkamaiEdgeGridAuthValues {
accessToken?: string;
Comment thread
shubh-bruno marked this conversation as resolved.
Resolved
clientToken?: string;
clientSecret?: string;
nonce?: string;
timestamp?: string;
baseURL?: string;
headersToSign?: string;
baseURL?: string | null;
nonce?: string | null;
timestamp?: string | null;
headersToSign?: string | null;
maxBodySize?: number | null;
}

Expand All @@ -35,8 +35,8 @@ interface AkamaiEdgeGridAuthProps {
}

const FIELDS: Array<{ key: EdgeGridField; label: string; tooltip?: string; isSecret?: boolean }> = [
{ key: 'accessToken', label: 'Access Token' },
{ key: 'clientToken', label: 'Client Token' },
{ key: 'accessToken', label: 'Access Token', isSecret: true },
{ key: 'clientToken', label: 'Client Token', isSecret: true },
{ key: 'clientSecret', label: 'Client Secret', isSecret: true },
{ key: 'baseURL', label: 'Base URL', tooltip: 'Defaults to the request URL if not specified.' },
{
Expand Down Expand Up @@ -77,9 +77,6 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ collection }) => {
? get(collection, 'draft.root.request.auth.akamaiEdgegrid')
: get(collection, 'root.request.auth.akamaiEdgegrid')) || {};
const { isSensitive } = useDetectSensitiveField(collection);
const { showWarning: showClientSecretWarning, warningMessage: clientSecretWarningMessage } = isSensitive(
edgeGridAuth?.clientSecret
);

const handleSave = () => dispatch(saveCollectionRoot(collection.uid));

Expand Down Expand Up @@ -111,9 +108,9 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ collection }) => {
};

const renderField = ({ key, label, tooltip, isSecret }: EdgeGridFieldConfig) => {
const showWarning = isSecret && showClientSecretWarning;
const rawValue = edgeGridAuth[key];
const fieldValue = rawValue === null || rawValue === undefined ? '' : String(rawValue);
const { showWarning, warningMessage } = isSecret ? isSensitive(rawValue) : { showWarning: false, warningMessage: '' };
return (
<div key={key}>
<label>
Expand All @@ -136,7 +133,7 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ collection }) => {
isCompact
/>
{showWarning && (
<SensitiveFieldWarning fieldName="edgegrid-client-secret" warningMessage={clientSecretWarningMessage} />
<SensitiveFieldWarning fieldName={`edgegrid-${key}`} warningMessage={warningMessage} />
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ const EnvVarValueCell = ({
) : null}
editor={(
<div
className="relative flex flex-col"
className="flex items-center"
onFocus={() => handleRowFocus(variable.uid)}
>
{renderExtraValueContent && renderExtraValueContent(variable)}
<MultiLineEditor
ref={editorRef}
theme={storedTheme}
Expand Down Expand Up @@ -120,7 +121,6 @@ const EnvVarValueCell = ({
}}
onSave={handleSave}
/>
{renderExtraValueContent && renderExtraValueContent(variable)}
</div>
)}
renderTypeSelector={!isLastEmptyRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const sensitiveFields = [
'request.auth.wsse.password',
'request.auth.ntlm.password',
'request.auth.awsv4.secretAccessKey',
'request.auth.bearer.token'
'request.auth.bearer.token',
'request.auth.akamaiEdgegrid.accessToken',
'request.auth.akamaiEdgegrid.clientToken',
'request.auth.akamaiEdgegrid.clientSecret'
];

export { sensitiveFields };
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ interface AkamaiEdgeGridAuthValues {
accessToken?: string;
clientToken?: string;
clientSecret?: string;
nonce?: string;
timestamp?: string;
baseURL?: string;
headersToSign?: string;
baseURL?: string | null;
nonce?: string | null;
timestamp?: string | null;
headersToSign?: string | null;
maxBodySize?: number | null;
}

Expand All @@ -39,8 +39,8 @@ interface AkamaiEdgeGridAuthProps {
}

const FIELDS: Array<{ key: EdgeGridField; label: string; tooltip?: string; isSecret?: boolean }> = [
{ key: 'accessToken', label: 'Access Token' },
{ key: 'clientToken', label: 'Client Token' },
{ key: 'accessToken', label: 'Access Token', isSecret: true },
{ key: 'clientToken', label: 'Client Token', isSecret: true },
{ key: 'clientSecret', label: 'Client Secret', isSecret: true },
{ key: 'baseURL', label: 'Base URL', tooltip: 'Defaults to the request URL if not specified.' },
{
Expand Down Expand Up @@ -79,9 +79,6 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ item, collection, upd
const edgeGridAuth: AkamaiEdgeGridAuthValues = get(request, 'auth.akamaiEdgegrid') || {};
const requestUrl = get(request, 'url', '');
const { isSensitive } = useDetectSensitiveField(collection);
const { showWarning: showClientSecretWarning, warningMessage: clientSecretWarningMessage } = isSensitive(
edgeGridAuth?.clientSecret
);

const handleRun = () => dispatch(sendRequest(item, collection.uid));

Expand Down Expand Up @@ -118,9 +115,9 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ item, collection, upd
};

const renderField = ({ key, label, tooltip, isSecret }: EdgeGridFieldConfig) => {
const showWarning = isSecret && showClientSecretWarning;
const rawValue = key === 'baseURL' ? edgeGridAuth.baseURL || requestUrl : edgeGridAuth[key];
const fieldValue = rawValue === null || rawValue === undefined ? '' : String(rawValue);
const { showWarning, warningMessage } = isSecret ? isSensitive(rawValue) : { showWarning: false, warningMessage: '' };
return (
<div key={key}>
<label>
Expand All @@ -145,7 +142,7 @@ const EdgeGridAuth: React.FC<AkamaiEdgeGridAuthProps> = ({ item, collection, upd
isCompact
/>
{showWarning && (
<SensitiveFieldWarning fieldName="edgegrid-client-secret" warningMessage={clientSecretWarningMessage} />
<SensitiveFieldWarning fieldName={`edgegrid-${key}`} warningMessage={warningMessage} />
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const SensitiveFieldWarning = ({ fieldName, warningMessage }) => {

return (
<StyledWrapper>
<span className="ml-2 flex items-center">
<IconAlertTriangle id={tooltipId} className="tooltip-icon cursor-pointer" size={20} />
<span className="m-[4px] flex items-center">
Comment thread
shubh-bruno marked this conversation as resolved.
Resolved
<IconAlertTriangle id={tooltipId} className="tooltip-icon cursor-pointer" size={16} />
<Tooltip
anchorId={tooltipId}
className="tooltip-mod max-w-lg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import toast from 'react-hot-toast';
import { IconCopy } from '@tabler/icons';
import { findCollectionByItemUid, getGlobalEnvironmentVariables } from 'utils/collections/index';
import { cloneDeep } from 'lodash';
import { useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { generateSnippet } from '../utils/snippet-generator';
const CodeView = ({ language, item }) => {
const { displayedTheme } = useTheme();
Expand All @@ -31,13 +31,22 @@ const CodeView = ({ language, item }) => {
return c;
}, [collectionOriginal, globalEnvironments, activeGlobalEnvironmentUid]);

const snippet = useMemo(() => {
return generateSnippet({
// generateSnippet is async (EdgeGrid signs via Web Crypto), so the snippet is produced in an
// effect; the cancelled flag drops results from a superseded render.
const [snippet, setSnippet] = useState('');
useEffect(() => {
let cancelled = false;
generateSnippet({
language,
item,
collection,
shouldInterpolate: generateCodePrefs.shouldInterpolate
}).then((result) => {
if (!cancelled) setSnippet(result);
});
return () => {
cancelled = true;
};
}, [language, item, collection, generateCodePrefs.shouldInterpolate]);
Comment thread
sid-bruno marked this conversation as resolved.
Resolved

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const addCurlAuthFlags = (curlCommand, auth) => {
return curlCommand;
};

const generateSnippet = ({ language, item, collection, shouldInterpolate = false }) => {
const generateSnippet = async ({ language, item, collection, shouldInterpolate = false }) => {
try {
// Get HTTPSnippet dynamically so mocks can be applied in tests
const { HTTPSnippet } = require('httpsnippet');
Expand All @@ -51,7 +51,7 @@ const generateSnippet = ({ language, item, collection, shouldInterpolate = false
const settings = item.draft ? get(item, 'draft.settings') : get(item, 'settings');

const sourceUrl = item.rawUrl || request.url;
const { har, rawUrl, encodedUrl, unhash } = buildHar({
const { har, rawUrl, encodedUrl, unhash } = await buildHar({
request: {
method: request.method,
url: sourceUrl,
Expand Down
Loading
Loading