Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polyapi",
"version": "0.24.10",
"version": "0.24.11",
"description": "Poly is a CLI tool to help create and manage your Poly definitions.",
"license": "MIT",
"repository": {
Expand Down
23 changes: 1 addition & 22 deletions templates/api-index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { axios } = require('../axios');
const { axios, scrub } = require('../axios');
const set = require('lodash/set');
const https = require('https');
const fs = require('fs');
Expand Down Expand Up @@ -49,27 +49,6 @@ const handleError = (err) => {
};
}

const scrub = (data) => {
if (!data || typeof data !== 'object' ) return data;
const secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"];
if (Array.isArray(data)) {
return data.map(item => scrub(item))
}
else {
const temp = {};
for (const key of Object.keys(data)) {
if (typeof data[key] === 'object') {
temp[key] = scrub(data[key]);
} else if (secrets.includes(key.toLowerCase())) {
temp[key] = "********";
} else {
temp[key] = data[key];
}
}
return temp
}
}


const executeApiFunction = (id, clientID, polyCustom, requestArgs) => {
const requestServerStartTime = Date.now();
Expand Down
27 changes: 25 additions & 2 deletions templates/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const https = require('https');
const dotenv = require('dotenv');
const polyCustom = require('./poly-custom');
const { API_KEY, API_BASE_URL } = require('./constants');
const { scrub } = require('../api/index.js')

dotenv.config();

Expand Down Expand Up @@ -43,6 +42,29 @@ axios.interceptors.request.use(
}
);


const scrub = (data) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add scrub to module.exports at bottom of the file.

if (!data || typeof data !== 'object' ) return data;
const secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"];
if (Array.isArray(data)) {
return data.map(item => scrub(item))
}
else {
const temp = {};
for (const key of Object.keys(data)) {
if (typeof data[key] === 'object') {
temp[key] = scrub(data[key]);
} else if (secrets.includes(key.toLowerCase())) {
temp[key] = "********";
} else {
temp[key] = data[key];
}
}
return temp
}
}


const scrubKeys = (err) => {
if (!err.request || typeof err.request.headers !== 'object') throw err
const temp = scrub(err.request.headers)
Expand All @@ -59,5 +81,6 @@ const scrubKeys = (err) => {

module.exports = {
axios,
scrubKeys
scrubKeys,
scrub
};