-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
1 parent
7fe8709
commit 626dcc1
Showing
9 changed files
with
136 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
import {BaseEntity, Column, Entity, JoinTable, ManyToOne, PrimaryGeneratedColumn} from "typeorm"; | ||
import { User } from './User'; | ||
import {BaseEntity, Column, Entity, PrimaryGeneratedColumn} from "typeorm"; | ||
|
||
@Entity({name: 'service_accounts'}) | ||
export class ServiceAccount extends BaseEntity { | ||
|
||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
@Column({type: Number}) | ||
public owner_id: number; | ||
|
||
@Column({type: Number}) | ||
public service_user_id: number; | ||
|
||
@Column({type: String}) | ||
public description: string; | ||
|
||
@Column({type: Date, nullable: false}) | ||
public endOfLife: string; | ||
|
||
@ManyToOne(type => User) | ||
@JoinTable({ | ||
name: 'service_account_user', | ||
joinColumn: {name: 'service_account_id'}, | ||
inverseJoinColumn: {name: 'user_id'} | ||
}) | ||
public service_account_owner: User; | ||
} |
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,55 @@ | ||
import { HomeDBManager } from 'app/gen-server/lib/homedb/HomeDBManager'; | ||
//import { UsersManager } from 'app/gen-server/lib/homedb/UsersManager'; | ||
import { EntityManager } from 'typeorm'; | ||
import { User } from 'app/gen-server/entity/User'; | ||
import {v4 as uuidv4} from 'uuid'; | ||
//import { ServiceAccount } from 'app/gen-server/entity/ServiceAccount'; | ||
|
||
export class ServiceAccountsManager { | ||
|
||
private get _connection () { | ||
return this._homeDb.connection; | ||
} | ||
|
||
public constructor( | ||
private readonly _homeDb: HomeDBManager, | ||
//private _runInTransaction: RunInTransaction | ||
) {} | ||
|
||
// This method is implemented for test purpose only | ||
// Using it outside of tests context will lead to partial db | ||
// destruction | ||
public async deleteAllServiceAccounts(optManager?: EntityManager){ | ||
const manager = optManager || new EntityManager(this._connection); | ||
const queryBuilder = manager.createQueryBuilder() | ||
.delete() | ||
.from(User, 'users') | ||
.where('users.type ="service"'); | ||
return await queryBuilder.execute(); | ||
} | ||
|
||
public async createServiceAccount( | ||
ownerId: number, | ||
description?: string, | ||
endOfLife?: Date, | ||
){ | ||
await this._connection.transaction(async manager => { | ||
//TODO create new service user in order to have its | ||
//id to insert | ||
const uuid = uuidv4(); | ||
const email = `${uuid}@serviceaccounts.local`; | ||
const serviceUser = await this._homeDb.getUserByLogin(email); | ||
// FIXME use manager.save(entité); | ||
return await manager.createQueryBuilder() | ||
.insert() | ||
.into('service_accounts') | ||
.values({ | ||
ownerId, | ||
serviceUserId: serviceUser.id, | ||
description, | ||
endOfLife, | ||
}) | ||
.execute(); | ||
}); | ||
} | ||
} |
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