Add plugin auth migrations

pull/2737/head
Chocobozzz 2020-04-27 10:19:14 +02:00 committed by Chocobozzz
parent e307e4fce3
commit 055cfb11a9
7 changed files with 94 additions and 49 deletions

View File

@ -1,30 +0,0 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
}): Promise<void> {
const metadata = {
type: Sequelize.JSONB,
allowNull: true
}
await utils.queryInterface.addColumn('videoFile', 'metadata', metadata)
const metadataUrl = {
type: Sequelize.STRING,
allowNull: true
}
await utils.queryInterface.addColumn('videoFile', 'metadataUrl', metadataUrl)
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -0,0 +1,42 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
}): Promise<void> {
{
const password = {
type: Sequelize.STRING,
allowNull: true
}
await utils.queryInterface.changeColumn('user', 'password', password)
}
{
const pluginAuth = {
type: Sequelize.STRING,
allowNull: true
}
await utils.queryInterface.addColumn('user', 'pluginAuth', pluginAuth)
}
{
const authName = {
type: Sequelize.STRING,
allowNull: true
}
await utils.queryInterface.addColumn('oAuthToken', 'authName', authName)
}
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -126,6 +126,7 @@ async function proxifyPasswordGrant (req: express.Request, res: express.Response
authOptions.authName, pluginAuth.npmName, loginOptions.id, authOptions.getWeight()
)
try {
const loginResult = await authOptions.login(loginOptions)
if (loginResult) {
logger.info(
@ -147,5 +148,8 @@ async function proxifyPasswordGrant (req: express.Request, res: express.Response
return
}
} catch (err) {
logger.error('Error in auth method %s of plugin %s', authOptions.authName, pluginAuth.npmName, { err })
}
}
}

View File

@ -198,6 +198,8 @@ export class RegisterHelpersStore {
return {
getSetting: (name: string) => PluginModel.getSetting(this.plugin.name, this.plugin.type, name),
getSettings: (names: string[]) => PluginModel.getSettings(this.plugin.name, this.plugin.type, names),
setSetting: (name: string, value: string) => PluginModel.setSetting(this.plugin.name, this.plugin.type, name, value)
}
}

View File

@ -129,6 +129,31 @@ export class PluginModel extends Model<PluginModel> {
})
}
static getSettings (pluginName: string, pluginType: PluginType, settingNames: string[]) {
const query = {
attributes: [ 'settings' ],
where: {
name: pluginName,
type: pluginType
}
}
return PluginModel.findOne(query)
.then(p => {
if (!p || !p.settings) return {}
const result: { [settingName: string ]: string } = {}
for (const key of Object.keys(p.settings)) {
if (settingNames.includes(key)) {
result[key] = p.settings[key]
}
}
return result
})
}
static setSetting (pluginName: string, pluginType: PluginType, settingName: string, settingValue: string) {
const query = {
where: {

View File

@ -143,7 +143,7 @@ describe('Test id and pass auth plugins', function () {
expect(body.role).to.equal(UserRole.MODERATOR)
})
it('Should correctly auth token of laguna', async function () {
it('Should reject token of laguna by the plugin hook', async function () {
this.timeout(10000)
await wait(5000)

View File

@ -1,7 +1,9 @@
import * as Bluebird from 'bluebird'
export interface PluginSettingsManager {
getSetting: (name: string) => Bluebird<string>
getSetting: (name: string) => Bluebird<string | boolean>
getSettings: (names: string[]) => Bluebird<{ [settingName: string]: string | boolean }>
setSetting: (name: string, value: string) => Bluebird<any>
}