-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,242 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import _ from 'lodash' | ||
import Knex from 'knex' | ||
import pMap from 'p-map' | ||
import {promises as fs} from 'fs' | ||
|
||
import { bootstrap } from '../server-nest/dist/sdk' | ||
import { KeycloakService } from '../server-nest/dist/keycloak/keycloak.service' | ||
import { UserService } from '../server-nest/dist/users/user.service' | ||
import { UserDTO } from '../server-nest/dist/dtos/user.dto' | ||
|
||
async function main () { | ||
const app = await bootstrap() | ||
const keycloakService = app.get(KeycloakService) | ||
const userService = app.get(UserService) | ||
|
||
const knex = Knex({ | ||
client: 'pg', | ||
connection: { | ||
host : 'localhost', | ||
port: 5432, | ||
user : 'postgres', | ||
password : 'postgres', | ||
database : 'postgres' | ||
} | ||
}) | ||
|
||
const ingestData = JSON.parse(await fs.readFile('../data/ingests/20201004-lego.json', 'utf-8')) | ||
const project = _.first(ingestData) | ||
|
||
const successes = await pMap(_.get(project, 'access', []), async user => { | ||
const party = _.get(user, 'party') | ||
const newUser = { | ||
id: party.id, | ||
displayFullName: `${party.prename} ${party.sortname}`, | ||
givenName: party.prename, | ||
familyName: party.sortname, | ||
emailPrimary: party.email, | ||
authServerId: null | ||
} | ||
newUser.authServerId = await keycloakService.registerUser( | ||
newUser.emailPrimary, | ||
newUser.givenName, | ||
newUser.familyName | ||
) | ||
const userDTO: UserDTO = new UserDTO(newUser) | ||
try { | ||
await userService.createUser(userDTO) | ||
return true | ||
} catch (error) { | ||
console.log(`Error when adding ${newUser.emailPrimary} (${newUser.authServerId}): ${error.msg}`) | ||
return false | ||
} | ||
}) | ||
|
||
console.log(`Added ${_.sum(successes)} users`) | ||
|
||
await knex.destroy() | ||
await app.close() | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// { | ||
// "compilerOptions": { | ||
// "module": "commonjs", | ||
// "declaration": true, | ||
// "removeComments": true, | ||
// "emitDecoratorMetadata": true, | ||
// "experimentalDecorators": true, | ||
// "target": "es2017", | ||
// "sourceMap": true, | ||
// "outDir": "./dist", | ||
// "baseUrl": "./", | ||
// "incremental": true, | ||
// "esModuleInterop": true, | ||
// }, | ||
// "exclude": ["node_modules", "dist"] | ||
// } | ||
|
||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"display": "Node 12", | ||
|
||
"compilerOptions": { | ||
"lib": ["es6"], | ||
"allowJs": true, | ||
"module": "commonjs", | ||
"target": "esnext", | ||
"outDir": "dist", | ||
"strict": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true | ||
}, | ||
|
||
"include": [ | ||
"src/**/*", | ||
"runs/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist", | ||
"**/*.spec.ts" | ||
] | ||
} |
Oops, something went wrong.