Skip to content

Commit

Permalink
feat: optional encode config (#131)
Browse files Browse the repository at this point in the history
* feat: encrypt config

* fix: recursive module

* feat: migrate config

* fix: import

* chore: prod build

* chore: text

* chore: no dev

* feat: init config

* chore: text

* chore: more generic text
  • Loading branch information
peterpeterparker authored Jul 28, 2024
1 parent bcf306f commit e4208a0
Show file tree
Hide file tree
Showing 26 changed files with 349 additions and 153 deletions.
4 changes: 2 additions & 2 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {reuseController} from '../services/controllers.services';
import {login as consoleLogin} from '../services/login.services';

export const logout = async () => {
clearCliConfig();
await clearCliConfig();

console.log(`${green('Logged out')}`);
};

export const login = async (args?: string[]) => {
const token = getToken();
const token = await getToken();

if (isNullish(token)) {
await consoleLogin(args);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const config = async (args?: string[]) => {
const {satellite: satelliteConfig} = await readJunoConfig(env);
const {storage, authentication, settings} = satelliteConfig;

const satellite = satelliteParameters({satellite: satelliteConfig, env});
const satellite = await satelliteParameters({satellite: satelliteConfig, env});

const spinner = ora(`Configuring...`).start();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const executeDeploy = async (args?: string[]) => {
await assertSatelliteMemorySize(args);
};

const satellite = satelliteParameters({satellite: satelliteConfig, env});
const satellite = await satelliteParameters({satellite: satelliteConfig, env});

const uploadFile = async ({
filename,
Expand Down
15 changes: 5 additions & 10 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import {cyan, yellow} from 'kleur';
import {unlink} from 'node:fs/promises';
import {basename} from 'node:path';
import prompts from 'prompts';
import {
getCliOrbiters,
getCliSatellites,
getToken,
type CliOrbiterConfig,
type CliSatelliteConfig
} from '../configs/cli.config';
import {getCliOrbiters, getCliSatellites, getToken} from '../configs/cli.config';
import {
detectJunoConfigType,
junoConfigExist,
Expand All @@ -20,10 +14,11 @@ import {
} from '../configs/juno.config';
import {promptConfigType} from '../services/init.services';
import {login as consoleLogin} from '../services/login.services';
import type {CliOrbiterConfig, CliSatelliteConfig} from '../types/cli.config';
import {NEW_CMD_LINE, confirm, confirmAndExit} from '../utils/prompt.utils';

export const init = async (args?: string[]) => {
const token = getToken();
const token = await getToken();

if (isNullish(token)) {
const login = await confirm(
Expand Down Expand Up @@ -79,7 +74,7 @@ const initConfig = async () => {
};

const initSatelliteConfig = async (): Promise<string> => {
const satellites = getCliSatellites();
const satellites = await getCliSatellites();

const satellite = await (satellites?.length > 0
? promptSatellites(satellites)
Expand All @@ -93,7 +88,7 @@ const initSatelliteConfig = async (): Promise<string> => {
};

const initOrbiterConfig = async (): Promise<string | undefined> => {
const authOrbiters = getCliOrbiters();
const authOrbiters = await getCliOrbiters();

if (authOrbiters === undefined || authOrbiters.length === 0) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const open = async (args?: string[]) => {
const env = configEnv(args);
const {satellite: satelliteConfig} = await readJunoConfig(env);

const satellite = satelliteParameters({satellite: satelliteConfig, env});
const satellite = await satelliteParameters({satellite: satelliteConfig, env});
const {satelliteId} = satellite;

if (hasArgs({args, options: ['-c', '--console']})) {
Expand Down
20 changes: 10 additions & 10 deletions src/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import {hasArgs, nextArg} from '@junobuild/cli-tools';
import {green, red} from 'kleur';
import {deleteUse, getProfiles, getUse, saveUse} from '../configs/cli.config';

export const use = (args?: string[]) => {
export const use = async (args?: string[]) => {
if (hasArgs({args, options: ['-l', '--list']})) {
listProfile();
await listProfile();
return;
}

switchProfile(args);
await switchProfile(args);
};

const listProfile = () => {
const profiles = getProfiles();
const listProfile = async () => {
const profiles = await getProfiles();

if (profiles === undefined) {
console.log('No particular profiles available. Using default.');
return;
}

const use = getUse();
const use = await getUse();

console.log('Available profiles:\n');
console.log(
Expand All @@ -29,7 +29,7 @@ const listProfile = () => {
);
};

const switchProfile = (args?: string[]) => {
const switchProfile = async (args?: string[]) => {
const profile = nextArg({args, option: '-p'}) ?? nextArg({args, option: '--profile'});

if (profile === undefined) {
Expand All @@ -38,20 +38,20 @@ const switchProfile = (args?: string[]) => {
}

if (profile === 'default') {
deleteUse();
await deleteUse();

console.log(`Now using ${green('default')}.`);
return;
}

const profiles = getProfiles();
const profiles = await getProfiles();

if (profiles?.[profile] === undefined) {
console.log(`${red('No corresponding profile found.')}`);
return;
}

saveUse(profile);
await saveUse(profile);

console.log(`Now using ${green(profile)}.`);
};
14 changes: 7 additions & 7 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const cliVersion = async () => {
};

const missionControlVersion = async () => {
const missionControl = getCliMissionControl();
const missionControl = await getCliMissionControl();

if (isNullish(missionControl)) {
console.log(
Expand All @@ -68,7 +68,7 @@ const missionControlVersion = async () => {

const missionControlParameters = {
missionControlId: missionControl,
...actorParameters()
...(await actorParameters())
};

const currentVersion = await missionControlVersionLib({
Expand All @@ -93,14 +93,14 @@ const satelliteVersion = async (args?: string[]) => {
const env = configEnv(args);
const {satellite: satelliteConfig} = await readJunoConfig(env);

const satellite = satelliteParameters({satellite: satelliteConfig, env});
const satellite = await satelliteParameters({satellite: satelliteConfig, env});
const {satelliteId} = satellite;

const currentVersion = await satelliteVersionLib({
satellite
});

const displayHint = `satellite "${satelliteKey(satelliteId)}"`;
const displayHint = `satellite "${await satelliteKey(satelliteId)}"`;

await checkSegmentVersion({
currentVersion,
Expand All @@ -110,7 +110,7 @@ const satelliteVersion = async (args?: string[]) => {
};

const orbitersVersion = async () => {
const orbiters = getCliOrbiters();
const orbiters = await getCliOrbiters();

if (isNullish(orbiters) || orbiters.length === 0) {
return;
Expand All @@ -119,14 +119,14 @@ const orbitersVersion = async () => {
const checkOrbiterVersion = async (orbiterId: string) => {
const orbiterParameters = {
orbiterId,
...actorParameters()
...(await actorParameters())
};

const currentVersion = await orbiterVersionLib({
orbiter: orbiterParameters
});

const displayHint = `orbiter "${orbiterKey(orbiterId)}"`;
const displayHint = `orbiter "${await orbiterKey(orbiterId)}"`;

await checkSegmentVersion({
currentVersion,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {getToken, getUse, isDefaultProfile} from '../configs/cli.config';
import {links} from '../services/links.services';

export const whoami = async (args?: string[]) => {
const {success} = info();
const {success} = await info();

if (!success) {
return;
Expand All @@ -14,14 +14,14 @@ export const whoami = async (args?: string[]) => {
await links(args);
};

const info = (): {success: boolean} => {
const profile = getUse();
const info = async (): Promise<{success: boolean}> => {
const profile = await getUse();

if (!isDefaultProfile(profile)) {
console.log(`👤 Profile: ${green(profile!)}`);
}

const token = getToken();
const token = await getToken();

if (isNullish(token)) {
console.log(`No controller found.`);
Expand Down
Loading

0 comments on commit e4208a0

Please sign in to comment.