-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a430fc8
commit 2aa7a8b
Showing
7 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// @ts-nocheck | ||
/* eslint-disable no-console */ | ||
|
||
// import chalk from 'chalk' | ||
import meow from 'meow' | ||
import ora from 'ora' | ||
|
||
import { outputFlags } from '../../flags/index.js' | ||
// import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' | ||
import { InputError } from '../../utils/errors.js' | ||
import { prepareFlags } from '../../utils/flags.js' | ||
import { printFlagList } from '../../utils/formatting.js' | ||
// import { getDefaultKey, setupSdk } from '../../utils/sdk.js' | ||
|
||
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ | ||
export const create = { | ||
description: 'Create a repository in an organization', | ||
async run (argv, importMeta, { parentName }) { | ||
const name = parentName + ' create' | ||
|
||
const input = setupCommand(name, create.description, argv, importMeta) | ||
if (input) { | ||
const spinnerText = 'Creating repository... \n' | ||
const spinner = ora(spinnerText).start() | ||
await createRepo(input.orgSlug, input, spinner) | ||
} | ||
} | ||
} | ||
|
||
const listFullScanFlags = prepareFlags({ | ||
sort: { | ||
type: 'string', | ||
shortFlag: 's', | ||
default: 'created_at', | ||
description: 'Sorting option (`name` or `created_at`) - default is `created_at`', | ||
}, | ||
direction: { | ||
type: 'string', | ||
shortFlag: 'd', | ||
default: 'desc', | ||
description: 'Direction option (`desc` or `asc`) - Default is `desc`', | ||
}, | ||
perPage: { | ||
type: 'number', | ||
shortFlag: 'pp', | ||
default: 30, | ||
description: 'Results per page - Default is 30', | ||
}, | ||
page: { | ||
type: 'number', | ||
shortFlag: 'p', | ||
default: 1, | ||
description: 'Page number - Default is 1', | ||
}, | ||
fromTime: { | ||
type: 'string', | ||
shortFlag: 'f', | ||
default: '', | ||
description: 'From time - as a unix timestamp', | ||
}, | ||
untilTime: { | ||
type: 'string', | ||
shortFlag: 'u', | ||
default: '', | ||
description: 'Until time - as a unix timestamp', | ||
} | ||
}) | ||
|
||
// Internal functions | ||
|
||
/** | ||
* @typedef CommandContext | ||
* @property {boolean} outputJson | ||
* @property {boolean} outputMarkdown | ||
* @property {string} orgSlug | ||
* @property {string} sort | ||
* @property {string} direction | ||
* @property {number} perPage | ||
* @property {number} page | ||
* @property {string} fromTime | ||
* @property {string} untilTime | ||
*/ | ||
|
||
/** | ||
* @param {string} name | ||
* @param {string} description | ||
* @param {readonly string[]} argv | ||
* @param {ImportMeta} importMeta | ||
* @returns {void|CommandContext} | ||
*/ | ||
function setupCommand (name, description, argv, importMeta) { | ||
const flags = { | ||
...outputFlags, | ||
...listFullScanFlags | ||
} | ||
|
||
const cli = meow(` | ||
Usage | ||
$ ${name} <org slug> | ||
Options | ||
${printFlagList(flags, 6)} | ||
Examples | ||
$ ${name} FakeOrg | ||
`, { | ||
argv, | ||
description, | ||
importMeta, | ||
flags | ||
}) | ||
|
||
const { | ||
json: outputJson, | ||
markdown: outputMarkdown, | ||
sort, | ||
direction, | ||
perPage, | ||
page, | ||
fromTime, | ||
untilTime | ||
} = cli.flags | ||
|
||
if (!cli.input[0]) { | ||
throw new InputError(`Please specify an organization slug. \n | ||
Example: | ||
socket scan list FakeOrg | ||
`) | ||
} | ||
|
||
const orgSlug = cli.input[0] || '' | ||
|
||
return { | ||
outputJson, | ||
outputMarkdown, | ||
orgSlug, | ||
sort, | ||
direction, | ||
perPage, | ||
page, | ||
fromTime, | ||
untilTime | ||
} | ||
} | ||
|
||
/** | ||
* @typedef FullScansData | ||
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data | ||
*/ | ||
|
||
/** | ||
* @param {string} orgSlug | ||
* @param {CommandContext} input | ||
* @param {import('ora').Ora} spinner | ||
* @returns {Promise<void|FullScansData>} | ||
*/ | ||
async function createRepo (orgSlug, input, spinner) { | ||
// const socketSdk = await setupSdk(getDefaultKey()) | ||
console.log(input) | ||
|
||
// return { | ||
// // data: result.data | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// @ts-nocheck | ||
/* eslint-disable no-console */ | ||
|
||
// import chalk from 'chalk' | ||
import meow from 'meow' | ||
import ora from 'ora' | ||
|
||
import { outputFlags } from '../../flags/index.js' | ||
// import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' | ||
import { InputError } from '../../utils/errors.js' | ||
import { printFlagList } from '../../utils/formatting.js' | ||
// import { getDefaultKey, setupSdk } from '../../utils/sdk.js' | ||
|
||
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ | ||
export const del = { | ||
description: 'Delete a repository in an organization', | ||
async run (argv, importMeta, { parentName }) { | ||
const name = parentName + ' del' | ||
|
||
const input = setupCommand(name, del.description, argv, importMeta) | ||
if (input) { | ||
const spinnerText = 'Deleting repository... \n' | ||
const spinner = ora(spinnerText).start() | ||
await deleteRepository(input.orgSlug, input, spinner) | ||
} | ||
} | ||
} | ||
|
||
// Internal functions | ||
|
||
/** | ||
* @typedef CommandContext | ||
* @property {boolean} outputJson | ||
* @property {boolean} outputMarkdown | ||
* @property {string} orgSlug | ||
*/ | ||
|
||
/** | ||
* @param {string} name | ||
* @param {string} description | ||
* @param {readonly string[]} argv | ||
* @param {ImportMeta} importMeta | ||
* @returns {void|CommandContext} | ||
*/ | ||
function setupCommand (name, description, argv, importMeta) { | ||
const flags = { | ||
...outputFlags | ||
} | ||
|
||
const cli = meow(` | ||
Usage | ||
$ ${name} <org slug> | ||
Options | ||
${printFlagList(flags, 6)} | ||
Examples | ||
$ ${name} FakeOrg | ||
`, { | ||
argv, | ||
description, | ||
importMeta, | ||
flags | ||
}) | ||
|
||
const { | ||
json: outputJson, | ||
markdown: outputMarkdown | ||
} = cli.flags | ||
|
||
if (!cli.input[0]) { | ||
throw new InputError(`Please specify an organization slug. \n | ||
Example: | ||
socket scan list FakeOrg | ||
`) | ||
} | ||
|
||
const orgSlug = cli.input[0] || '' | ||
|
||
return { | ||
outputJson, | ||
outputMarkdown, | ||
orgSlug | ||
} | ||
} | ||
|
||
/** | ||
* @typedef RepositoryData | ||
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data | ||
*/ | ||
|
||
/** | ||
* @param {string} orgSlug | ||
* @param {CommandContext} input | ||
* @param {import('ora').Ora} spinner | ||
* @returns {Promise<void|RepositoryData>} | ||
*/ | ||
async function deleteRepository (orgSlug, input, spinner) { | ||
// const socketSdk = await setupSdk(getDefaultKey()) | ||
console.log(input) | ||
|
||
// return { | ||
// // data: result.data | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @ts-nocheck | ||
import { create } from './create.js' | ||
import { del } from './delete.js' | ||
import { list } from './list.js' | ||
import { update } from './update.js' | ||
import { view } from './view.js' | ||
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js' | ||
|
||
const description = 'Repositories related commands' | ||
|
||
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ | ||
export const repo = { | ||
description, | ||
run: async (argv, importMeta, { parentName }) => { | ||
await meowWithSubcommands( | ||
{ | ||
create, | ||
view, | ||
list, | ||
del, | ||
update | ||
}, | ||
{ | ||
argv, | ||
description, | ||
importMeta, | ||
name: parentName + ' repo', | ||
} | ||
) | ||
} | ||
} |
Oops, something went wrong.