Skip to content

Commit 657e5d6

Browse files
committed
WIP
1 parent 46441ba commit 657e5d6

19 files changed

Lines changed: 175 additions & 78 deletions

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: openopsdev
22
services:
33
tables:
44
container_name: tables
5-
image: public.ecr.aws/openops/openops-tables:0.2.10
5+
image: 535002847982.dkr.ecr.us-east-2.amazonaws.com/openops/openops-tables:mg-OPS-3123-2
66
environment:
77
BASEROW_PUBLIC_URL: ${OPS_OPENOPS_TABLES_PUBLIC_URL}
88
BASEROW_PRIVATE_URL: http://localhost:3001

packages/openops/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export * from './lib/openops-tables/fields';
4343
export * from './lib/openops-tables/filters';
4444
export * from './lib/openops-tables/openops-tables-common-properties';
4545
export * from './lib/openops-tables/requests-helpers';
46+
export * from './lib/openops-tables/reset-user-password';
4647
export * from './lib/openops-tables/rows';
4748
export * from './lib/openops-tables/tables';
4849
export * from './lib/openops-tables/types';
Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { AppSystemProp, cacheWrapper, system } from '@openops/server-shared';
21
import { AxiosHeaders } from 'axios';
32
import { IAxiosRetryConfig } from 'axios-retry';
43
import { makeOpenOpsTablesPost } from './requests-helpers';
5-
const tokenLifetimeMinutes = system.getNumber(
6-
AppSystemProp.TABLES_TOKEN_LIFETIME_MINUTES,
7-
);
8-
9-
const tokenLifetimeSeconds = tokenLifetimeMinutes
10-
? (tokenLifetimeMinutes - 10) * 60 // Subtract 10 minutes to ensure the cache expired before the token
11-
: undefined;
124

135
export interface AuthTokens {
146
token: string;
@@ -36,29 +28,3 @@ export async function authenticateUserInOpenOpsTables(
3628
axiosRetryConfig,
3729
);
3830
}
39-
40-
export async function authenticateDefaultUserInOpenOpsTables(
41-
axiosRetryConfig?: IAxiosRetryConfig,
42-
): Promise<AuthTokens> {
43-
const cacheKey = 'openops-tables-token';
44-
45-
let tokens = await cacheWrapper.getSerializedObject<AuthTokens>(cacheKey);
46-
47-
if (!tokens) {
48-
const email = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_EMAIL);
49-
const password = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_PASSWORD);
50-
51-
tokens = await authenticateUserInOpenOpsTables(
52-
email,
53-
password,
54-
axiosRetryConfig,
55-
);
56-
await cacheWrapper.setSerializedObject(
57-
cacheKey,
58-
tokens,
59-
tokenLifetimeSeconds,
60-
);
61-
}
62-
63-
return tokens;
64-
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ServerContext } from '@openops/blocks-framework';
22
import { AppSystemProp, encryptUtils, system } from '@openops/server-shared';
3-
import { authenticateDefaultUserInOpenOpsTables } from './auth-user';
43

