Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-credential-env

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-credential-env - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

.editorconfig

25

helper.js
#!/usr/bin/env node
var opts = require('minimist')(process.argv.slice(2), {
alias: {u: 'username', p: 'password'}
alias: { u: 'username', p: 'password' }
});
envCredential(opts);
// a `get` action is expected, otherwise exit non-zero
if (!opts._.length || opts._[0].toLowerCase() !== 'get') process.exit(1);
function envCredential(opts) {
// only respond to get actions
if (!opts._.length || opts._[0].toLowerCase() !== 'get') process.exit(1);
// load value from environment variable if specified, otherwise use blank value
var username = opts.username ? process.env[opts.username] : '';
var password = opts.password ? process.env[opts.password] : '';
var username = opts.username ? process.env[opts.username] : '';
var password = opts.password ? process.env[opts.password] : '';
// exit non-zero if a specified environment variable is not set
if (username === undefined || password === undefined) process.exit(1);
if (username === undefined) process.exit(1);
if (password === undefined) process.exit(1);
process.stdout.write('username=' + username + '\n');
process.stdout.write('password=' + password + '\n');
}
process.stdout.write(
'username=' + username + '\n' +
'password=' + password + '\n'
);
{
"name": "git-credential-env",
"version": "0.4.0",
"version": "1.0.0",
"description": "A git credential helper for setting git credentials from environment variables",
"keywords": [],
"keywords": [
"git",
"config",
"credential",
"helper",
"environment"
],
"contributors": [

@@ -19,8 +25,8 @@ "Ryan Tsao <ryan.j.tsao@gmail.com>",

"dependencies": {
"minimist": "^1.2.0"
"minimist": "1.2.0"
},
"devDependencies": {
"tape": "^4.4.0"
"tape": "4.4.0"
},
"license": "MIT"
}
# git-credential-env
[![Version][version-badge]][version-href]
[![Build status][build-badge]][build-href]
[![Stability][stability-badge]][stability-href]
A git credential helper for setting git credentials from environment variables. Useful for CI deployments with Travis.
A Git credential helper for setting Git credentials from environment variables. Useful for CI deployments with [Travis CI](https://travis-ci.org), [CircleCI](https://circleci.com), and others.
## quick example
#### local install
## Quick Example
**Global Installation**
```bash
npm install git-credential-env
npm install -g git-credential-env
GIT_USER=foo
GIT_PASS=bar
git config --global credential.helper "$PWD/node_modules/.bin/git-credential-env -u=GIT_USER -p=GIT_PASS"
git config credential.helper "env --username=GIT_USER --password=GIT_PASS"
```
#### global install
**Local Installation** *(recommended)*
```bash
npm install git-credential-env -g
npm install git-credential-env
GIT_USER=foo
GIT_PASS=bar
git config --global credential.helper "env --username=GIT_USER --password=GIT_PASS"
git config credential.helper "$PWD/node_modules/.bin/git-credential-env --username=GIT_USER --password=GIT_PASS"
```
The git username will be `foo` and the password will be `bar`, i.e. git-credential-env will return:
In both examples, the username `foo` and password `bar` will be provided as credentials when requested by Git.
```
username=foo
password=bar
```
You can read more about git credential helpers here: http://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
## usage
```
## Usage
```bash
Usage: git-credential-env get {OPTIONS}

@@ -40,10 +38,19 @@

--username, -u The name of environment variable containing the git username
--username, -u The name of environment variable containing the Git username
--password, -p The name of environment variable containing the git password
--password, -p The name of environment variable containing the Git password
```
## Documentation
See the [Wiki](https://github.com/L33T-KR3W/git-credential-env/wiki) for full documentation.
[version-badge]: https://img.shields.io/npm/v/git-credential-env.svg
[version-href]: https://www.npmjs.com/package/git-credential-env
[build-badge]: https://travis-ci.org/L33T-KR3W/git-credential-env.svg
[build-href]: https://travis-ci.org/L33T-KR3W/git-credential-env
[stability-badge]: https://img.shields.io/badge/stability-locked-blue.svg
[stability-href]: https://nodejs.org/api/documentation.html#documentation_stability_index

@@ -7,71 +7,72 @@ var test = require('tape');

test('test failure if username env var empty', function (t) {
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
});
test('test failure if password env var empty', function (t) {
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
});
test('test failure if username and password env vars empty', function (t) {
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME_WRONG --password=GIT_AUTH_PASSWORD_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME_WRONG --password=GIT_AUTH_PASSWORD_WRONG';
t.throws(execSync.bind(null, cmd));
t.end();
});
test('test success if nothing specified', function (t) {
var cmd = ENV_VARS + './helper.js get';
t.equal(execSyncToString(cmd), 'username=\npassword=\n');
t.end();
var cmd = ENV_VARS + './helper.js get';
t.equal(execSyncToString(cmd), 'username=\npassword=\n');
t.end();
});
test('test success if username specified', function (t) {
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=\n');
t.end();
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=\n');
t.end();
});
test('test success if password specified', function (t) {
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=\npassword=swag\n');
t.end();
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=\npassword=swag\n');
t.end();
});
test('test success if username and password specified', function (t) {
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME --password=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
var cmd = ENV_VARS + './helper.js get --username=GIT_AUTH_USERNAME --password=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
});
test('test success if username and password specified with alias', function (t) {
var cmd = ENV_VARS + './helper.js get -u=GIT_AUTH_USERNAME -p=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
var cmd = ENV_VARS + './helper.js get -u=GIT_AUTH_USERNAME -p=GIT_AUTH_PASSWORD';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
});
test('test success if username and password specified (reversed order)', function (t) {
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
var cmd = ENV_VARS + './helper.js get --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.equal(execSyncToString(cmd), 'username=yolo\npassword=swag\n');
t.end();
});
test('test failure if no action', function (t) {
var cmd = ENV_VARS + './helper.js --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, cmd));
t.end();
var cmd = ENV_VARS + './helper.js --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, cmd));
t.end();
});
test('test failure if action not get', function (t) {
var storeCmd = ENV_VARS + './helper.js store --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, storeCmd));
var eraseCmd = ENV_VARS + './helper.js erase --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, eraseCmd));
t.end();
var storeCmd = ENV_VARS + './helper.js store --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, storeCmd));
var eraseCmd = ENV_VARS + './helper.js erase --password=GIT_AUTH_PASSWORD --username=GIT_AUTH_USERNAME';
t.throws(execSync.bind(null, eraseCmd));
t.end();
});
function execSyncToString(cmd) {
return String(execSync(cmd));
return String(execSync(cmd));
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc