mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-11 20:42:00 -05:00
8377005187
This reverts commit c8814e7fd85776feb37bf8fad95038349b36cd9a. GitOrigin-RevId: 9deeb445917c856acee54ef793575c8ab9c81304
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
/* eslint-disable max-len */
|
|
/**
|
|
* run with: node import_oauth_applications /path/oauth_applications.csv
|
|
*
|
|
* where csv is generated from v1 with sql statement like:
|
|
*
|
|
* \copy (SELECT * FROM oauth_applications) to 'oauth_applications.csv' WITH CSV HEADER;
|
|
*/
|
|
/* eslint-enable */
|
|
|
|
'use strict'
|
|
|
|
const OauthApplication = require('../../app/js/models/OauthApplication')
|
|
.OauthApplication
|
|
const async = require('async')
|
|
const csvParser = require('csv-parser')
|
|
const fs = require('fs')
|
|
const minimist = require('minimist')
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
|
|
|
const records = []
|
|
|
|
fs.createReadStream(argv._[0])
|
|
.pipe(csvParser())
|
|
.on('data', data => records.push(data))
|
|
.on('end', () => {
|
|
async.mapSeries(records, loadRecord, function(err) {
|
|
if (err) console.error(err)
|
|
process.exit()
|
|
})
|
|
})
|
|
|
|
function loadRecord(record, cb) {
|
|
const newRecord = {
|
|
clientSecret: record.secret,
|
|
id: record.uid,
|
|
// doorkeeper does not define grant types so add all supported
|
|
grants: ['authorization_code', 'refresh_token', 'password'],
|
|
name: record.name,
|
|
// redirect uris are stored new-line separated
|
|
redirectUris: record.redirect_uri.split(/\r?\n/),
|
|
// scopes are stored space separated
|
|
scopes: record.scopes.split(/\s+/)
|
|
}
|
|
console.log('Creating OauthApplication ' + newRecord.name)
|
|
OauthApplication.update(newRecord, newRecord, { upsert: true }, cb)
|
|
}
|