feat: auth + storage config improvements
This commit is contained in:
@@ -2,6 +2,7 @@ const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -51,8 +52,22 @@ module.exports = class Authentication extends Model {
|
||||
title: strategy.title,
|
||||
isEnabled: false,
|
||||
useForm: strategy.useForm,
|
||||
config: _.reduce(strategy.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
config: _.transform(strategy.props, (result, value, key) => {
|
||||
if (_.isPlainObject(value)) {
|
||||
let cfgValue = {
|
||||
type: typeof value.type(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
|
||||
}
|
||||
if (_.isArray(value.enum)) {
|
||||
cfgValue.enum = value.enum
|
||||
}
|
||||
_.set(result, key, cfgValue)
|
||||
} else {
|
||||
_.set(result, key, {
|
||||
type: typeof value(),
|
||||
value: commonHelper.getTypeDefaultValue(value)
|
||||
})
|
||||
}
|
||||
return result
|
||||
}, {}),
|
||||
selfRegistration: false,
|
||||
|
||||
@@ -2,6 +2,7 @@ const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -43,8 +44,22 @@ module.exports = class Storage extends Model {
|
||||
title: target.title,
|
||||
isEnabled: false,
|
||||
mode: 'push',
|
||||
config: _.reduce(target.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
config: _.transform(target.props, (result, value, key) => {
|
||||
if (_.isPlainObject(value)) {
|
||||
let cfgValue = {
|
||||
type: typeof value.type(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
|
||||
}
|
||||
if (_.isArray(value.enum)) {
|
||||
cfgValue.enum = value.enum
|
||||
}
|
||||
_.set(result, key, cfgValue)
|
||||
} else {
|
||||
_.set(result, key, {
|
||||
type: typeof value(),
|
||||
value: commonHelper.getTypeDefaultValue(value)
|
||||
})
|
||||
}
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
|
||||
@@ -19,9 +19,9 @@ module.exports = {
|
||||
let strategies = await WIKI.db.authentication.getStrategies()
|
||||
strategies = strategies.map(stg => ({
|
||||
...stg,
|
||||
config: _.transform(stg.config, (res, value, key) => {
|
||||
res.push({ key, value })
|
||||
}, [])
|
||||
config: _.sortBy(_.transform(stg.config, (res, value, key) => {
|
||||
res.push({ key, value: JSON.stringify(value) })
|
||||
}, []), 'key')
|
||||
}))
|
||||
if (args.filter) { strategies = graphHelper.filter(strategies, args.filter) }
|
||||
if (args.orderBy) { strategies = graphHelper.orderBy(strategies, args.orderBy) }
|
||||
@@ -57,7 +57,7 @@ module.exports = {
|
||||
await WIKI.db.authentication.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, value.key, value.value)
|
||||
_.set(result, `${value.key}.value`, value.value)
|
||||
return result
|
||||
}, {}),
|
||||
selfRegistration: str.selfRegistration,
|
||||
|
||||
@@ -13,11 +13,11 @@ module.exports = {
|
||||
StorageQuery: {
|
||||
async targets(obj, args, context, info) {
|
||||
let targets = await WIKI.db.storage.getTargets()
|
||||
targets = targets.map(stg => ({
|
||||
...stg,
|
||||
config: _.transform(stg.config, (res, value, key) => {
|
||||
res.push({ key, value })
|
||||
}, [])
|
||||
targets = targets.map(tgt => ({
|
||||
...tgt,
|
||||
config: _.sortBy(_.transform(tgt.config, (res, value, key) => {
|
||||
res.push({ key, value: JSON.stringify(value) })
|
||||
}, []), 'key')
|
||||
}))
|
||||
if (args.filter) { targets = graphHelper.filter(targets, args.filter) }
|
||||
if (args.orderBy) { targets = graphHelper.orderBy(targets, args.orderBy) }
|
||||
@@ -32,7 +32,7 @@ module.exports = {
|
||||
isEnabled: tgt.isEnabled,
|
||||
mode: tgt.mode,
|
||||
config: _.reduce(tgt.config, (result, value, key) => {
|
||||
_.set(result, value.key, value.value)
|
||||
_.set(result, `${value.key}.value`, value.value)
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', tgt.key)
|
||||
|
||||
17
server/helpers/common.js
Normal file
17
server/helpers/common.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Get default value of type
|
||||
*
|
||||
* @param {any} Type Primitive Type
|
||||
* @returns Default value
|
||||
*/
|
||||
getTypeDefaultValue (Type) {
|
||||
if (_.isArray(Type)) {
|
||||
return _.head(Type)
|
||||
} else {
|
||||
return new Type()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,11 @@ module.exports = {
|
||||
key: 'auth0',
|
||||
title: 'Auth0',
|
||||
useForm: false,
|
||||
props: ['domain', 'clientId', 'clientSecret'],
|
||||
props: {
|
||||
domain: String,
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('auth0',
|
||||
new Auth0Strategy({
|
||||
|
||||
@@ -10,7 +10,18 @@ module.exports = {
|
||||
key: 'azure',
|
||||
title: 'Azure Active Directory',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'resource', 'tenant'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String,
|
||||
resource: {
|
||||
type: String,
|
||||
default: '00000002-0000-0000-c000-000000000000'
|
||||
},
|
||||
tenant: {
|
||||
type: String,
|
||||
default: 'YOUR_TENANT.onmicrosoft.com'
|
||||
}
|
||||
},
|
||||
init (passport, conf) {
|
||||
const jwt = require('jsonwebtoken')
|
||||
passport.use('azure_ad_oauth2',
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'discord',
|
||||
title: 'Discord',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('discord',
|
||||
new DiscordStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'dropbox',
|
||||
title: 'Dropbox',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('dropbox',
|
||||
new DropboxStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'facebook',
|
||||
title: 'Facebook',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('facebook',
|
||||
new FacebookStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'github',
|
||||
title: 'GitHub',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('github',
|
||||
new GitHubStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'google',
|
||||
title: 'Google',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('google',
|
||||
new GoogleStrategy({
|
||||
|
||||
@@ -11,7 +11,30 @@ module.exports = {
|
||||
key: 'ldap',
|
||||
title: 'LDAP / Active Directory',
|
||||
useForm: true,
|
||||
props: ['url', 'bindDn', 'bindCredentials', 'searchBase', 'searchFilter', 'tlsEnabled', 'tlsCertPath'],
|
||||
props: {
|
||||
url: {
|
||||
type: String,
|
||||
default: 'ldap://serverhost:389'
|
||||
},
|
||||
bindDn: {
|
||||
type: String,
|
||||
default: `cn='root'`
|
||||
},
|
||||
bindCredentials: String,
|
||||
searchBase: {
|
||||
type: String,
|
||||
default: 'o=users,o=example.com'
|
||||
},
|
||||
searchFilter: {
|
||||
type: String,
|
||||
default: '(uid={{username}})'
|
||||
},
|
||||
tlsEnabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
tlsCertPath: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('ldapauth',
|
||||
new LdapStrategy({
|
||||
|
||||
@@ -10,7 +10,7 @@ module.exports = {
|
||||
key: 'local',
|
||||
title: 'Local',
|
||||
useForm: true,
|
||||
props: [],
|
||||
props: {},
|
||||
init (passport, conf) {
|
||||
passport.use('local',
|
||||
new LocalStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'microsoft',
|
||||
title: 'Microsoft Account',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('microsoft',
|
||||
new WindowsLiveStrategy({
|
||||
|
||||
@@ -10,7 +10,12 @@ module.exports = {
|
||||
key: 'oauth2',
|
||||
title: 'OAuth2',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'authorizationURL', 'tokenURL'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String,
|
||||
authorizationURL: String,
|
||||
tokenURL: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('oauth2',
|
||||
new OAuth2Strategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'slack',
|
||||
title: 'Slack',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('slack',
|
||||
new SlackStrategy({
|
||||
|
||||
@@ -10,7 +10,10 @@ module.exports = {
|
||||
key: 'twitch',
|
||||
title: 'Twitch',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
init (passport, conf) {
|
||||
passport.use('twitch',
|
||||
new TwitchStrategy({
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
module.exports = {
|
||||
key: 'azure',
|
||||
title: 'Azure Blob Storage',
|
||||
props: [],
|
||||
props: {
|
||||
accountName: String,
|
||||
accountKey: String,
|
||||
container: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
module.exports = {
|
||||
key: 'digitalocean',
|
||||
title: 'DigialOcean Spaces',
|
||||
props: ['accessKeyId', 'accessSecret', 'region', 'bucket'],
|
||||
props: {
|
||||
accessKeyId: String,
|
||||
accessSecret: String,
|
||||
region: {
|
||||
type: String,
|
||||
default: 'nyc3'
|
||||
},
|
||||
bucket: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
module.exports = {
|
||||
key: 'disk',
|
||||
title: 'Local FS',
|
||||
props: ['path'],
|
||||
props: {
|
||||
path: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
module.exports = {
|
||||
key: 'dropbox',
|
||||
title: 'Dropbox',
|
||||
props: [],
|
||||
props: {
|
||||
appKey: String,
|
||||
appSecret: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
module.exports = {
|
||||
key: 'gdrive',
|
||||
title: 'Google Drive',
|
||||
props: [],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
module.exports = {
|
||||
key: 'git',
|
||||
title: 'Git',
|
||||
props: [],
|
||||
props: {
|
||||
authType: {
|
||||
type: String,
|
||||
default: 'ssh',
|
||||
enum: ['basic', 'ssh']
|
||||
},
|
||||
repoUrl: String,
|
||||
branch: {
|
||||
type: String,
|
||||
default: 'master'
|
||||
},
|
||||
verifySSL: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
sshPrivateKeyPath: String,
|
||||
basicUsername: String,
|
||||
basicPassword: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
module.exports = {
|
||||
key: 'onedrive',
|
||||
title: 'OneDrive',
|
||||
props: [],
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
module.exports = {
|
||||
key: 's3',
|
||||
title: 'Amazon S3',
|
||||
props: [],
|
||||
props: {
|
||||
accessKeyId: String,
|
||||
accessSecret: String,
|
||||
region: String,
|
||||
bucket: String
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
module.exports = {
|
||||
key: 'scp',
|
||||
title: 'SCP (SSH)',
|
||||
props: [],
|
||||
props: {
|
||||
host: String,
|
||||
port: {
|
||||
type: Number,
|
||||
default: 22
|
||||
},
|
||||
username: String,
|
||||
privateKeyPath: String,
|
||||
basePath: {
|
||||
type: String,
|
||||
default: '~'
|
||||
}
|
||||
},
|
||||
activate() {
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user