Skip to content

Commit

Permalink
Added mask api
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Aug 17, 2024
1 parent 0352af0 commit 8c53b18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ invoke(<Batch>

security.jsx
```jsx
import { mask } from "@neurospeech/jex/dist/index.js";

//These are reusable functions...
export const Security = {

Expand All @@ -93,7 +95,7 @@ export const Security = {
}) {
return <Run
cmd="security"
args={["create-keychain", "-p", password, path]}
args={["create-keychain", "-p", mask(password), path]}
/>
},

Expand All @@ -113,7 +115,7 @@ export const Security = {
}) {
return <Run
cmd="security"
args={["unlock-keychain", "-p", password, path]}
args={["unlock-keychain", "-p", mask(password), path]}
/>
},

Expand All @@ -127,7 +129,7 @@ export const Security = {
return <Run
cmd="security"
args={["import", certPath,
"-P", certPass,
"-P", mask(certPass),
"-A",
"-t", cert,
"-f", format,
Expand Down
9 changes: 9 additions & 0 deletions src/core/Secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Secret {
constructor(public secret: string) {

}

toString() {
return "********";
}
}
5 changes: 3 additions & 2 deletions src/core/spawnPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { SpawnOptionsWithoutStdio, spawn } from "node:child_process";

import { color } from "console-log-colors";
import { Secret } from "./Secret.js";

export const spawnPromise = (path, args?: string[], options?: SpawnOptionsWithoutStdio & {
export const spawnPromise = (path, args?: (string | Secret)[], options?: SpawnOptionsWithoutStdio & {
logCommand?: boolean,
logData?: boolean,
logError?: boolean,
Expand All @@ -20,7 +21,7 @@ export const spawnPromise = (path, args?: string[], options?: SpawnOptionsWithou
const errorList = [];
const allList = [];
const { logCommand = true, throwOnFail = false, logData = true, logError = true, log, error } = options ?? {};
const cd = spawn(path, args, options);
const cd = spawn(path, args.map((x) => x instanceof Secret ? x.secret : x), options);
const pid = cd.pid;
if (logCommand) {
console.log(`${path} ${args.join(" ")}`);
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { unlinkSync } from "fs";
import { Babel } from "./core/babel.js";
import XNode from "./core/XNode.js";
import { pathToFileURL } from "url";
import { Secret } from "./core/Secret.js";

export { default as XNode } from "./core/XNode.js";

Expand Down Expand Up @@ -33,6 +34,8 @@ export const Log = ({ text = void 0 , error = void 0 }) => {
}
};

export const mask = (secret: string) => new Secret(secret);

export const invoke = async (name: string | XNode , args?: string[]) => {

if (name instanceof XNode) {
Expand Down

0 comments on commit 8c53b18

Please sign in to comment.