mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-18 21:28:35 +02:00
* feat/(#1003): oauth2 support - styling fixes, code cleanup (#1674) --------- Co-authored-by: lohit-1 <lohit@usebruno.com>
This commit is contained in:
@@ -9,7 +9,7 @@ const safeParseJson = (json) => {
|
||||
|
||||
const indentString = (str) => {
|
||||
if (!str || !str.length) {
|
||||
return str;
|
||||
return str || '';
|
||||
}
|
||||
|
||||
return str
|
||||
@@ -20,7 +20,7 @@ const indentString = (str) => {
|
||||
|
||||
const outdentString = (str) => {
|
||||
if (!str || !str.length) {
|
||||
return str;
|
||||
return str || '';
|
||||
}
|
||||
|
||||
return str
|
||||
|
@@ -89,12 +89,12 @@ const jsonToBru = (json) => {
|
||||
|
||||
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}`)}
|
||||
${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 || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -102,8 +102,8 @@ ${indentString(`profileName: ${auth.awsv4.profileName}`)}
|
||||
|
||||
if (auth && auth.basic) {
|
||||
bru += `auth:basic {
|
||||
${indentString(`username: ${auth.basic.username}`)}
|
||||
${indentString(`password: ${auth.basic.password}`)}
|
||||
${indentString(`username: ${auth?.basic?.username || ''}`)}
|
||||
${indentString(`password: ${auth?.basic?.password || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -111,7 +111,7 @@ ${indentString(`password: ${auth.basic.password}`)}
|
||||
|
||||
if (auth && auth.bearer) {
|
||||
bru += `auth:bearer {
|
||||
${indentString(`token: ${auth.bearer.token}`)}
|
||||
${indentString(`token: ${auth?.bearer?.token || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -119,8 +119,8 @@ ${indentString(`token: ${auth.bearer.token}`)}
|
||||
|
||||
if (auth && auth.digest) {
|
||||
bru += `auth:digest {
|
||||
${indentString(`username: ${auth.digest.username}`)}
|
||||
${indentString(`password: ${auth.digest.password}`)}
|
||||
${indentString(`username: ${auth?.digest?.username || ''}`)}
|
||||
${indentString(`password: ${auth?.digest?.password || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -131,8 +131,8 @@ ${indentString(`password: ${auth.digest.password}`)}
|
||||
case 'password':
|
||||
bru += `auth:oauth2 {
|
||||
${indentString(`grant_type: password`)}
|
||||
${indentString(`username: ${auth.oauth2.username}`)}
|
||||
${indentString(`password: ${auth.oauth2.password}`)}
|
||||
${indentString(`username: ${auth?.oauth2?.username || ''}`)}
|
||||
${indentString(`password: ${auth?.oauth2?.password || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -140,12 +140,12 @@ ${indentString(`password: ${auth.oauth2.password}`)}
|
||||
case 'authorization_code':
|
||||
bru += `auth:oauth2 {
|
||||
${indentString(`grant_type: authorization_code`)}
|
||||
${indentString(`callback_url: ${auth.oauth2.callbackUrl}`)}
|
||||
${indentString(`authorization_url: ${auth.oauth2.authorizationUrl}`)}
|
||||
${indentString(`access_token_url: ${auth.oauth2.accessTokenUrl}`)}
|
||||
${indentString(`client_id: ${auth.oauth2.clientId}`)}
|
||||
${indentString(`client_secret: ${auth.oauth2.clientSecret}`)}
|
||||
${indentString(`scope: ${auth.oauth2.scope}`)}
|
||||
${indentString(`callback_url: ${auth?.oauth2?.callbackUrl || ''}`)}
|
||||
${indentString(`authorization_url: ${auth?.oauth2?.authorizationUrl || ''}`)}
|
||||
${indentString(`access_token_url: ${auth?.oauth2?.accessTokenUrl || ''}`)}
|
||||
${indentString(`client_id: ${auth?.oauth2?.clientId || ''}`)}
|
||||
${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
|
||||
${indentString(`scope: ${auth?.oauth2?.scope || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -153,8 +153,8 @@ ${indentString(`scope: ${auth.oauth2.scope}`)}
|
||||
case 'client_credentials':
|
||||
bru += `auth:oauth2 {
|
||||
${indentString(`grant_type: client_credentials`)}
|
||||
${indentString(`client_id: ${auth.oauth2.clientId}`)}
|
||||
${indentString(`client_secret: ${auth.oauth2.clientSecret}`)}
|
||||
${indentString(`client_id: ${auth?.oauth2?.clientId || ''}`)}
|
||||
${indentString(`client_secret: ${auth?.oauth2?.clientSecret || ''}`)}
|
||||
}
|
||||
|
||||
`;
|
||||
@@ -368,3 +368,5 @@ ${indentString(docs)}
|
||||
};
|
||||
|
||||
module.exports = jsonToBru;
|
||||
|
||||
// alternative to writing the below code to avoif undefined
|
||||
|
Reference in New Issue
Block a user