Comparing version 0.0.7 to 0.1.0
104
index.js
#!/usr/bin/env node | ||
const { ArgumentParser } = require('argparse'); | ||
const { version } = require('./package.json'); | ||
/* | ||
gitlab-x command structure | ||
gitlab-x => print help | ||
gitlab-x help => print help | ||
gitlab-x [-v | --version] => print version | ||
gitlab-x get project <id | path> => get project json | ||
gitlab-x ci-lint => /ci/lint | ||
*/ | ||
import pkg from 'argparse'; | ||
const {ArgumentParser} = pkg; | ||
import { apiTest, getApiDriver, filterFields } from './util.js' | ||
import { readFileSync } from 'fs' | ||
const version = JSON.parse(readFileSync('./package.json')).version; | ||
const parser = new ArgumentParser({ | ||
description: 'Argparse example' | ||
description: 'gitlab-x: Gitlab Executor API Interface' | ||
}); | ||
parser.add_argument('action', {metavar: 'action', type: String, nargs: '?', default: 'get', help: 'action to be executed'}); | ||
parser.add_argument('parameters', {metavar: 'parameters', type: String, nargs: '*', help: 'action parameters to be used'}); | ||
parser.add_argument('-v', '--version', { action: 'version', version }); | ||
parser.add_argument('-f', '--foo', { help: 'foo bar' }); | ||
parser.add_argument('-b', '--bar', { help: 'bar foo' }); | ||
parser.add_argument('--baz', { help: 'baz bar' }); | ||
parser.add_argument('-t', '--access-token'); | ||
parser.add_argument('-u', '--url') | ||
parser.add_argument('--verbose', {action: 'store_true', help: 'increased console output'}) | ||
parser.add_argument('--json', {action: 'store_true', help: 'always print result as json, even if it is a single value'}) | ||
console.log("npx test"); | ||
const args = parser.parse_args() | ||
// Check presence of AT and URL | ||
// Only use ENV variables when args are not set | ||
if(typeof process.env.GITLAB_AT === 'undefined' && typeof args.access_token === 'undefined') { | ||
throw new Error("Error: no access token specified. Either set it as ENV variable 'GITLAB_AT' or pass it with [-t | --access-token]") | ||
} | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = process.env.GITLAB_AT; | ||
} | ||
if(typeof process.env.GITLAB_URL === 'undefined' && typeof args.url === 'undefined') { | ||
throw new Error("Error: no GitLab URL specified. Either set it as ENV variable 'GITLAB_URL' or pass it with [-u | --url]") | ||
} | ||
else if(typeof args.url === 'undefined') { | ||
args.url = process.env.GITLAB_URL; | ||
} | ||
if(args.verbose) { | ||
console.dir(args); | ||
} | ||
(async () => { | ||
if(!await apiTest(args)) { | ||
throw new Error(`Error: API at '${args.url}' not accessible with given access token`) | ||
} | ||
doAction(args); | ||
})(); | ||
async function doAction(args) { | ||
const action = args.action; | ||
if(args.verbose) console.log(`Action is '${action}'`); | ||
switch(action) { | ||
case "get": | ||
await doGetAction(args); | ||
break; | ||
default: | ||
throw new Error(`Error: '${action}' is an invalid action`); | ||
} | ||
} | ||
async function doGetAction(args) { | ||
// get action syntax: | ||
// gitlab-x get <object type> <object identifier> [<object fields>...] | ||
let parameters = args.parameters; | ||
if(parameters.length < 2) { | ||
throw new Error(`Error: not enough parameter for 'get' action`) | ||
} | ||
const objectType = parameters.shift(); | ||
const objectIdentifier = parameters.shift(); | ||
// remaining parameters are object fields | ||
const fields = parameters; | ||
switch(objectType) { | ||
case "project": | ||
if(args.verbose) console.log(`Doing 'GET' > 'project' with identifier '${objectIdentifier}' and fields '${fields}'`); | ||
await getProject(args, objectIdentifier, fields); | ||
break; | ||
default: | ||
throw new Error(`Error: object type '${objectType}' is not supported`) | ||
} | ||
} | ||
async function getProject(args, objectIdentifier, fields) { | ||
const api = getApiDriver(args); | ||
const project = await api.getProject(objectIdentifier); | ||
const result = filterFields(args, project, fields); | ||
console.dir(result); | ||
} |
{ | ||
"name": "gitlab-x", | ||
"version": "0.0.7", | ||
"description": "GitLab API interface", | ||
"version": "0.1.0", | ||
"description": "GitLab Executor API Interface", | ||
"repository": "https://github.com/mxcd/gitlab-api", | ||
@@ -14,4 +14,11 @@ "main": "index.js", | ||
}, | ||
"type": "module", | ||
"author": "Max Partenfelder", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"dependencies": { | ||
"argparse": "^2.0.1", | ||
"axios": "^0.21.0", | ||
"diff": "^5.0.0", | ||
"fs": "0.0.1-security" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
12161
6
310
1
4
Yes
4
6
+ Addedargparse@^2.0.1
+ Addedaxios@^0.21.0
+ Addeddiff@^5.0.0
+ Addedfs@0.0.1-security
+ Addedargparse@2.0.1(transitive)
+ Addedaxios@0.21.4(transitive)
+ Addeddiff@5.2.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedfs@0.0.1-security(transitive)