mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 22:27:48 +00:00
Replace axios with request
This commit is contained in:
@@ -6,7 +6,7 @@ const axiosInstance = axios.create();
|
|||||||
// add retry functionality to the axios instance
|
// add retry functionality to the axios instance
|
||||||
axiosRetry(axiosInstance, {
|
axiosRetry(axiosInstance, {
|
||||||
retries: 3,
|
retries: 3,
|
||||||
retryDelay: (retryCount) => retryCount * 1000, // delay between retries (in milliseconds)
|
retryDelay: axiosRetry.exponentialDelay, // exponential back-off delay between retries
|
||||||
retryCondition: (error) => {
|
retryCondition: (error) => {
|
||||||
// only retry if the error is a network error or a 5xx server error
|
// only retry if the error is a network error or a 5xx server error
|
||||||
return axiosRetry.isNetworkError(error) || axiosRetry.isRetryableError(error);
|
return axiosRetry.isNetworkError(error) || axiosRetry.isRetryableError(error);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { issueAuthTokens } from '../../helpers/auth';
|
import { issueAuthTokens } from '../../helpers/auth';
|
||||||
import { INVITED, ACCEPTED } from '../../variables';
|
import { INVITED, ACCEPTED } from '../../variables';
|
||||||
import { NODE_ENV } from '../../config';
|
import { NODE_ENV } from '../../config';
|
||||||
import axios from 'axios';
|
import request from '../../config/request';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete setting up user by adding their personal and auth information as part of the
|
* Complete setting up user by adding their personal and auth information as part of the
|
||||||
@@ -109,7 +109,7 @@ export const completeAccountSignup = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// sending a welcome email to new users
|
// sending a welcome email to new users
|
||||||
if (process.env.LOOPS_API_KEY) {
|
if (process.env.LOOPS_API_KEY) {
|
||||||
await axios.post("https://app.loops.so/api/v1/events/send", {
|
await request.post("https://app.loops.so/api/v1/events/send", {
|
||||||
"email": email,
|
"email": email,
|
||||||
"eventName": "Sign Up",
|
"eventName": "Sign Up",
|
||||||
"firstName": firstName,
|
"firstName": firstName,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import { IIntegrationAuth } from "../models";
|
import { IIntegrationAuth } from "../models";
|
||||||
|
import request from '../config/request';
|
||||||
import {
|
import {
|
||||||
INTEGRATION_AZURE_KEY_VAULT,
|
INTEGRATION_AZURE_KEY_VAULT,
|
||||||
INTEGRATION_AWS_PARAMETER_STORE,
|
INTEGRATION_AWS_PARAMETER_STORE,
|
||||||
@@ -111,7 +111,7 @@ const getAppsHeroku = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
let apps;
|
let apps;
|
||||||
try {
|
try {
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(`${INTEGRATION_HEROKU_API_URL}/apps`, {
|
await request.get(`${INTEGRATION_HEROKU_API_URL}/apps`, {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/vnd.heroku+json; version=3",
|
Accept: "application/vnd.heroku+json; version=3",
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
@@ -148,7 +148,7 @@ const getAppsVercel = async ({
|
|||||||
let apps;
|
let apps;
|
||||||
try {
|
try {
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(`${INTEGRATION_VERCEL_API_URL}/v9/projects`, {
|
await request.get(`${INTEGRATION_VERCEL_API_URL}/v9/projects`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json'
|
||||||
@@ -186,7 +186,7 @@ const getAppsNetlify = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
let apps;
|
let apps;
|
||||||
try {
|
try {
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(`${INTEGRATION_NETLIFY_API_URL}/api/v1/sites`, {
|
await request.get(`${INTEGRATION_NETLIFY_API_URL}/api/v1/sites`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json'
|
||||||
@@ -257,7 +257,7 @@ const getAppsRender = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
let apps: any;
|
let apps: any;
|
||||||
try {
|
try {
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(`${INTEGRATION_RENDER_API_URL}/v1/services`, {
|
await request.get(`${INTEGRATION_RENDER_API_URL}/v1/services`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
@@ -303,23 +303,18 @@ const getAppsFlyio = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const res = (
|
const res = (await request.post(INTEGRATION_FLYIO_API_URL, {
|
||||||
await axios({
|
query,
|
||||||
url: INTEGRATION_FLYIO_API_URL,
|
variables: {
|
||||||
method: "post",
|
role: null,
|
||||||
headers: {
|
},
|
||||||
Authorization: "Bearer " + accessToken,
|
}, {
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer " + accessToken,
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Accept-Encoding': 'application/json',
|
'Accept-Encoding': 'application/json',
|
||||||
},
|
},
|
||||||
data: {
|
})).data.data.apps.nodes;
|
||||||
query,
|
|
||||||
variables: {
|
|
||||||
role: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).data.data.apps.nodes;
|
|
||||||
|
|
||||||
apps = res.map((a: any) => ({
|
apps = res.map((a: any) => ({
|
||||||
name: a.name,
|
name: a.name,
|
||||||
@@ -344,7 +339,7 @@ const getAppsCircleCI = async ({ accessToken }: { accessToken: string }) => {
|
|||||||
let apps: any;
|
let apps: any;
|
||||||
try {
|
try {
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(
|
await request.get(
|
||||||
`${INTEGRATION_CIRCLECI_API_URL}/v1.1/projects`,
|
`${INTEGRATION_CIRCLECI_API_URL}/v1.1/projects`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import axios from 'axios';
|
import request from '../config/request';
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import {
|
import {
|
||||||
INTEGRATION_AZURE_KEY_VAULT,
|
INTEGRATION_AZURE_KEY_VAULT,
|
||||||
@@ -136,7 +136,7 @@ const exchangeCodeAzure = async ({
|
|||||||
const accessExpiresAt = new Date();
|
const accessExpiresAt = new Date();
|
||||||
let res: ExchangeCodeAzureResponse;
|
let res: ExchangeCodeAzureResponse;
|
||||||
try {
|
try {
|
||||||
res = (await axios.post(
|
res = (await request.post(
|
||||||
INTEGRATION_AZURE_TOKEN_URL,
|
INTEGRATION_AZURE_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
@@ -182,7 +182,7 @@ const exchangeCodeHeroku = async ({
|
|||||||
let res: ExchangeCodeHerokuResponse;
|
let res: ExchangeCodeHerokuResponse;
|
||||||
const accessExpiresAt = new Date();
|
const accessExpiresAt = new Date();
|
||||||
try {
|
try {
|
||||||
res = (await axios.post(
|
res = (await request.post(
|
||||||
INTEGRATION_HEROKU_TOKEN_URL,
|
INTEGRATION_HEROKU_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
@@ -221,7 +221,7 @@ const exchangeCodeVercel = async ({ code }: { code: string }) => {
|
|||||||
let res: ExchangeCodeVercelResponse;
|
let res: ExchangeCodeVercelResponse;
|
||||||
try {
|
try {
|
||||||
res = (
|
res = (
|
||||||
await axios.post(
|
await request.post(
|
||||||
INTEGRATION_VERCEL_TOKEN_URL,
|
INTEGRATION_VERCEL_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
code: code,
|
code: code,
|
||||||
@@ -260,7 +260,7 @@ const exchangeCodeNetlify = async ({ code }: { code: string }) => {
|
|||||||
let accountId;
|
let accountId;
|
||||||
try {
|
try {
|
||||||
res = (
|
res = (
|
||||||
await axios.post(
|
await request.post(
|
||||||
INTEGRATION_NETLIFY_TOKEN_URL,
|
INTEGRATION_NETLIFY_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
@@ -272,14 +272,14 @@ const exchangeCodeNetlify = async ({ code }: { code: string }) => {
|
|||||||
)
|
)
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
const res2 = await axios.get('https://api.netlify.com/api/v1/sites', {
|
const res2 = await request.get('https://api.netlify.com/api/v1/sites', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${res.access_token}`
|
Authorization: `Bearer ${res.access_token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const res3 = (
|
const res3 = (
|
||||||
await axios.get('https://api.netlify.com/api/v1/accounts', {
|
await request.get('https://api.netlify.com/api/v1/accounts', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${res.access_token}`
|
Authorization: `Bearer ${res.access_token}`
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ const exchangeCodeGithub = async ({ code }: { code: string }) => {
|
|||||||
let res: ExchangeCodeGithubResponse;
|
let res: ExchangeCodeGithubResponse;
|
||||||
try {
|
try {
|
||||||
res = (
|
res = (
|
||||||
await axios.get(INTEGRATION_GITHUB_TOKEN_URL, {
|
await request.get(INTEGRATION_GITHUB_TOKEN_URL, {
|
||||||
params: {
|
params: {
|
||||||
client_id: CLIENT_ID_GITHUB,
|
client_id: CLIENT_ID_GITHUB,
|
||||||
client_secret: CLIENT_SECRET_GITHUB,
|
client_secret: CLIENT_SECRET_GITHUB,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import axios from 'axios';
|
import request from '../config/request';
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import { INTEGRATION_AZURE_KEY_VAULT, INTEGRATION_HEROKU } from '../variables';
|
import { INTEGRATION_AZURE_KEY_VAULT, INTEGRATION_HEROKU } from '../variables';
|
||||||
import {
|
import {
|
||||||
@@ -71,7 +71,7 @@ const exchangeRefreshAzure = async ({
|
|||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const res: RefreshTokenAzureResponse = (await axios.post(
|
const res: RefreshTokenAzureResponse = (await request.post(
|
||||||
INTEGRATION_AZURE_TOKEN_URL,
|
INTEGRATION_AZURE_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
client_id: CLIENT_ID_AZURE,
|
client_id: CLIENT_ID_AZURE,
|
||||||
@@ -105,7 +105,7 @@ const exchangeRefreshHeroku = async ({
|
|||||||
|
|
||||||
let accessToken;
|
let accessToken;
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(
|
const res = await request.post(
|
||||||
INTEGRATION_HEROKU_TOKEN_URL,
|
INTEGRATION_HEROKU_TOKEN_URL,
|
||||||
new URLSearchParams({
|
new URLSearchParams({
|
||||||
grant_type: 'refresh_token',
|
grant_type: 'refresh_token',
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import axios from "axios";
|
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import AWS from 'aws-sdk';
|
import AWS from 'aws-sdk';
|
||||||
@@ -30,7 +29,7 @@ import {
|
|||||||
INTEGRATION_FLYIO_API_URL,
|
INTEGRATION_FLYIO_API_URL,
|
||||||
INTEGRATION_CIRCLECI_API_URL,
|
INTEGRATION_CIRCLECI_API_URL,
|
||||||
} from "../variables";
|
} from "../variables";
|
||||||
import axiosWithRetry from '../config/request';
|
import request from '../config/request';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync/push [secrets] to [app] in integration named [integration]
|
* Sync/push [secrets] to [app] in integration named [integration]
|
||||||
@@ -179,7 +178,7 @@ const syncSecretsAzureKeyVault = async ({
|
|||||||
let result: GetAzureKeyVaultSecret[] = [];
|
let result: GetAzureKeyVaultSecret[] = [];
|
||||||
|
|
||||||
while (url) {
|
while (url) {
|
||||||
const res = await axios.get(url, {
|
const res = await request.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json'
|
||||||
@@ -201,7 +200,7 @@ const syncSecretsAzureKeyVault = async ({
|
|||||||
lastSlashIndex = getAzureKeyVaultSecret.id.lastIndexOf('/');
|
lastSlashIndex = getAzureKeyVaultSecret.id.lastIndexOf('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const azureKeyVaultSecret = await axios.get(`${getAzureKeyVaultSecret.id}?api-version=7.3`, {
|
const azureKeyVaultSecret = await request.get(`${getAzureKeyVaultSecret.id}?api-version=7.3`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json'
|
||||||
@@ -254,7 +253,7 @@ const syncSecretsAzureKeyVault = async ({
|
|||||||
// Sync/push set secrets
|
// Sync/push set secrets
|
||||||
if (setSecrets.length > 0) {
|
if (setSecrets.length > 0) {
|
||||||
setSecrets.forEach(async ({ key, value }) => {
|
setSecrets.forEach(async ({ key, value }) => {
|
||||||
await axios.put(
|
await request.put(
|
||||||
`${integration.app}/secrets/${key}?api-version=7.3`,
|
`${integration.app}/secrets/${key}?api-version=7.3`,
|
||||||
{
|
{
|
||||||
value
|
value
|
||||||
@@ -271,7 +270,7 @@ const syncSecretsAzureKeyVault = async ({
|
|||||||
|
|
||||||
if (deleteSecrets.length > 0) {
|
if (deleteSecrets.length > 0) {
|
||||||
deleteSecrets.forEach(async (secret) => {
|
deleteSecrets.forEach(async (secret) => {
|
||||||
await axios.delete(`${integration.app}/secrets/${secret.key}?api-version=7.3`, {
|
await request.delete(`${integration.app}/secrets/${secret.key}?api-version=7.3`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${accessToken}`,
|
'Authorization': `Bearer ${accessToken}`,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json'
|
||||||
@@ -486,7 +485,7 @@ const syncSecretsHeroku = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const herokuSecrets = (
|
const herokuSecrets = (
|
||||||
await axios.get(
|
await request.get(
|
||||||
`${INTEGRATION_HEROKU_API_URL}/apps/${integration.app}/config-vars`,
|
`${INTEGRATION_HEROKU_API_URL}/apps/${integration.app}/config-vars`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -504,7 +503,7 @@ const syncSecretsHeroku = async ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await axios.patch(
|
await request.patch(
|
||||||
`${INTEGRATION_HEROKU_API_URL}/apps/${integration.app}/config-vars`,
|
`${INTEGRATION_HEROKU_API_URL}/apps/${integration.app}/config-vars`,
|
||||||
secrets,
|
secrets,
|
||||||
{
|
{
|
||||||
@@ -562,7 +561,7 @@ const syncSecretsVercel = async ({
|
|||||||
// const res = (
|
// const res = (
|
||||||
// await Promise.all(
|
// await Promise.all(
|
||||||
// (
|
// (
|
||||||
// await axios.get(
|
// await request.get(
|
||||||
// `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
|
// `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
|
||||||
// {
|
// {
|
||||||
// params,
|
// params,
|
||||||
@@ -578,7 +577,7 @@ const syncSecretsVercel = async ({
|
|||||||
// .map(async (secret: VercelSecret) => {
|
// .map(async (secret: VercelSecret) => {
|
||||||
// if (secret.type === 'encrypted') {
|
// if (secret.type === 'encrypted') {
|
||||||
// // case: secret is encrypted -> need to decrypt
|
// // case: secret is encrypted -> need to decrypt
|
||||||
// const decryptedSecret = (await axios.get(
|
// const decryptedSecret = (await request.get(
|
||||||
// `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
// `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
||||||
// {
|
// {
|
||||||
// params,
|
// params,
|
||||||
@@ -598,7 +597,7 @@ const syncSecretsVercel = async ({
|
|||||||
// [secret.key]: secret
|
// [secret.key]: secret
|
||||||
// }), {});
|
// }), {});
|
||||||
|
|
||||||
const vercelSecrets: VercelSecret[] = (await axiosWithRetry.get(
|
const vercelSecrets: VercelSecret[] = (await request.get(
|
||||||
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
|
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
|
||||||
{
|
{
|
||||||
params,
|
params,
|
||||||
@@ -617,7 +616,7 @@ const syncSecretsVercel = async ({
|
|||||||
for await (const vercelSecret of vercelSecrets) {
|
for await (const vercelSecret of vercelSecrets) {
|
||||||
if (vercelSecret.type === 'encrypted') {
|
if (vercelSecret.type === 'encrypted') {
|
||||||
// case: secret is encrypted -> need to decrypt
|
// case: secret is encrypted -> need to decrypt
|
||||||
const decryptedSecret = (await axiosWithRetry.get(
|
const decryptedSecret = (await request.get(
|
||||||
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${vercelSecret.id}`,
|
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${vercelSecret.id}`,
|
||||||
{
|
{
|
||||||
params,
|
params,
|
||||||
@@ -680,7 +679,7 @@ const syncSecretsVercel = async ({
|
|||||||
|
|
||||||
// Sync/push new secrets
|
// Sync/push new secrets
|
||||||
if (newSecrets.length > 0) {
|
if (newSecrets.length > 0) {
|
||||||
await axiosWithRetry.post(
|
await request.post(
|
||||||
`${INTEGRATION_VERCEL_API_URL}/v10/projects/${integration.app}/env`,
|
`${INTEGRATION_VERCEL_API_URL}/v10/projects/${integration.app}/env`,
|
||||||
newSecrets,
|
newSecrets,
|
||||||
{
|
{
|
||||||
@@ -696,7 +695,7 @@ const syncSecretsVercel = async ({
|
|||||||
for await (const secret of updateSecrets) {
|
for await (const secret of updateSecrets) {
|
||||||
if (secret.type !== 'sensitive') {
|
if (secret.type !== 'sensitive') {
|
||||||
const { id, ...updatedSecret } = secret;
|
const { id, ...updatedSecret } = secret;
|
||||||
await axiosWithRetry.patch(
|
await request.patch(
|
||||||
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
||||||
updatedSecret,
|
updatedSecret,
|
||||||
{
|
{
|
||||||
@@ -711,7 +710,7 @@ const syncSecretsVercel = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
for await (const secret of deleteSecrets) {
|
for await (const secret of deleteSecrets) {
|
||||||
await axiosWithRetry.delete(
|
await request.delete(
|
||||||
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
|
||||||
{
|
{
|
||||||
params,
|
params,
|
||||||
@@ -770,7 +769,7 @@ const syncSecretsNetlify = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const res = (
|
const res = (
|
||||||
await axios.get(
|
await request.get(
|
||||||
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env`,
|
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env`,
|
||||||
{
|
{
|
||||||
params: getParams,
|
params: getParams,
|
||||||
@@ -884,7 +883,7 @@ const syncSecretsNetlify = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (newSecrets.length > 0) {
|
if (newSecrets.length > 0) {
|
||||||
await axios.post(
|
await request.post(
|
||||||
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env`,
|
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env`,
|
||||||
newSecrets,
|
newSecrets,
|
||||||
{
|
{
|
||||||
@@ -899,7 +898,7 @@ const syncSecretsNetlify = async ({
|
|||||||
|
|
||||||
if (updateSecrets.length > 0) {
|
if (updateSecrets.length > 0) {
|
||||||
updateSecrets.forEach(async (secret: NetlifySecret) => {
|
updateSecrets.forEach(async (secret: NetlifySecret) => {
|
||||||
await axios.patch(
|
await request.patch(
|
||||||
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${secret.key}`,
|
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${secret.key}`,
|
||||||
{
|
{
|
||||||
context: secret.values[0].context,
|
context: secret.values[0].context,
|
||||||
@@ -918,7 +917,7 @@ const syncSecretsNetlify = async ({
|
|||||||
|
|
||||||
if (deleteSecrets.length > 0) {
|
if (deleteSecrets.length > 0) {
|
||||||
deleteSecrets.forEach(async (key: string) => {
|
deleteSecrets.forEach(async (key: string) => {
|
||||||
await axios.delete(
|
await request.delete(
|
||||||
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${key}`,
|
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${key}`,
|
||||||
{
|
{
|
||||||
params: syncParams,
|
params: syncParams,
|
||||||
@@ -933,7 +932,7 @@ const syncSecretsNetlify = async ({
|
|||||||
|
|
||||||
if (deleteSecretValues.length > 0) {
|
if (deleteSecretValues.length > 0) {
|
||||||
deleteSecretValues.forEach(async (secret: NetlifySecret) => {
|
deleteSecretValues.forEach(async (secret: NetlifySecret) => {
|
||||||
await axios.delete(
|
await request.delete(
|
||||||
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${secret.key}/value/${secret.values[0].id}`,
|
`${INTEGRATION_NETLIFY_API_URL}/api/v1/accounts/${integrationAuth.accountId}/env/${secret.key}/value/${secret.values[0].id}`,
|
||||||
{
|
{
|
||||||
params: syncParams,
|
params: syncParams,
|
||||||
@@ -1084,7 +1083,7 @@ const syncSecretsRender = async ({
|
|||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
await axios.put(
|
await request.put(
|
||||||
`${INTEGRATION_RENDER_API_URL}/v1/services/${integration.appId}/env-vars`,
|
`${INTEGRATION_RENDER_API_URL}/v1/services/${integration.appId}/env-vars`,
|
||||||
Object.keys(secrets).map((key) => ({
|
Object.keys(secrets).map((key) => ({
|
||||||
key,
|
key,
|
||||||
@@ -1142,24 +1141,21 @@ const syncSecretsFlyio = async ({
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await axios({
|
await request.post(INTEGRATION_FLYIO_API_URL, {
|
||||||
url: INTEGRATION_FLYIO_API_URL,
|
query: SetSecrets,
|
||||||
method: "post",
|
variables: {
|
||||||
|
input: {
|
||||||
|
appId: integration.app,
|
||||||
|
secrets: Object.entries(secrets).map(([key, value]) => ({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json',
|
||||||
},
|
|
||||||
data: {
|
|
||||||
query: SetSecrets,
|
|
||||||
variables: {
|
|
||||||
input: {
|
|
||||||
appId: integration.app,
|
|
||||||
secrets: Object.entries(secrets).map(([key, value]) => ({
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1180,23 +1176,18 @@ const syncSecretsFlyio = async ({
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
const getSecretsRes = (
|
const getSecretsRes = (await request.post(INTEGRATION_FLYIO_API_URL, {
|
||||||
await axios({
|
query: GetSecrets,
|
||||||
method: "post",
|
variables: {
|
||||||
url: INTEGRATION_FLYIO_API_URL,
|
appName: integration.app,
|
||||||
headers: {
|
},
|
||||||
'Authorization': 'Bearer ' + accessToken,
|
}, {
|
||||||
'Content-Type': 'application/json',
|
headers: {
|
||||||
'Accept-Encoding': 'application/json'
|
Authorization: "Bearer " + accessToken,
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
data: {
|
'Accept-Encoding': 'application/json',
|
||||||
query: GetSecrets,
|
},
|
||||||
variables: {
|
})).data.data.app.secrets;
|
||||||
appName: integration.app,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).data.data.app.secrets;
|
|
||||||
|
|
||||||
const deleteSecretsKeys = getSecretsRes
|
const deleteSecretsKeys = getSecretsRes
|
||||||
.filter((secret: FlyioSecret) => !(secret.name in secrets))
|
.filter((secret: FlyioSecret) => !(secret.name in secrets))
|
||||||
@@ -1221,24 +1212,22 @@ const syncSecretsFlyio = async ({
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
await axios({
|
await request.post(INTEGRATION_FLYIO_API_URL, {
|
||||||
method: "post",
|
query: DeleteSecrets,
|
||||||
url: INTEGRATION_FLYIO_API_URL,
|
variables: {
|
||||||
|
input: {
|
||||||
|
appId: integration.app,
|
||||||
|
keys: deleteSecretsKeys,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
'Accept-Encoding': 'application/json'
|
'Accept-Encoding': 'application/json',
|
||||||
},
|
|
||||||
data: {
|
|
||||||
query: DeleteSecrets,
|
|
||||||
variables: {
|
|
||||||
input: {
|
|
||||||
appId: integration.app,
|
|
||||||
keys: deleteSecretsKeys,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.setUser(null);
|
Sentry.setUser(null);
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
@@ -1264,7 +1253,7 @@ const syncSecretsCircleCI = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const circleciOrganizationDetail = (
|
const circleciOrganizationDetail = (
|
||||||
await axios.get(`${INTEGRATION_CIRCLECI_API_URL}/v2/me/collaborations`, {
|
await request.get(`${INTEGRATION_CIRCLECI_API_URL}/v2/me/collaborations`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Circle-Token": accessToken,
|
"Circle-Token": accessToken,
|
||||||
"Accept-Encoding": "application/json",
|
"Accept-Encoding": "application/json",
|
||||||
@@ -1277,7 +1266,7 @@ const syncSecretsCircleCI = async ({
|
|||||||
// sync secrets to CircleCI
|
// sync secrets to CircleCI
|
||||||
Object.keys(secrets).forEach(
|
Object.keys(secrets).forEach(
|
||||||
async (key) =>
|
async (key) =>
|
||||||
await axios.post(
|
await request.post(
|
||||||
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar`,
|
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar`,
|
||||||
{
|
{
|
||||||
name: key,
|
name: key,
|
||||||
@@ -1294,7 +1283,7 @@ const syncSecretsCircleCI = async ({
|
|||||||
|
|
||||||
// get secrets from CircleCI
|
// get secrets from CircleCI
|
||||||
const getSecretsRes = (
|
const getSecretsRes = (
|
||||||
await axios.get(
|
await request.get(
|
||||||
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar`,
|
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -1308,7 +1297,7 @@ const syncSecretsCircleCI = async ({
|
|||||||
// delete secrets from CircleCI
|
// delete secrets from CircleCI
|
||||||
getSecretsRes.forEach(async (sec: any) => {
|
getSecretsRes.forEach(async (sec: any) => {
|
||||||
if (!(sec.name in secrets)) {
|
if (!(sec.name in secrets)) {
|
||||||
await axios.delete(
|
await request.delete(
|
||||||
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar/${sec.name}`,
|
`${INTEGRATION_CIRCLECI_API_URL}/v2/project/${slug}/${integration.app}/envvar/${sec.name}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user