54
export function shouldUseDatabaseToken(): boolean {
65
return system.getBoolean(AppSystemProp.ENABLE_TABLES_DATABASE_TOKEN) ?? false;
@@ -15,15 +14,15 @@ export type TablesServerContext = Pick<
1514
export async function resolveTokenProvider(
1615
serverContext: TablesServerContext,
1716
): Promise<TokenOrResolver> {
18-
if (shouldUseDatabaseToken()) {
19-
return {
20-
getToken: () => {
17+
// if (shouldUseDatabaseToken()) {
18+
return {
19+
getToken: () => {
2120
const { tablesDatabaseToken } = serverContext;
22-
return encryptUtils.decryptString(tablesDatabaseToken);
23-
},
24-
};
25-
}
21+
return encryptUtils.decryptString(tablesDatabaseToken);
22+
},
23+
};
24+
// }
2625

27-
const { token } = await authenticateDefaultUserInOpenOpsTables();
28-
return token;
26+
// const { token } = await authenticateDefaultUserInOpenOpsTables();
27+
// return token;
2928
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createAxiosHeaders, makeOpenOpsTablesPatch } from './requests-helpers';
2+
3+
export async function resetUserPassword(
4+
email: string,
5+
password: string,
6+
token: string,
7+
): Promise<void> {
8+
const payload = {
9+
username: email,
10+
password,
11+
};
12+
13+
const headers = createAxiosHeaders(token);
14+
15+
await makeOpenOpsTablesPatch<void>('api/admin/users/', payload, headers);
16+
}

packages/server/api/src/app/ai/mcp/tables-tools.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import {
2-
authenticateDefaultUserInOpenOpsTables,
3-
createAxiosHeaders,
4-
} from '@openops/common';
1+
import { createAxiosHeaders } from '@openops/common';
52
import { AppSystemProp, system } from '@openops/server-shared';
63
import { experimental_createMCPClient as createMCPClient, ToolSet } from 'ai';
4+
import { authenticateAdminUserInOpenOpsTables } from '../../database/seeds/auth-tables';
75
import { openopsTables } from '../../openops-tables';
86
import { MCPTool } from './types';
97

108
export async function getTablesTools(): Promise<MCPTool> {
11-
const { token } = await authenticateDefaultUserInOpenOpsTables();
9+
const { token } = await authenticateAdminUserInOpenOpsTables();
1210
const mcpEndpoint = await openopsTables.getMcpEndpointList(token);
1311
if (!mcpEndpoint) {
1412
return {

packages/server/api/src/app/authentication/basic/authentication-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const authenticationService = {
3838

3939
const { refresh_token } = await authenticateUserInOpenOpsTables(
4040
request.email,
41-
request.password,
41+
user.password,
4242
);
4343

4444
return this.authResponse(user, refresh_token);

packages/server/api/src/app/authentication/new-user/create-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function createUser(
122122
const tablesRefreshToken = await createTablesUser(
123123
name,
124124
params.email,
125-
params.password,
125+
user.password,
126126
);
127127

128128
return {

packages/server/api/src/app/authentication/new-user/organization-assignment.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { authenticateDefaultUserInOpenOpsTables } from '@openops/common';
21
import { AppSystemProp, system } from '@openops/server-shared';
32
import { ApplicationError, ErrorCode, isNil, User } from '@openops/shared';
3+
import { authenticateAdminUserInOpenOpsTables } from '../../database/seeds/auth-tables';
44
import { openopsTables } from '../../openops-tables';
55
import { organizationService } from '../../organization/organization.service';
66
import { projectService } from '../../project/project-service';
@@ -53,8 +53,7 @@ async function addUserToDefaultWorkspace(values: {
5353
email: string;
5454
workspaceId: number;
5555
}): Promise<void> {
56-
const { token: defaultToken } =
57-
await authenticateDefaultUserInOpenOpsTables();
56+
const { token: defaultToken } = await authenticateAdminUserInOpenOpsTables();
5857

5958
await openopsTables.addUserToWorkspace(defaultToken, {
6059
...values,

packages/server/api/src/app/database/migrations/1763394159990-AddTablesTokenToProject.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { authenticateDefaultUserInOpenOpsTables } from '@openops/common';
2-
import { encryptUtils } from '@openops/server-shared';
1+
import { authenticateUserInOpenOpsTables } from '@openops/common';
2+
import { AppSystemProp, encryptUtils, system } from '@openops/server-shared';
33
import { MigrationInterface, QueryRunner } from 'typeorm';
44
import { openopsTables } from '../../openops-tables';
55

@@ -43,7 +43,9 @@ async function createTokensForExistingProjects(
4343
return;
4444
}
4545

46-
const { token } = await authenticateDefaultUserInOpenOpsTables();
46+
const adminEmail = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_EMAIL);
47+
const password = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_PASSWORD);
48+
const { token } = await authenticateUserInOpenOpsTables(adminEmail, password);
4749
for (const record of projects) {
4850
const newToken = await openopsTables.createDatabaseToken(
4951
record.tablesWorkspaceId,

0 commit comments

Comments
 (0)