Skip to content

Commit 8d5caee

Browse files
committed
Store token, fix binding
1 parent bec4742 commit 8d5caee

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

components/gitpod-db/src/typeorm/entity/db-linked-in-token.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { Entity, PrimaryColumn } from "typeorm";
7+
import { Column, Entity, PrimaryColumn } from "typeorm";
8+
import { Transformer } from "../transformer";
89
import { TypeORM } from "../typeorm";
10+
import { encryptionService } from "../user-db-impl";
911

1012
@Entity()
1113
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
1214
export class DBLinkedInToken {
1315
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
1416
id: string;
17+
18+
@Column(TypeORM.UUID_COLUMN_TYPE)
19+
userId: string;
20+
21+
@Column({
22+
type: "simple-json",
23+
transformer: Transformer.compose(
24+
Transformer.SIMPLE_JSON([]),
25+
// Relies on the initialization of the var in UserDbImpl
26+
Transformer.encrypted(() => encryptionService),
27+
),
28+
})
29+
token: { token: string };
1530
}

components/gitpod-db/src/typeorm/linked-in-token-db-impl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ export class LinkedInTokenDBImpl implements LinkedInTokenDB {
2121
protected async getRepo(): Promise<Repository<DBLinkedInToken>> {
2222
return (await this.getEntityManager()).getRepository<DBLinkedInToken>(DBLinkedInToken);
2323
}
24+
25+
public async storeToken(userId: string, token: string): Promise<void> {
26+
const repo = await this.getRepo();
27+
const dbToken = new DBLinkedInToken();
28+
dbToken.userId = userId;
29+
dbToken.token = { token };
30+
await repo.save(dbToken);
31+
}
2432
}

components/gitpod-db/src/typeorm/migration/1680096507296-LinkedInToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const TABLE_NAME = "d_b_linked_in_token";
1212
export class LinkedInToken1680096507296 implements MigrationInterface {
1313
public async up(queryRunner: QueryRunner): Promise<void> {
1414
await queryRunner.query(
15-
`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id char(36) NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`,
15+
`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id char(36) NOT NULL, userId char(36) NOT NULL, token text NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`,
1616
);
1717
}
1818

components/server/ee/src/container-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { EntitlementServiceLicense } from "./billing/entitlement-service-license
6262
import { EntitlementServiceImpl } from "./billing/entitlement-service";
6363
import { EntitlementServiceUBP } from "./billing/entitlement-service-ubp";
6464
import { UsageService, UsageServiceImpl, NoOpUsageService } from "../../src/user/usage-service";
65+
import { LinkedInService } from "./user/linkedin-service";
6566

6667
export const productionEEContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
6768
rebind(Server).to(ServerEE).inSingletonScope();
@@ -135,4 +136,5 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
135136
return new NoOpUsageService();
136137
})
137138
.inSingletonScope();
139+
bind(LinkedInService).toSelf().inSingletonScope();
138140
});

0 commit comments

Comments
 (0)