Skip to content

Commit

Permalink
Merge pull request #1148 from gperdomor/feature/fix-secret-files
Browse files Browse the repository at this point in the history
fix(nx-container): fix secret-files interpolation
  • Loading branch information
gperdomor authored Oct 6, 2024
2 parents fb7adcd + 08b8f10 commit 196ccf1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/nx-container/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ if (swcJestConfig.swcrc === undefined) {
export default {
displayName: 'nx-container',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleFileExtensions: ['ts', 'js', 'html'],
testEnvironment: 'node',
coverageDirectory: '../../coverage/plugins/nx-container',
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as core from '@nx-tools/core';
import { interpolate } from '@nx-tools/core';
import { parse } from 'csv-parse/sync';
import fs from 'node:fs';
import path from 'node:path';
import * as semver from 'semver';
import * as context from '../../context';
import { interpolate } from '@nx-tools/core';

export async function getImageIDFile(): Promise<string> {
return path.join(context.tmpDir(), 'iidfile').split(path.sep).join(path.posix.sep);
Expand Down Expand Up @@ -61,13 +61,15 @@ export async function getSecret(kvp: string, file: boolean): Promise<string> {
throw new Error(`${kvp} is not a valid secret`);
}

const interpolated = interpolate(value);

if (file) {
if (!fs.existsSync(value)) {
throw new Error(`secret file ${value} not found`);
if (!fs.existsSync(interpolated)) {
throw new Error(`secret file ${interpolated} not found`);
}
value = fs.readFileSync(value, { encoding: 'utf-8' });
value = fs.readFileSync(interpolated, { encoding: 'utf-8' });
} else {
value = interpolate(value);
value = interpolated;
}

const secretFile = context.tmpNameSync({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as core from '@nx-tools/core';
import { interpolate } from '@nx-tools/core';
import { parse } from 'csv-parse/sync';
import fs from 'node:fs';
import path from 'node:path';
import * as semver from 'semver';
import * as context from '../../context';
import { interpolate } from '@nx-tools/core';

export async function getImageIDFile(): Promise<string> {
return path.join(context.tmpDir(), 'iidfile').split(path.sep).join(path.posix.sep);
Expand Down Expand Up @@ -61,13 +61,15 @@ export async function getSecret(kvp: string, file: boolean): Promise<string> {
throw new Error(`${kvp} is not a valid secret`);
}

const interpolated = interpolate(value);

if (file) {
if (!fs.existsSync(value)) {
throw new Error(`secret file ${value} not found`);
if (!fs.existsSync(interpolated)) {
throw new Error(`secret file ${interpolated} not found`);
}
value = fs.readFileSync(value, { encoding: 'utf-8' });
value = fs.readFileSync(interpolated, { encoding: 'utf-8' });
} else {
value = interpolate(value);
value = interpolated;
}

const secretFile = context.tmpNameSync({
Expand Down

0 comments on commit 196ccf1

Please sign in to comment.