1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

add groups feature

This commit is contained in:
Denis barbaron 2019-06-12 10:29:07 +02:00
parent 6fd750dad5
commit 7f5dc4c152
119 changed files with 12416 additions and 402 deletions

View file

@ -1,3 +1,7 @@
/**
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'api'
module.exports.describe = 'Start an API unit.'
@ -18,6 +22,18 @@ module.exports.builder = function(yargs) {
, array: true
, demand: true
})
.option('connect-push-dev', {
alias: 'pd'
, describe: 'Device-side ZeroMQ PULL endpoint to connect to.'
, array: true
, demand: true
})
.option('connect-sub-dev', {
alias: 'sd'
, describe: 'Device-side ZeroMQ PUB endpoint to connect to.'
, array: true
, demand: true
})
.option('port', {
alias: 'p'
, describe: 'The port to bind to.'
@ -53,6 +69,8 @@ module.exports.handler = function(argv) {
, endpoints: {
push: argv.connectPush
, sub: argv.connectSub
, pushdev: argv.connectPushDev
, subdev: argv.connectSubDev
}
})
}

View file

@ -0,0 +1,39 @@
/**
* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'generate-fake-group'
module.exports.builder = function(yargs) {
return yargs
.strict()
.option('n', {
alias: 'number'
, describe: 'How many groups to create.'
, type: 'number'
, default: 1
})
}
module.exports.handler = function(argv) {
var logger = require('../../util/logger')
var log = logger.createLogger('cli:generate-fake-group')
var fake = require('../../util/fakegroup')
var n = argv.number
function next() {
return fake.generate().then(function(email) {
log.info('Created fake group "%s"', email)
return --n ? next() : null
})
}
return next()
.then(function() {
process.exit(0)
})
.catch(function(err) {
log.fatal('Fake group creation had an error:', err.stack)
process.exit(1)
})
}

View file

@ -0,0 +1,39 @@
/**
* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'generate-fake-user'
module.exports.builder = function(yargs) {
return yargs
.strict()
.option('n', {
alias: 'number'
, describe: 'How many users to create.'
, type: 'number'
, default: 1
})
}
module.exports.handler = function(argv) {
var logger = require('../../util/logger')
var log = logger.createLogger('cli:generate-fake-user')
var fake = require('../../util/fakeuser')
var n = argv.number
function next() {
return fake.generate().then(function(email) {
log.info('Created fake user "%s"', email)
return --n ? next() : null
})
}
return next()
.then(function() {
process.exit(0)
})
.catch(function(err) {
log.fatal('Fake user creation had an error:', err.stack)
process.exit(1)
})
}

View file

@ -0,0 +1,51 @@
/**
* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'groups-engine'
module.exports.describe = 'Start the groups engine unit.'
module.exports.builder = function(yargs) {
return yargs
.env('STF_GROUPS_ENGINE')
.strict()
.option('connect-push', {
alias: 'c'
, describe: 'App-side ZeroMQ PULL endpoint to connect to.'
, array: true
, demand: true
})
.option('connect-sub', {
alias: 'u'
, describe: 'App-side ZeroMQ PUB endpoint to connect to.'
, array: true
, demand: true
})
.option('connect-push-dev', {
alias: 'pd'
, describe: 'Device-side ZeroMQ PULL endpoint to connect to.'
, array: true
, demand: true
})
.option('connect-sub-dev', {
alias: 'sd'
, describe: 'Device-side ZeroMQ PUB endpoint to connect to.'
, array: true
, demand: true
})
.epilog('Each option can be be overwritten with an environment variable ' +
'by converting the option to uppercase, replacing dashes with ' +
'underscores and prefixing it with `STF_GROUPS_ENGINE_` .)')
}
module.exports.handler = function(argv) {
return require('../../units/groups-engine')({
endpoints: {
push: argv.connectPush
, sub: argv.connectSub
, pushdev: argv.connectPushDev
, subdev: argv.connectSubDev
}
})
}

View file

@ -1,3 +1,7 @@
/**
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
var yargs = require('yargs')
var Promise = require('bluebird')
@ -12,9 +16,12 @@ var _argv = yargs.usage('Usage: $0 <command> [options]')
.command(require('./auth-oauth2'))
.command(require('./auth-openid'))
.command(require('./auth-saml2'))
.command(require('./groups-engine'))
.command(require('./device'))
.command(require('./doctor'))
.command(require('./generate-fake-device'))
.command(require('./generate-fake-user'))
.command(require('./generate-fake-group'))
.command(require('./local'))
.command(require('./log-rethinkdb'))
.command(require('./migrate'))

View file

@ -1,3 +1,7 @@
/**
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'local [serial..]'
module.exports.describe = 'Start a complete local development environment.'
@ -337,6 +341,17 @@ module.exports.handler = function(argv) {
, '--secret', argv.authSecret
, '--connect-push', argv.bindAppPull
, '--connect-sub', argv.bindAppPub
, '--connect-push-dev', argv.bindDevPull
, '--connect-sub-dev', argv.bindDevPub
])
// groups engine
, procutil.fork(path.resolve(__dirname, '..'), [
'groups-engine'
, '--connect-push', argv.bindAppPull
, '--connect-sub', argv.bindAppPub
, '--connect-push-dev', argv.bindDevPull
, '--connect-sub-dev', argv.bindDevPub
])
// websocket

View file

@ -1,3 +1,7 @@
/**
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
module.exports.command = 'migrate'
module.exports.describe = 'Migrates the database to the latest version.'
@ -10,13 +14,44 @@ module.exports.handler = function() {
var logger = require('../../util/logger')
var log = logger.createLogger('cli:migrate')
var db = require('../../db')
var dbapi = require('../../db/api')
const apiutil = require('../../util/apiutil')
const Promise = require('bluebird')
return db.setup()
.then(function() {
process.exit(0)
return new Promise(function(resolve, reject) {
setTimeout(function() {
return dbapi.getGroupByIndex(apiutil.ROOT, 'privilege').then(function(group) {
if (!group) {
const env = {
STF_ROOT_GROUP_NAME: 'Common'
, STF_ADMIN_NAME: 'administrator'
, STF_ADMIN_EMAIL: 'administrator@fakedomain.com'
}
for (const i in env) {
if (process.env[i]) {
env[i] = process.env[i]
}
}
return dbapi.createBootStrap(env)
}
return group
})
.then(function() {
resolve(true)
})
.catch(function(err) {
reject(err)
})
}, 1000)
})
})
.catch(function(err) {
log.fatal('Migration had an error:', err.stack)
process.exit(1)
})
.finally(function() {
process.exit(0)
})
}