Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const AuthMode = ({ collection }) => {
label: 'API Key',
onClick: () => onModeChange('apikey')
},
{
id: 'edgegrid',
label: 'Akamai EdgeGrid',
onClick: () => onModeChange('edgegrid')
},
{
id: 'none',
label: 'No Auth',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import styled from 'styled-components';
import { rgba } from 'polished';

const StyledWrapper = styled.div`
label {
display: flex;
align-items: center;
font-size: ${(props) => props.theme.font.size.sm};
font-weight: 500;
color: ${(props) => props.theme.colors.text.subtext1};
margin-bottom: 0.5rem;
}

.single-line-editor-wrapper {
display: flex;
align-items: center;
max-width: 400px;
margin-bottom: 0.5rem;
padding: 0.15rem 0.4rem;
border-radius: 3px;
border: solid 1px ${(props) => props.theme.input.border};
background-color: ${(props) => props.theme.input.bg};

&:focus-within {
border: solid 1px ${(props) => props.theme.input.focusBorder} !important;
}
}

.advanced-settings-header {
display: flex;
align-items: center;
gap: 10px;
width: fit-content;
margin: 1rem 0 0.75rem;
font-size: ${(props) => props.theme.font.size.sm};
font-weight: 600;
color: ${(props) => props.theme.colors.text.subtext1};
user-select: none;

.advanced-settings-icon {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.375rem 0.625rem;
border-radius: 0.375rem;
background-color: ${(props) => rgba(props.theme.primary.solid, 0.1)};
Comment thread
sid-bruno marked this conversation as resolved.
Resolved

svg {
color: ${(props) => props.theme.primary.text};
}
}
}

.advanced-settings-hint {
margin: -0.25rem 0 0.75rem;
font-size: ${(props) => props.theme.font.size.sm};
color: rgb(107 114 128);
}

.field-info {
position: relative;
display: inline-flex;
align-items: center;
margin-left: 6px;
cursor: pointer;

svg {
color: rgb(107 114 128);
}

.field-tooltip {
position: absolute;
left: 0;
bottom: 100%;
z-index: 10;
width: max-content;
max-width: 15rem;
margin-bottom: 0.25rem;
padding: 0.5rem;
border-radius: 0.375rem;
background-color: #374151;
color: #fff;
font-size: 0.75rem;
Comment thread
sid-bruno marked this conversation as resolved.
Resolved
line-height: 1rem;
font-weight: 400;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}

&:hover .field-tooltip {
opacity: 1;
}
}
`;

export default StyledWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { IconAdjustmentsHorizontal, IconInfoCircle } from '@tabler/icons';
import get from 'lodash/get';
import React from 'react';
import { useDispatch } from 'react-redux';

import SensitiveFieldWarning from 'components/SensitiveFieldWarning';
import SingleLineEditor from 'components/SingleLineEditor';
import { useDetectSensitiveField } from 'hooks/useDetectSensitiveField';
import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections';
import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions';
import { useTheme } from 'providers/Theme';
import StyledWrapper from './StyledWrapper';

interface EdgeGridAuthValues {
accessToken?: string;
clientToken?: string;
clientSecret?: string;
nonce?: string;
timestamp?: string;
baseURL?: string;
headersToSign?: string;
maxBodySize?: string;
}

type EdgeGridField = keyof EdgeGridAuthValues;

interface EdgeGridAuthProps {
collection: any;
}

const FIELDS: Array<{ key: EdgeGridField; label: string; tooltip?: string; isSecret?: boolean }> = [
{ key: 'accessToken', label: 'Access Token' },
{ key: 'clientToken', label: 'Client Token' },
{ key: 'clientSecret', label: 'Client Secret', isSecret: true },
{ key: 'baseURL', label: 'Base URL', tooltip: 'Defaults to the request URL if not specified.' },
{
key: 'nonce',
label: 'Nonce',
tooltip: 'A unique nonce is required per request. Defaults to an auto-generated UUID v4 if not provided.'
},
{
key: 'timestamp',
label: 'Timestamp',
tooltip:
'UTC timestamp of when the request is signed (yyyyMMddTHH:mm:ss+0000). Defaults to current time if not provided.'
},
{
key: 'headersToSign',
label: 'Headers to Sign',
tooltip: 'Comma-separated list of headers to include in the signature.'
},
{
key: 'maxBodySize',
label: 'Max Body Size',
tooltip: 'Maximum message body size to include in the signature, in bytes. Defaults to 131072.'
}
];

type EdgeGridFieldConfig = (typeof FIELDS)[number];

// Fields shown up front vs. those grouped under the "Advanced Settings" section
const BASIC_FIELDS = FIELDS.slice(0, 3);
const ADVANCED_FIELDS = FIELDS.slice(3);

const EdgeGridAuth: React.FC<EdgeGridAuthProps> = ({ collection }) => {
const dispatch = useDispatch();
const { storedTheme } = useTheme();

const edgeGridAuth: EdgeGridAuthValues =
(collection.draft?.root
? get(collection, 'draft.root.request.auth.edgegrid')
: get(collection, 'root.request.auth.edgegrid')) || {};
const { isSensitive } = useDetectSensitiveField(collection);
const { showWarning: showClientSecretWarning, warningMessage: clientSecretWarningMessage } = isSensitive(
edgeGridAuth?.clientSecret
);

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

const handleFieldChange = (field: EdgeGridField, value: string) => {
dispatch(
updateCollectionAuth({
mode: 'edgegrid',
collectionUid: collection.uid,
content: {
accessToken: edgeGridAuth.accessToken || '',
clientToken: edgeGridAuth.clientToken || '',
clientSecret: edgeGridAuth.clientSecret || '',
nonce: edgeGridAuth.nonce || '',
timestamp: edgeGridAuth.timestamp || '',
baseURL: edgeGridAuth.baseURL || '',
headersToSign: edgeGridAuth.headersToSign || '',
maxBodySize: edgeGridAuth.maxBodySize || '',
[field]: value || ''
}
})
);
};

const renderField = ({ key, label, tooltip, isSecret }: EdgeGridFieldConfig) => {
const showWarning = isSecret && showClientSecretWarning;
return (
<div key={key}>
<label>
{label}
{tooltip && (
<span className="field-info">
<IconInfoCircle size={16} />
<span className="field-tooltip">{tooltip}</span>
</span>
)}
</label>
<div className="single-line-editor-wrapper">
<SingleLineEditor
value={edgeGridAuth[key] || ''}
theme={storedTheme}
onSave={handleSave}
onChange={(val: string) => handleFieldChange(key, val)}
collection={collection}
isSecret={isSecret}
isCompact
/>
{showWarning && (
<SensitiveFieldWarning fieldName="edgegrid-client-secret" warningMessage={clientSecretWarningMessage} />
)}
</div>
</div>
);
};

return (
<StyledWrapper className="mt-2 w-full">
{BASIC_FIELDS.map(renderField)}

<div className="advanced-settings-header">
<span className="advanced-settings-icon">
<IconAdjustmentsHorizontal size={16} />
</span>
<span>Advanced Settings</span>
</div>

<>
{ADVANCED_FIELDS.map(renderField)}
</>

</StyledWrapper>
);
};

export default EdgeGridAuth;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BasicAuth from './BasicAuth';
import DigestAuth from './DigestAuth';
import WsseAuth from './WsseAuth';
import ApiKeyAuth from './ApiKeyAuth/';
import EdgeGridAuth from './EdgeGridAuth';
import { saveCollectionSettings } from 'providers/ReduxStore/slices/collections/actions';
import StyledWrapper from './StyledWrapper';
import OAuth2 from './OAuth2';
Expand Down Expand Up @@ -50,6 +51,9 @@ const Auth = ({ collection }) => {
case 'apikey': {
return <ApiKeyAuth collection={collection} />;
}
case 'edgegrid': {
return <EdgeGridAuth collection={collection} />;
}
}
};

