Skip to content

Commit

Permalink
add groups feature
Browse files Browse the repository at this point in the history
  • Loading branch information
denis99999 committed Jun 12, 2019
1 parent 6fd750d commit 7f5dc4c
Show file tree
Hide file tree
Showing 119 changed files with 12,491 additions and 477 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Copyright © 2013 CyberAgent, Inc.
Copyright © 2016 The OpenSTF Project
Copyright © 2019 Orange SA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 18 additions & 0 deletions lib/cli/api/index.js
Original file line number Diff line number Diff line change
@@ -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.'
Expand All @@ -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.'
Expand Down Expand Up @@ -53,6 +69,8 @@ module.exports.handler = function(argv) {
, endpoints: {
push: argv.connectPush
, sub: argv.connectSub
, pushdev: argv.connectPushDev
, subdev: argv.connectSubDev
}
})
}
39 changes: 39 additions & 0 deletions lib/cli/generate-fake-group/index.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
39 changes: 39 additions & 0 deletions lib/cli/generate-fake-user/index.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
51 changes: 51 additions & 0 deletions lib/cli/groups-engine/index.js
Original file line number Diff line number Diff line change
@@ -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
}
})
}
7 changes: 7 additions & 0 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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'))
Expand Down
15 changes: 15 additions & 0 deletions lib/cli/local/index.js
Original file line number Diff line number Diff line change
@@ -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.'
Expand Down Expand Up @@ -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
Expand Down
37 changes: 36 additions & 1 deletion lib/cli/migrate/index.js
Original file line number Diff line number Diff line change
@@ -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.'
Expand All @@ -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: '[email protected]'
}
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)
})
}
Loading

0 comments on commit 7f5dc4c

Please sign in to comment.