Skip to content

Commit

Permalink
keychain-cli: @sadams/environment => env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jan 17, 2024
1 parent 5d67d59 commit ccd2cb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 41 deletions.
2 changes: 1 addition & 1 deletion mk/build-post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ async function transformDeclaration(filename) {
* All other packages are assumed to have ES Module entrypoint.
*/
const CJS_IMPORTS = new Set([
"@sadams/environment",
"@yoursunny/asn1",
"applymixins",
"buffer-compare",
"encoding-down",
"env-var",
"event-iterator",
"fast-chunk-string",
"it-keepalive",
Expand Down
2 changes: 1 addition & 1 deletion packages/keychain-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@ndn/repo": "workspace:*",
"@ndn/tlv": "workspace:*",
"@ndn/util": "workspace:*",
"@sadams/environment": "^9.0.0",
"env-var": "^7.4.1",
"fast-chunk-string": "^1.0.1",
"get-stdin": "^9.0.0",
"leveldown": "^6.1.1",
Expand Down
47 changes: 8 additions & 39 deletions packages/keychain-cli/src/ndncert03-ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Server, type ServerChallenge, ServerEmailChallenge, ServerNopChallenge,
import type { Verifier } from "@ndn/packet";
import { DataStore, PrefixRegShorter, RepoProducer } from "@ndn/repo";
import { toHex } from "@ndn/util";
import { makeEnv, parsers } from "@sadams/environment";
import envvar from "env-var";
import leveldown from "leveldown";
import { createTransport as createMT } from "nodemailer";
import stdout from "stdout-stream";
Expand Down Expand Up @@ -74,46 +74,15 @@ export const Ndncert03CaCommand: CommandModule<{}, Args> = {
break;
}
case "email": {
const env = makeEnv({
host: {
envVarName: "CA_EMAIL_HOST",
parser: parsers.string,
required: true,
},
port: {
envVarName: "CA_EMAIL_PORT",
parser: parsers.port,
required: false,
defaultValue: 587,
},
user: {
envVarName: "CA_EMAIL_USER",
parser: parsers.string,
required: true,
},
pass: {
envVarName: "CA_EMAIL_PASS",
parser: parsers.string,
required: true,
},
from: {
envVarName: "CA_EMAIL_FROM",
parser: parsers.email,
required: true,
},
});
const host = envvar.get("CA_EMAIL_HOST").required().asString();
const port = envvar.get("CA_EMAIL_PORT").default(587).asPortNumber();
const user = envvar.get("CA_EMAIL_USER").required().asString();
const pass = envvar.get("CA_EMAIL_PASS").required().asString();
const from = envvar.get("CA_EMAIL_FROM").required().asString(); // asEmailString() is too strict
const challenge = new ServerEmailChallenge({
mail: createMT({
host: env.host,
port: env.port,
secure: env.port === 465,
auth: {
user: env.user,
pass: env.pass,
},
}),
mail: createMT({ host, port, secure: port === 465, auth: { user, pass } }),
template: {
from: env.from,
from,
subject: "NDNCERT email challenge",
text: `Hi there
Expand Down

0 comments on commit ccd2cb4

Please sign in to comment.