Expand Down
14 changes: 14 additions & 0 deletions packages/bruno-app/src/components/FolderSettings/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import OAuth1 from 'components/RequestPane/Auth/OAuth1';
import WsseAuth from 'components/RequestPane/Auth/WsseAuth';
import ApiKeyAuth from 'components/RequestPane/Auth/ApiKeyAuth';
import AwsV4Auth from 'components/RequestPane/Auth/AwsV4Auth';
import EdgeGridAuth from 'components/RequestPane/Auth/EdgeGridAuth';
import { humanizeRequestAuthMode, getTreePathFromCollectionToItem } from 'utils/collections/index';
import Button from 'ui/Button';

Expand Down Expand Up @@ -212,6 +213,19 @@ const Auth = ({ collection, folder }) => {
</>
);
}
case 'edgegrid': {
return (
<>
<EdgeGridAuth
collection={collection}
item={folder}
updateAuth={updateFolderAuth}
request={request}
save={() => handleSave()}
/>
</>
);
}
case 'none': {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const AuthMode = ({ collection, folder }) => {
label: 'API Key',
onClick: () => onModeChange('apikey')
},
{
id: 'edgegrid',
label: 'Akamai EdgeGrid',
onClick: () => onModeChange('edgegrid')
},
{
id: 'inherit',
label: 'Inherit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const AuthMode = ({ item, collection }) => {
label: 'API Key',
onClick: () => onModeChange('apikey')
},
{
id: 'edgegrid',
label: 'Akamai EdgeGrid',
onClick: () => onModeChange('edgegrid')
},
{
id: 'inherit',
label: 'Inherit',
Expand Down
Loading