Skip to content

Commit

Permalink
Manage users
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoberger committed Mar 10, 2017
1 parent deb6cdc commit 086eb64
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
5 changes: 2 additions & 3 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var prompt = require('prompt-sync')();
var crypto = require('crypto');
var fs = require('fs');
var jsonfile = require('jsonfile');
var uslug = require('uslug');
var path = require('path');

var utils = require('./utils');
Expand Down Expand Up @@ -42,8 +43,7 @@ exports.api = function(args, opts) {
return;
}

/*
var apiId = crypto.randomBytes(7).toString('hex');
var apiId = swagger.info.title ? uslug(swagger.info.title) : crypto.randomBytes(7).toString('hex');

if(!swagger['x-api-id']) {
console.log('Your Swagger file needs a unique "x-api-id" property to work. Do you want us to add it automatically?');
Expand Down Expand Up @@ -75,7 +75,6 @@ exports.api = function(args, opts) {

}
}
*/

utils.removeMetadata(swagger);

Expand Down
27 changes: 27 additions & 0 deletions lib/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var request = require('request');
var jsonfile = require('jsonfile');

exports.swagger = true;
exports.login = true;
exports.desc = "Add a user";

exports.run = function(config, info) {
var email = info.args[1];
console.log("Granting " + email.yellow + " push access to " + info.swagger['x-api-id'].yellow + "!");
console.log("");

var user = jsonfile.readFileSync(config.apiFile);

console.log(user.token, config.host.url + '/add');

request.post(config.host.url + '/add', {
'form': {
'user': user.token,
'email': email,
'repo': info.swagger['x-api-id'],
}
}, function() {
console.log("Success! ".green + "User has been added.");
process.exit();
});
};
2 changes: 1 addition & 1 deletion lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.run = function(config, info) {
commands: [],
},
'utility': {
desc: 'Utility functions for working locally',
desc: 'Utility functions',
commands: [],
},
};
Expand Down
3 changes: 2 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs');
var crypto = require('crypto');
var YAML = require('json2yaml');
var utils = require('../utils');
var uslug = require('uslug');

exports.swagger = false;
exports.login = false;
Expand Down Expand Up @@ -103,7 +104,7 @@ exports.run = function(config, info) {
inquirer.prompt(questions).then(function (answers) {
var swagger = {
'swagger': '2.0',
//'x-api-id': crypto.randomBytes(7).toString('hex'),
'x-api-id': uslug(answers['info.title']) || crypto.randomBytes(7).toString('hex'),
'info': {
'version': answers['info.version'],
'title': answers['info.title'],
Expand Down
21 changes: 21 additions & 0 deletions lib/manage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var colors = require('colors');
var utils = require('../utils');

exports.swagger = false;
exports.login = false;
exports.category = "utility";
exports.desc = "Manage users and versions";

exports.run = function(config, info) {
console.log("You can modify your settings from here!");
console.log("");
console.log("GRANT PUSH ACCESS".cyan);
console.log("Run the following command to add them (must match their GitHub email):");
console.log("");
console.log(" $ oai add [email protected]".grey);
console.log("");
console.log("");

process.exit();
};

9 changes: 0 additions & 9 deletions lib/test.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"swagger-inline": "0.0.7",
"swagger-parser": "^3.4.1",
"swagger2-to-postman": "^1.1.0",
"uslug": "^1.0.4",
"yamljs": "^0.2.8"
},
"devDependencies": {
Expand Down

0 comments on commit 086eb64

Please sign in to comment.