Skip to content

Commit

Permalink
refactor: extract named type for env
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Jul 18, 2024
1 parent 2bd63b9 commit b5fe25a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/src/plugins/container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type { Resolved } from "../../actions/types.js"
import pMemoize from "../../lib/p-memoize.js"
import { styles } from "../../logger/styles.js"
import type { ContainerProviderConfig } from "./container.js"
import { maybeSecret, type MaybeSecret } from "../../util/secrets.js"
import { maybeSecret, type MaybeSecretEnv } from "../../util/secrets.js"

const { readFile, pathExists, lstat } = fsExtra

Expand Down Expand Up @@ -393,7 +393,7 @@ const helpers = {
stdout?: Writable
stderr?: Writable
timeout?: number
env?: { [key: string]: MaybeSecret }
env?: MaybeSecretEnv
}) {
const docker = ctx.tools["container.docker"]

Expand Down Expand Up @@ -611,7 +611,7 @@ function getDockerfilePath(basePath: string, dockerfile = defaultDockerfileName)
return joinWithPosix(basePath, dockerfile)
}

function getProcessEnv(): { [key: string]: MaybeSecret } {
function getProcessEnv(): MaybeSecretEnv {
return Object.fromEntries(
Object.entries(process.env)
.filter((tuple: [string, string | undefined]): tuple is [string, string] => tuple[1] !== undefined)
Expand Down
7 changes: 4 additions & 3 deletions core/src/util/ext-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import fsExtra from "fs-extra"
const { pathExists, createWriteStream, ensureDir, chmod, remove, move, createReadStream } = fsExtra
import { InternalError } from "../exceptions.js"
import { join, dirname, basename, posix } from "path"
import { getArchitecture, getPlatform, isDarwinARM } from "./arch-platform.js"
Expand All @@ -28,15 +27,17 @@ import { LogLevel } from "../logger/logger.js"
import { uuidv4 } from "./random.js"
import { streamLogs, waitForProcess } from "./process.js"
import { pipeline } from "node:stream/promises"
import { type MaybeSecret } from "./secrets.js"
import type { MaybeSecretEnv } from "./secrets.js"

const { pathExists, createWriteStream, ensureDir, chmod, remove, move, createReadStream } = fsExtra

const toolsPath = join(GARDEN_GLOBAL_PATH, "tools")
const lock = new AsyncLock()

export interface ExecParams {
args?: string[]
cwd?: string
env?: { [key: string]: MaybeSecret }
env?: MaybeSecretEnv
log: Log
timeoutSec?: number
input?: Buffer | string
Expand Down
1 change: 1 addition & 0 deletions core/src/util/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Secret {
}

export type MaybeSecret = string | Secret
export type MaybeSecretEnv = { [key: string]: MaybeSecret }

/**
* To be used as tagged string, to concatenate secret and non-secret strings, protecting the secrets from leaking them accidentally.
Expand Down

0 comments on commit b5fe25a

Please sign in to comment.