diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/AuthMode/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/AuthMode/index.js index 2e0abe572..5cf3a5f7a 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Auth/AuthMode/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/AuthMode/index.js @@ -34,6 +34,15 @@ const AuthMode = ({ collection }) => {
} placement="bottom-end"> +
{ + dropdownTippyRef.current.hide(); + onModeChange('awsv4'); + }} + > + AWS Sig v4 +
{ diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/StyledWrapper.js b/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/StyledWrapper.js new file mode 100644 index 000000000..c2bb5d207 --- /dev/null +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/StyledWrapper.js @@ -0,0 +1,16 @@ +import styled from 'styled-components'; + +const Wrapper = styled.div` + label { + font-size: 0.8125rem; + } + + .single-line-editor-wrapper { + padding: 0.15rem 0.4rem; + border-radius: 3px; + border: solid 1px ${(props) => props.theme.input.border}; + background-color: ${(props) => props.theme.input.bg}; + } +`; + +export default Wrapper; diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/index.js new file mode 100644 index 000000000..1fe35eea0 --- /dev/null +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/AwsV4Auth/index.js @@ -0,0 +1,192 @@ +import React from 'react'; +import get from 'lodash/get'; +import { useTheme } from 'providers/Theme'; +import { useDispatch } from 'react-redux'; +import SingleLineEditor from 'components/SingleLineEditor'; +import { updateCollectionAuth } from 'providers/ReduxStore/slices/collections'; +import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions'; +import StyledWrapper from './StyledWrapper'; + +const AwsV4Auth = ({ collection }) => { + const dispatch = useDispatch(); + const { storedTheme } = useTheme(); + + const awsv4Auth = get(collection, 'root.request.auth.awsv4', {}); + console.log('saved auth', awsv4Auth); + + const handleSave = () => dispatch(saveCollectionRoot(collection.uid)); + + const handleAccessKeyIdChange = (accessKeyId) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: accessKeyId, + secretAccessKey: awsv4Auth.secretAccessKey, + sessionToken: awsv4Auth.sessionToken, + service: awsv4Auth.service, + region: awsv4Auth.region, + profileName: awsv4Auth.profileName + } + }) + ); + }; + + const handleSecretAccessKeyChange = (secretAccessKey) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: awsv4Auth.accessKeyId, + secretAccessKey: secretAccessKey, + sessionToken: awsv4Auth.sessionToken, + service: awsv4Auth.service, + region: awsv4Auth.region, + profileName: awsv4Auth.profileName + } + }) + ); + }; + + const handleSessionTokenChange = (sessionToken) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: awsv4Auth.accessKeyId, + secretAccessKey: awsv4Auth.secretAccessKey, + sessionToken: sessionToken, + service: awsv4Auth.service, + region: awsv4Auth.region, + profileName: awsv4Auth.profileName + } + }) + ); + }; + + const handleServiceChange = (service) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: awsv4Auth.accessKeyId, + secretAccessKey: awsv4Auth.secretAccessKey, + sessionToken: awsv4Auth.sessionToken, + service: service, + region: awsv4Auth.region, + profileName: awsv4Auth.profileName + } + }) + ); + }; + + const handleRegionChange = (region) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: awsv4Auth.accessKeyId, + secretAccessKey: awsv4Auth.secretAccessKey, + sessionToken: awsv4Auth.sessionToken, + service: awsv4Auth.service, + region: region, + profileName: awsv4Auth.profileName + } + }) + ); + }; + + const handleProfileNameChange = (profileName) => { + dispatch( + updateCollectionAuth({ + mode: 'awsv4', + collectionUid: collection.uid, + content: { + accessKeyId: awsv4Auth.accessKeyId, + secretAccessKey: awsv4Auth.secretAccessKey, + sessionToken: awsv4Auth.sessionToken, + service: awsv4Auth.service, + region: awsv4Auth.region, + profileName: profileName + } + }) + ); + }; + + return ( + + +
+ handleAccessKeyIdChange(val)} + collection={collection} + /> +
+ + +
+ handleSecretAccessKeyChange(val)} + collection={collection} + /> +
+ + +
+ handleSessionTokenChange(val)} + collection={collection} + /> +
+ + +
+ handleServiceChange(val)} + collection={collection} + /> +
+ + +
+ handleRegionChange(val)} + collection={collection} + /> +
+ + +
+ handleProfileNameChange(val)} + collection={collection} + /> +
+
+ ); +}; + +export default AwsV4Auth; diff --git a/packages/bruno-app/src/components/CollectionSettings/Auth/index.js b/packages/bruno-app/src/components/CollectionSettings/Auth/index.js index fe2fd5b33..d9e80358b 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Auth/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Auth/index.js @@ -2,6 +2,7 @@ import React from 'react'; import get from 'lodash/get'; import { useDispatch } from 'react-redux'; import AuthMode from './AuthMode'; +import AwsV4Auth from './AwsV4Auth'; import BearerAuth from './BearerAuth'; import BasicAuth from './BasicAuth'; import { saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions'; @@ -15,6 +16,9 @@ const Auth = ({ collection }) => { const getAuthView = () => { switch (authMode) { + case 'awsv4': { + return ; + } case 'basic': { return ; } diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index f8595daa1..8140dcf72 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -969,6 +969,10 @@ export const collectionsSlice = createSlice({ if (collection) { switch (action.payload.mode) { + case 'awsv4': + set(collection, 'root.request.auth.awsv4', action.payload.content); + console.log('set auth awsv4', action.payload.content); + break; case 'bearer': set(collection, 'root.request.auth.bearer', action.payload.content); break; diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index f08536209..3beab80f7 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -8,15 +8,26 @@ const decomment = require('decomment'); const setAuthHeaders = (axiosRequest, request, collectionRoot) => { const collectionAuth = get(collectionRoot, 'request.auth'); if (collectionAuth) { - if (collectionAuth.mode === 'basic') { - axiosRequest.auth = { - username: get(collectionAuth, 'basic.username'), - password: get(collectionAuth, 'basic.password') - }; - } - - if (collectionAuth.mode === 'bearer') { - axiosRequest.headers['authorization'] = `Bearer ${get(collectionAuth, 'bearer.token')}`; + switch (collectionAuth.mode) { + case 'awsv4': + axiosRequest.awsv4config = { + accessKeyId: get(collectionAuth, 'awsv4.accessKeyId'), + secretAccessKey: get(collectionAuth, 'awsv4.secretAccessKey'), + sessionToken: get(collectionAuth, 'awsv4.sessionToken'), + service: get(collectionAuth, 'awsv4.service'), + region: get(collectionAuth, 'awsv4.region'), + profileName: get(collectionAuth, 'awsv4.profileName') + }; + break; + case 'basic': + axiosRequest.auth = { + username: get(collectionAuth, 'basic.username'), + password: get(collectionAuth, 'basic.password') + }; + break; + case 'bearer': + axiosRequest.headers['authorization'] = `Bearer ${get(collectionAuth, 'bearer.token')}`; + break; } } diff --git a/packages/bruno-lang/v2/src/collectionBruToJson.js b/packages/bruno-lang/v2/src/collectionBruToJson.js index d78f752c0..4569736f1 100644 --- a/packages/bruno-lang/v2/src/collectionBruToJson.js +++ b/packages/bruno-lang/v2/src/collectionBruToJson.js @@ -4,7 +4,7 @@ const { outdentString } = require('../../v1/src/utils'); const grammar = ohm.grammar(`Bru { BruFile = (meta | query | headers | auth | auths | vars | script | tests | docs)* - auths = authbasic | authbearer + auths = authawsv4 | authbasic | authbearer nl = "\\r"? "\\n" st = " " | "\\t" @@ -38,6 +38,7 @@ const grammar = ohm.grammar(`Bru { varsreq = "vars:pre-request" dictionary varsres = "vars:post-response" dictionary + authawsv4 = "auth:awsv4" dictionary authbasic = "auth:basic" dictionary authbearer = "auth:bearer" dictionary @@ -171,6 +172,33 @@ const sem = grammar.createSemantics().addAttribute('ast', { headers: mapPairListToKeyValPairs(dictionary.ast) }; }, + authawsv4(_1, dictionary) { + const auth = mapPairListToKeyValPairs(dictionary.ast, false); + const accessKeyIdKey = _.find(auth, { name: 'accessKeyId' }); + const secretAccessKeyKey = _.find(auth, { name: 'secretAccessKey' }); + const sessionTokenKey = _.find(auth, { name: 'sessionToken' }); + const serviceKey = _.find(auth, { name: 'service' }); + const regionKey = _.find(auth, { name: 'region' }); + const profileNameKey = _.find(auth, { name: 'profileName' }); + const accessKeyId = accessKeyIdKey ? accessKeyIdKey.value : ''; + const secretAccessKey = secretAccessKeyKey ? secretAccessKeyKey.value : ''; + const sessionToken = sessionTokenKey ? sessionTokenKey.value : ''; + const service = serviceKey ? serviceKey.value : ''; + const region = regionKey ? regionKey.value : ''; + const profileName = profileNameKey ? profileNameKey.value : ''; + return { + auth: { + awsv4: { + accessKeyId, + secretAccessKey, + sessionToken, + service, + region, + profileName + } + } + }; + }, authbasic(_1, dictionary) { const auth = mapPairListToKeyValPairs(dictionary.ast, false); const usernameKey = _.find(auth, { name: 'username' }); diff --git a/packages/bruno-lang/v2/src/jsonToCollectionBru.js b/packages/bruno-lang/v2/src/jsonToCollectionBru.js index 57a5ea7bf..ea928a68f 100644 --- a/packages/bruno-lang/v2/src/jsonToCollectionBru.js +++ b/packages/bruno-lang/v2/src/jsonToCollectionBru.js @@ -72,6 +72,19 @@ const jsonToCollectionBru = (json) => { ${indentString(`mode: ${auth.mode}`)} } +`; + } + + if (auth && auth.awsv4) { + bru += `auth:awsv4 { +${indentString(`accessKeyId: ${auth.awsv4.accessKeyId}`)} +${indentString(`secretAccessKey: ${auth.awsv4.secretAccessKey}`)} +${indentString(`sessionToken: ${auth.awsv4.sessionToken}`)} +${indentString(`service: ${auth.awsv4.service}`)} +${indentString(`region: ${auth.awsv4.region}`)} +${indentString(`profileName: ${auth.awsv4.profileName}`)} +} + `; }