From a5c745505ab519b610f11e3e224e5d68816b5e73 Mon Sep 17 00:00:00 2001 From: Jakub Vacek Date: Fri, 18 Aug 2023 12:32:33 +0200 Subject: [PATCH 1/3] feat: one sdk log env --- src/commands/prepare.test.ts | 16 ++++++---- .../application-code/dotenv/dotenv.test.ts | 30 +++++++++++++++++++ src/logic/application-code/dotenv/dotenv.ts | 22 ++++++++++---- .../application-code/dotenv/onesdk-log.ts | 2 ++ 4 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 src/logic/application-code/dotenv/onesdk-log.ts diff --git a/src/commands/prepare.test.ts b/src/commands/prepare.test.ts index 71fde855..022eab21 100644 --- a/src/commands/prepare.test.ts +++ b/src/commands/prepare.test.ts @@ -131,12 +131,16 @@ describe('prepare CLI command', () => { jest.mocked(readFile).mockResolvedValueOnce(fileContent); jest.mocked(prepareProviderJson).mockResolvedValueOnce(providerJson); - await expect(instance.execute({ - logger, - userError, - flags: {}, - args: { urlOrPath: 'path/to/FILE.docs.2!87.yaml' }, - })).rejects.toThrow(`Provider name inferred from file name is not valid. Please provide provider name explicitly as second argument.`); + await expect( + instance.execute({ + logger, + userError, + flags: {}, + args: { urlOrPath: 'path/to/FILE.docs.2!87.yaml' }, + }) + ).rejects.toThrow( + `Provider name inferred from file name is not valid. Please provide provider name explicitly as second argument.` + ); }); it('prepares provider json from url', async () => { diff --git a/src/logic/application-code/dotenv/dotenv.test.ts b/src/logic/application-code/dotenv/dotenv.test.ts index 5a7b5b26..3434d0eb 100644 --- a/src/logic/application-code/dotenv/dotenv.test.ts +++ b/src/logic/application-code/dotenv/dotenv.test.ts @@ -26,6 +26,10 @@ const BEARER_AUTH: SecurityScheme = { const TOKEN = 'sfs_b31314b7fc8...8ec1930e'; const EXISTING_DOTENV = `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 @@ -45,6 +49,9 @@ describe('createNewDotenv', () => { content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Parameter description MY_PROVIDER_PARAM_ONE= MY_PROVIDER_TOKEN= @@ -60,6 +67,9 @@ MY_PROVIDER_TOKEN= expect(result).toStrictEqual({ content: `# Set your OneSDK token to monitor your usage out-of-the-box. Get yours at https://superface.ai SUPERFACE_ONESDK_TOKEN= + +# Set to "on" to enable better output logging +ONESDK_LOG="off" `, newEmptyEnvVariables: ['SUPERFACE_ONESDK_TOKEN'], }); @@ -74,6 +84,9 @@ SUPERFACE_ONESDK_TOKEN= expect(result).toStrictEqual({ content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable better output logging +ONESDK_LOG="off" `, newEmptyEnvVariables: [], }); @@ -90,6 +103,9 @@ SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e expect(result).toStrictEqual({ content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable better output logging +ONESDK_LOG="off" `, newEmptyEnvVariables: [], }); @@ -106,6 +122,9 @@ SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Parameter description MY_PROVIDER_PARAM_ONE= @@ -129,6 +148,9 @@ MY_PROVIDER_PARAM_TWO=us-west-1 content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Parameter description MY_PROVIDER_PARAM_ONE= @@ -171,6 +193,10 @@ MY_PROVIDER_TOKEN= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 @@ -193,6 +219,10 @@ MY_PROVIDER_PARAM_ONE= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable better output logging +ONESDK_LOG="off" + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 diff --git a/src/logic/application-code/dotenv/dotenv.ts b/src/logic/application-code/dotenv/dotenv.ts index a17fc92e..03660e7a 100644 --- a/src/logic/application-code/dotenv/dotenv.ts +++ b/src/logic/application-code/dotenv/dotenv.ts @@ -4,6 +4,7 @@ import { prepareSecurityValues, } from '@superfaceai/ast'; +import { ONESDK_LOG_COMMENT, ONESDK_LOG_ENV } from './onesdk-log'; import { ONESDK_TOKEN_COMMENT, ONESDK_TOKEN_ENV, @@ -27,22 +28,25 @@ export function createNewDotenv({ parameters, security, token, + logEnabled, }: { previousDotenv?: string; providerName: string; parameters?: IntegrationParameter[]; security?: SecurityScheme[]; token?: string | null; + logEnabled?: boolean; }): NewDotenv { const previousContent = previousDotenv ?? ''; const parameterEnvs = getParameterEnvs(providerName, parameters); const securityEnvs = getSecurityEnvs(providerName, security); const tokenEnv = makeTokenEnv(token); + const logEnv = makeLogEnv(logEnabled === true ? '"on"' : '"off"'); const newEnvsOnly = makeFilterForNewEnvs(previousContent); - const newEnvVariables = [tokenEnv, ...parameterEnvs, ...securityEnvs] + const newEnvVariables = [tokenEnv, logEnv, ...parameterEnvs, ...securityEnvs] .filter(uniqueEnvsOnly) .filter(newEnvsOnly); @@ -54,6 +58,14 @@ export function createNewDotenv({ }; } +function makeLogEnv(logValue = '"off"'): EnvVar { + return { + name: ONESDK_LOG_ENV, + value: logValue, + comment: ONESDK_LOG_COMMENT, + }; +} + function makeTokenEnv(token?: string | null): EnvVar { return { name: ONESDK_TOKEN_ENV, @@ -98,10 +110,10 @@ function serializeEnvVar(env: EnvVar): string { const comment = env.comment !== undefined ? '\n' + - env.comment - .split('\n') - .map(commentLine => `# ${commentLine}`) - .join('\n') + env.comment + .split('\n') + .map(commentLine => `# ${commentLine}`) + .join('\n') : ''; return `${comment ? comment + '\n' : ''}${env.name}=${env.value ?? ''}`; diff --git a/src/logic/application-code/dotenv/onesdk-log.ts b/src/logic/application-code/dotenv/onesdk-log.ts new file mode 100644 index 00000000..bfa22c47 --- /dev/null +++ b/src/logic/application-code/dotenv/onesdk-log.ts @@ -0,0 +1,2 @@ +export const ONESDK_LOG_ENV = 'ONESDK_LOG'; +export const ONESDK_LOG_COMMENT = 'Set to "on" to enable better output logging'; From d08662108ab3b5c438dd103fb1819b4ce14f8983 Mon Sep 17 00:00:00 2001 From: Jakub Vacek Date: Mon, 21 Aug 2023 12:12:03 +0200 Subject: [PATCH 2/3] fix: review fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Radek KyselĂ˝ --- src/logic/application-code/dotenv/dotenv.ts | 2 +- src/logic/application-code/dotenv/onesdk-log.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logic/application-code/dotenv/dotenv.ts b/src/logic/application-code/dotenv/dotenv.ts index 03660e7a..e0cb17d6 100644 --- a/src/logic/application-code/dotenv/dotenv.ts +++ b/src/logic/application-code/dotenv/dotenv.ts @@ -58,7 +58,7 @@ export function createNewDotenv({ }; } -function makeLogEnv(logValue = '"off"'): EnvVar { +function makeLogEnv(logValue = 'off'): EnvVar { return { name: ONESDK_LOG_ENV, value: logValue, diff --git a/src/logic/application-code/dotenv/onesdk-log.ts b/src/logic/application-code/dotenv/onesdk-log.ts index bfa22c47..86755380 100644 --- a/src/logic/application-code/dotenv/onesdk-log.ts +++ b/src/logic/application-code/dotenv/onesdk-log.ts @@ -1,2 +1,2 @@ export const ONESDK_LOG_ENV = 'ONESDK_LOG'; -export const ONESDK_LOG_COMMENT = 'Set to "on" to enable better output logging'; +export const ONESDK_LOG_COMMENT = 'Set to "on" to enable debug logging'; From 931e9843710dd1decc468e4a1c1619a5adbc69f8 Mon Sep 17 00:00:00 2001 From: Jakub Vacek Date: Mon, 21 Aug 2023 12:25:19 +0200 Subject: [PATCH 3/3] fix: review fixes --- .../application-code/dotenv/dotenv.test.ts | 36 +++++++++---------- src/logic/application-code/dotenv/dotenv.ts | 10 +++--- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/logic/application-code/dotenv/dotenv.test.ts b/src/logic/application-code/dotenv/dotenv.test.ts index 3434d0eb..627a112b 100644 --- a/src/logic/application-code/dotenv/dotenv.test.ts +++ b/src/logic/application-code/dotenv/dotenv.test.ts @@ -27,8 +27,8 @@ const TOKEN = 'sfs_b31314b7fc8...8ec1930e'; const EXISTING_DOTENV = `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Deployment zone # for AWS @@ -49,8 +49,8 @@ describe('createNewDotenv', () => { content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Parameter description MY_PROVIDER_PARAM_ONE= @@ -68,8 +68,8 @@ MY_PROVIDER_TOKEN= content: `# Set your OneSDK token to monitor your usage out-of-the-box. Get yours at https://superface.ai SUPERFACE_ONESDK_TOKEN= -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: ['SUPERFACE_ONESDK_TOKEN'], }); @@ -85,8 +85,8 @@ ONESDK_LOG="off" content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: [], }); @@ -104,8 +104,8 @@ ONESDK_LOG="off" content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: [], }); @@ -122,8 +122,8 @@ ONESDK_LOG="off" content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Parameter description MY_PROVIDER_PARAM_ONE= @@ -148,8 +148,8 @@ MY_PROVIDER_PARAM_TWO=us-west-1 content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Parameter description MY_PROVIDER_PARAM_ONE= @@ -194,8 +194,8 @@ MY_PROVIDER_TOKEN= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Deployment zone # for AWS @@ -220,8 +220,8 @@ MY_PROVIDER_PARAM_ONE= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e -# Set to "on" to enable better output logging -ONESDK_LOG="off" +# Set to "on" to enable debug logging +ONESDK_LOG=off # Deployment zone # for AWS diff --git a/src/logic/application-code/dotenv/dotenv.ts b/src/logic/application-code/dotenv/dotenv.ts index e0cb17d6..314edb2a 100644 --- a/src/logic/application-code/dotenv/dotenv.ts +++ b/src/logic/application-code/dotenv/dotenv.ts @@ -42,7 +42,7 @@ export function createNewDotenv({ const parameterEnvs = getParameterEnvs(providerName, parameters); const securityEnvs = getSecurityEnvs(providerName, security); const tokenEnv = makeTokenEnv(token); - const logEnv = makeLogEnv(logEnabled === true ? '"on"' : '"off"'); + const logEnv = makeLogEnv(logEnabled === true ? 'on' : 'off'); const newEnvsOnly = makeFilterForNewEnvs(previousContent); @@ -110,10 +110,10 @@ function serializeEnvVar(env: EnvVar): string { const comment = env.comment !== undefined ? '\n' + - env.comment - .split('\n') - .map(commentLine => `# ${commentLine}`) - .join('\n') + env.comment + .split('\n') + .map(commentLine => `# ${commentLine}`) + .join('\n') : ''; return `${comment ? comment + '\n' : ''}${env.name}=${env.value ?? ''}`;