Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'scmn-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx authored Dec 18, 2021
2 parents 414eb6e + 02ce1cc commit 8a72981
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 88 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
---

## [[v6.0.8] 2021-12-14](#v608-2021-12-14)

### Added

- configure `.devcontainer` for secman

### Changed

nothing

### Fixed

- fix config files warning messages ([#120](https://github.com/scmn-dev/secman/issues/120))
- fix Homedir bug in windows ([#121](https://github.com/scmn-dev/secman/issues/121))

## [[v6.0.71] 2021-11-14](#v6071-2021-11-14)

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://secman.dev/blog">Blog</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://twitter.com/_secman_">Twitter</a>
<a href="https://twitter.com/_secman">Twitter</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://github.com/secman-archive/secman-v1">Secman V1</a>
<br />
Expand Down
20 changes: 10 additions & 10 deletions app/config/index.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DOT_SECMAN_PATH,
SECMAN_CONFIG_PATH,
SECMAN_DATA_PATH,
SECMAN_SETTINGS_PATH,
SECMAN_SETTINGS_PATH
} from "../../constants";
import { writeJsonFile as writeJSON } from "../../tools/json/write";
import { platform } from "os";
Expand Down Expand Up @@ -78,8 +78,8 @@ export async function writeDataFile(
access_token: access_token,
refresh_token: refresh_token,
transmission_key: transmission_key,
master_password_hash: master_password_hash,
},
master_password_hash: master_password_hash
}
},
{}
);
Expand All @@ -97,7 +97,7 @@ export async function writeSettingFile() {
await writeJSON(
SECMAN_SETTINGS_PATH,
{
editor: "secman_editor",
editor: "secman_editor"
},
{}
);
Expand Down Expand Up @@ -128,9 +128,10 @@ export function readDataFile(obj: any) {
} catch {
console.log(
error(
`can't find your auth tokens, to authenticate run ${
(command("`secman auth`"), true)
}.`
`can't find your auth tokens, to authenticate run ${command(
"`secman auth`",
true
)}.`
)
);
process.exit(0);
Expand All @@ -153,9 +154,8 @@ export function readSettingsFile(obj: any) {
const fileIsNotFound = (fileName: string) => {
console.log(
logSymbols.warning +
`${warning(
"~/.secman/" + fileName + ".json"
)} does not exist, run ${command("secman init")}.`
warning(" ~/.secman/" + fileName + ".json ") +
`does not exist, run ${command("secman init")}`
);

process.exit(0);
Expand Down
4 changes: 3 additions & 1 deletion constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ env.config();
export const PRIMARY_COLOR: any = "#1163E6";
export const GH_TOKEN: any = process.env.GH_TOKEN;
export const API_URL: any = "https://api.secman.dev";
export const HOMEDIR: any =
process.platform === "win32" ? "USERPROFILE" : "HOME";
export const CHARS = {
alphabet: "abcdefghijklmnopqrstuvwxyz",
numeric: "0123456789",
special: "_-+=)/(*&^%$#@%!?~",
};
export const DOT_SECMAN_PATH = `${process.env.HOME}/.secman`;
export const DOT_SECMAN_PATH = `${HOMEDIR}/.secman`;
export const SECMAN_CONFIG_PATH: any = `/${DOT_SECMAN_PATH}/config.json`;
export const SECMAN_DATA_PATH: any = `/${DOT_SECMAN_PATH}/data.json`;
export const SECMAN_SETTINGS_PATH: any = `/${DOT_SECMAN_PATH}/settings.json`;
Expand Down
2 changes: 1 addition & 1 deletion design/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const warning = (text: string, bold: boolean = false) => {
if (bold) {
return chalk.yellow.bold(text);
} else {
return chalk.gray(text);
return chalk.yellow(text);
}
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "secman",
"description": "The command-line interface of Secman",
"version": "6.0.71",
"versionDate": "2021-11-13",
"version": "6.0.8",
"versionDate": "2021-12-14",
"main": "lib/index.js",
"license": "MIT",
"homepage": "https://secman.dev",
Expand Down
4 changes: 2 additions & 2 deletions scripts/brew/homebrew.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const rm = require("rimraf");
const mkdirp = require("mkdirp");
const { promisify } = require("util");
const { pipeline } = require("stream");
const crypto = require("crypto");
const _crypto = require("crypto");
const sh = require("shelljs");

const NODE_JS_BASE = "https://nodejs.org/download/release";
Expand Down Expand Up @@ -62,7 +62,7 @@ async function getDownloadInfoForNodeVersion(version) {
// }

async function calculateSHA256(fileName) {
const hash = crypto.createHash("sha256");
const hash = _crypto.createHash("sha256");
hash.setEncoding("hex");
await promisify(pipeline)(fs.createReadStream(fileName), hash);
return hash.read();
Expand Down
114 changes: 43 additions & 71 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Command, flags } from "@oclif/command";
import chalk from "chalk";
import { PRIMARY_COLOR } from "../../constants";
import writeConfigFile, { readConfigFile } from "../../app/config";
import { API } from "../../contract";
import { CryptoTools } from "../../tools/crypto";
import { cli as ux } from "cli-ux";
import { readPipe } from "../../tools/readPipe";
import { command, withPrimary } from "../../design/layout";
import { AuthExamples } from "../../contents/examples/auth";
import { cli } from "cli-ux";
const prompts = require("prompts");
prompts.override(require("yargs").argv);

Expand All @@ -15,73 +13,51 @@ export default class Auth extends Command {

static flags = {
help: flags.help({ char: "h" }),
"create-account": flags.boolean({
createAccount: flags.boolean({
char: "c",
description: "Create a new account.",
default: false,
}),
user: flags.string({
char: "u",
email: flags.string({
char: "e",
description: "Email address of the account to use.",
}),
"master-password": flags.string({
char: "p",
masterPassword: flags.string({
char: "m",
description: "Master password of the account to use.",
}),
"password-stdin": flags.boolean({
description: "Take the password from stdin",
default: false,
}),
};

static aliases = ["login", "signin"];

static examples = AuthExamples;

async run() {
const { flags } = this.parse(Auth);
const configFile = `${process.env.HOME}/.secman/config.json`;

const _ = async (isNewLogin: boolean) => {
let email;

if (flags.user) {
email = flags.user;
} else {
email =
readConfigFile("user") ??
(
await prompts({
type: "text",
name: "e",
message: "Enter your email: ",
validate: (value: string) => {
if (value.length > 0) {
return true;
} else {
return "Please enter your email";
}
},
})
).e;
}
// let email = readlineSync.questionEMail("Enter your email: ");
const email =
flags.email ||
readConfigFile("user") ||
(
await prompts({
type: "text",
name: "e",
message: "Enter your email: ",
validate: (value: string) => {
if (value.length > 0) {
return true;
} else {
return "Please enter your email";
}
},
})
).e;

try {
let password;
let master_password: any;

if (flags["master-password"]) {
password = flags["master-password"];
master_password = password;
} else if (flags["password-stdin"]) {
const stdin = await readPipe();

if (stdin) {
password = stdin.replace(/\s/g, "");
master_password = password;
}
} else {
password = await prompts({
let password =
flags.masterPassword ||
(await prompts({
type: "password",
name: "mp",
message: "Enter your master password: ",
Expand All @@ -92,10 +68,9 @@ export default class Auth extends Command {
return "Please enter your master password";
}
},
});
master_password = password.mp;
console.log("");
}
}));

let master_password = password.mp;

if (master_password) {
const hash = CryptoTools.sha256Encrypt(master_password);
Expand Down Expand Up @@ -136,24 +111,23 @@ export default class Auth extends Command {
);

const msg = isNewLogin
? "🎉 Welcome " + withPrimary(name) + "!"
: "Re-authentication successful";
? "\n🎉 Welcome " + chalk.hex(PRIMARY_COLOR).bold(name) + "!"
: "\nRe-authentication successful";

console.log(msg);
})
.catch(function (err: any) {
if (err.response.status === 401) {
console.log(
command(
`\nInvalid email or master password. if you don't have an account, please create one using the command ${
(command("`secman auth --create-account`."), true)
}`,
true
chalk.red.bold(
`\nInvalid email or master password. if you don't have an account, please create one using the command ${chalk.gray.bold(
"`secman auth --create-account`."
)}`
)
);
} else {
console.log(
command("\nSomething went wrong. Please try again.", true)
chalk.red.bold("\nSomething went wrong. Please try again.")
);
}
});
Expand All @@ -164,8 +138,8 @@ export default class Auth extends Command {
};

switch (true) {
case flags["create-account"]:
ux.open("https://auth.secman.dev");
case flags.createAccount:
cli.open("https://auth.secman.dev");

break;

Expand All @@ -177,16 +151,14 @@ export default class Auth extends Command {
const reauth = await prompts({
type: "toggle",
name: "value",
message: `You are already logged in as ${withPrimary(
user
)}. Would you like to re-authenticate?`,
message: `You are already logged in as ${chalk
.hex(PRIMARY_COLOR)
.bold(user)}. Would you like to re-authenticate?`,
initial: "yes",
active: "yes",
inactive: "no",
});

console.log("");

if (reauth.value) {
_(false);
} else {
Expand Down

0 comments on commit 8a72981

Please sign in to comment.