Przeglądaj źródła

switched credentialmanager for git

master
guest 3 lat temu
rodzic
commit
7f9272abc8
3 zmienionych plików z 4360 dodań i 2500 usunięć
  1. 1407
    342
      elxr.js
  2. 2817
    2088
      i.js
  3. 136
    70
      index.js

+ 1407
- 342
elxr.js
Plik diff jest za duży
Wyświetl plik


+ 2817
- 2088
i.js
Plik diff jest za duży
Wyświetl plik


+ 136
- 70
index.js Wyświetl plik

@@ -8,7 +8,20 @@ Tasq.addlistener(statuslog.statuslog)
var cli = require('./cliverse')
var nodeShellExec = cli.nodeShellExec;
var chalk = require('chalk')
const homedir = require('os').homedir();

// singleton one time lazy
var getCredentials = function(){

// First call
var creds = fs.readFileSync(path.normalize(`${homedir}/.elxrcredentials`), { encoding: 'utf8' });
var creds = creds.split('\n').map( c => c.trim() && new URL(c));
console.log(creds);

// Subsequent calls
getCredentials = ()=>{ return creds }
return getCredentials();
}

const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
@@ -82,71 +95,8 @@ console.dir(processedArgs)

//

// elxr cli operations
var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
, remote : true, 'c' : true, 'h' : true
, httpget : true, getuser : true
, 'switch user' : true
, 'switch' : true
// , 'undefined' : true
}

var reconfirmcmds = { create : true }

var subcommandlabels = {
remote : (`remote ${processedArgs._[1] || ''}`).trim()
, switch : (`switch ${processedArgs._[1] || ''}`).trim()
}

var cmds = {
remote : {
// return a interpreted set of arguments for this comd run context.
interpret() {
return { cmd : subcommandlabels['remote'], runchoice : 'c' }
}
}
, switch : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2]
, reposerver : __default.reposerver
}
}
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument...
}
, 'switch user' : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] }
}
, getPossiblePrompts(){ return { username : true } } // Requires only one argument...
}
}

var interpretrun = function(){

var cmd = processedArgs._[0];
var clioverrides = { cmd }
processedArgs.node_env ? clioverrides.node_env = processedArgs.node_env
: (process.env.NODE_ENV && process.env.NODE_ENV.trim())
? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) : null;
return cmds[cmd] ? cmds[cmd].interpret() : (function(){
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
// return clioverrides
cmds[cmd] = {
interpret() {
return Object.assign(clioverrides, { cmd, runchoice : 'c' })
}
, getPossiblePrompts(){ return { cmd, username : true, password : true,
instanceName : true, instanceType : true, reposerver : true } }
}
return cmds[cmd].interpret()
})()
}

var clioverrides = interpretrun()
console.dir(clioverrides)

// Object.keys(clioverrides).forEach( prop => { })

@@ -1921,9 +1871,8 @@ var op = {

g[processedArgs._[1]]();
}

, 'create' : () => {
return createInstance(selectedinstance) }
, 'create' : () => { return createInstance(selectedinstance) }

, 'httpget' : () => {
// RESTAPI.get({
@@ -1936,15 +1885,125 @@ var op = {
return createInstance(selectedinstance)
}

, 'getuser' : ()=>{
return prerequisites.git.getuser().then(u=>{ console.log(u)})
, 'getuser' : ()=>{ return prerequisites.git.getuser().then(u=>{ console.log(u)}) }
, 'switch user' : (tousername)=>{ return GIT['switch user'](tousername) }
}

// elxr cli operations
var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
, remote : true, 'c' : true, 'h' : true
, httpget : true, getuser : true
, 'switch user' : true
, 'switch' : true
// , 'undefined' : true
}

var reconfirmcmds = { create : true }

var subcommandlabels = {
remote : (`remote ${processedArgs._[1] || ''}`).trim()
, switch : (`switch ${processedArgs._[1] || ''}`).trim()
}

var cmds = {
remote : {
// return a interpreted set of arguments for this comd run context.
interpret() {
return { cmd : subcommandlabels['remote'], runchoice : 'c' }
}
}
, switch : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2]
, reposerver : __default.reposerver
}
}
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument...
}
, 'switch user' : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] }
}
, getPossiblePrompts(){ return { username : true } } // Requires only one argument...
}

// Flat linear structure. Every subcommand should have a top level 'label'
, 'users' : {
// default to the users list
subcommands : { list : {} }
, cmdFn : ()=>getCredentials() // default
, cmd : 'users'
, noprerequisites : true
}
, 'users list' : {
cmdFn : ()=>getCredentials()
, cmd : 'users list'
, noprerequisites : true
}
}

var elxrcmd = (function(){

, 'switch user' : (tousername)=>{
return GIT['switch user'](tousername)
__cmdprototype = function(){}
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() }

var __cmd = {
interpret() { return { cmd : this.cmd } }
, getPossiblePrompts(){ return {} } // Requires only one argument...
, cmdFn : ()=>{ throw "Elxr Unknown command."}
, finalized : true
}

function __createO(o){
if(o.finalized) return o;
var subs = Object.keys(cmds[o.cmd].subcommands || {})
console.log(subs)
console.log(o)
subs.forEach(sub=>elxrcmd.create( cmds[subcommandlabelFor(o.cmd, sub)] ))
var created = utils.assign_strict({}, __cmd, cmds[o.cmd], o)
cmds[o.cmd] = created;
op[o.cmd] = created.cmdFn;
noprerequisites[o.cmd] = created.noprerequisites
return created.cmdFn;
}

function create(o){ return __createO(o) }

__cmdprototype.create = create;

return __cmdprototype;
})()

elxrcmd.create(cmds['users'])

var interpretrun = function(){

var cmd = processedArgs._[0];
var clioverrides = { cmd }
processedArgs.node_env ? clioverrides.node_env = processedArgs.node_env
: (process.env.NODE_ENV && process.env.NODE_ENV.trim())
? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) : null;


return cmds[cmd] ? cmds[cmd].interpret() : (function(){
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
// return clioverrides
cmds[cmd] = {
interpret() {
return Object.assign(clioverrides, { cmd, runchoice : 'c' })
}
, getPossiblePrompts(){ return { cmd, username : true, password : true,
instanceName : true, instanceType : true, reposerver : true } }
}
return cmds[cmd].interpret()
})()
}

var clioverrides = interpretrun()
console.dir(clioverrides)

var util = require('util');
var cliname = 'elxr';
var ver = '1.1';
@@ -2330,6 +2389,13 @@ var acquireData = function(slections){
return any(configPriority.map(cfg => { return function() { return instanceData[cfg](slections) } } ), true, true)
}

// Git Credential storage...
// notepad C:/Program Files/Git/etc/gitconfig
// git config --global --unset credential
// git config --edit --system
// git config --global credential.helper "store --file ~/gitcredentials"
// git credential fill
// git credential-store --file ~/git.store store
var __acquireConfig = function (selected, owner, clusternodename, configrepo, errHandler) {

configrepo = configrepo || selected.instanceName + '-config-' + selected.node_env;

Ładowanie…
Anuluj
Zapisz