Skip to content

Commit f324aeb

Browse files
refactor: revert back to using proxy name
1 parent f327fcf commit f324aeb

11 files changed

Lines changed: 456 additions & 3204 deletions

File tree

data/init.sql

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,25 @@ CREATE TABLE IF NOT EXISTS domains(
100100
PRIMARY KEY (name, domain_suffix, tenant_id)
101101
);
102102
CREATE TABLE IF NOT EXISTS proxyconfigs(
103-
access_info varchar(256) NOT NULL,
104-
info_format integer,
105-
port integer,
103+
proxy_config_name citext,
104+
access_info citext NOT NULL,
105+
info_format integer NOT NULL,
106+
port integer NOT NULL,
106107
network_dns_suffix varchar(192),
107108
creation_date timestamp,
108-
tenant_id varchar(36) NOT NULL,
109-
PRIMARY KEY (access_info, tenant_id)
109+
tenant_id varchar(36),
110+
CONSTRAINT access_info_port UNIQUE (access_info, port, tenant_id),
111+
PRIMARY KEY (proxy_config_name, tenant_id)
110112
);
111113
CREATE TABLE IF NOT EXISTS profiles_proxyconfigs(
114+
proxy_config_name citext,
112115
access_info citext,
113116
profile_name citext,
114-
FOREIGN KEY (access_info,tenant_id) REFERENCES proxyconfigs(access_info,tenant_id),
117+
FOREIGN KEY (proxy_config_name,tenant_id) REFERENCES proxyconfigs(proxy_config_name,tenant_id),
115118
FOREIGN KEY (profile_name,tenant_id) REFERENCES profiles(profile_name,tenant_id),
116119
priority integer,
117120
creation_date timestamp,
118121
created_by varchar(40),
119-
tenant_id varchar(36) NOT NULL,
120-
PRIMARY KEY (access_info, profile_name, priority, tenant_id)
122+
tenant_id varchar(36),
123+
PRIMARY KEY (proxy_config_name, profile_name, priority, tenant_id)
121124
);

src/data/postgres/tables/profileProxyConfigs.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ describe('profileproxyconfig tests', () => {
1515
let profilesProxyConfigsTable: ProfileProxyConfigsTable
1616
let querySpy: SpyInstance<any>
1717
const proxyConfigs: ProfileProxyConfigs[] = [
18-
{ configName: 'proxyConfig', priority: 1 } as any
18+
{ profileName: 'proxyConfig', priority: 1 } as any
1919
]
20-
const configName = 'profileName'
20+
const profileName = 'profileName'
2121
const tenantId = 'tenantId'
2222

2323
beforeEach(() => {
@@ -31,75 +31,75 @@ describe('profileproxyconfig tests', () => {
3131
describe('Get', () => {
3232
test('should Get', async () => {
3333
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
34-
const result = await profilesProxyConfigsTable.getProfileProxyConfigs(configName)
34+
const result = await profilesProxyConfigsTable.getProfileProxyConfigs(profileName)
3535
expect(result).toStrictEqual([{}])
3636
expect(querySpy).toBeCalledTimes(1)
3737
expect(querySpy).toBeCalledWith(
3838
`
3939
SELECT
4040
priority as "priority",
41-
access_info as "configName"
41+
proxy_config_name as "profileName"
4242
FROM profiles_proxyconfigs
4343
WHERE profile_name = $1 and tenant_id = $2
4444
ORDER BY priority`,
45-
[configName, '']
45+
[profileName, '']
4646
)
4747
})
4848
})
4949
describe('Delete', () => {
5050
test('should Delete', async () => {
5151
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
52-
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(configName)
52+
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(profileName)
5353
expect(result).toBe(true)
5454
expect(querySpy).toBeCalledTimes(1)
5555
expect(querySpy).toBeCalledWith(
5656
`
5757
DELETE
5858
FROM profiles_proxyconfigs
5959
WHERE profile_name = $1 and tenant_id = $2`,
60-
[configName, '']
60+
[profileName, '']
6161
)
6262
})
6363
test('should Delete with tenandId', async () => {
6464
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
65-
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(configName, tenantId)
65+
const result = await profilesProxyConfigsTable.deleteProfileProxyConfigs(profileName, tenantId)
6666
expect(result).toBe(true)
6767
expect(querySpy).toBeCalledTimes(1)
6868
expect(querySpy).toBeCalledWith(
6969
`
7070
DELETE
7171
FROM profiles_proxyconfigs
7272
WHERE profile_name = $1 and tenant_id = $2`,
73-
[configName, tenantId]
73+
[profileName, tenantId]
7474
)
7575
})
7676
})
7777
describe('Insert', () => {
7878
test('should Insert', async () => {
7979
querySpy.mockResolvedValueOnce({ rows: [{}], rowCount: 1 })
80-
const result = await profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, configName)
80+
const result = await profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)
8181
expect(result).toBe(true)
8282
expect(querySpy).toBeCalledTimes(1)
8383
expect(querySpy).toBeCalledWith(`
8484
INSERT INTO
85-
profiles_proxyconfigs (access_info, profile_name, priority, tenant_id)
85+
profiles_proxyconfigs (proxy_config_name, profile_name, priority, tenant_id)
8686
VALUES ('proxyConfig', 'profileName', '1', '')`)
8787
})
8888
test('should NOT insert when no proxyconfigs', async () => {
89-
await expect(profilesProxyConfigsTable.createProfileProxyConfigs([], configName)).rejects.toThrow(
89+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs([], profileName)).rejects.toThrow(
9090
'Operation failed: profileName'
9191
)
9292
})
9393
test('should NOT insert when constraint violation', async () => {
9494
querySpy.mockRejectedValueOnce({ code: '23503', detail: 'error' })
95-
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, configName)).rejects.toThrow(
95+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)).rejects.toThrow(
9696
'error'
9797
)
9898
})
9999
test('should NOT insert when unknown error', async () => {
100100
querySpy.mockRejectedValueOnce('unknown')
101-
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, configName)).rejects.toThrow(
102-
API_UNEXPECTED_EXCEPTION(configName)
101+
await expect(profilesProxyConfigsTable.createProfileProxyConfigs(proxyConfigs, profileName)).rejects.toThrow(
102+
API_UNEXPECTED_EXCEPTION(profileName)
103103
)
104104
})
105105
})

src/data/postgres/tables/profileProxyConfigs.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
1919

2020
/**
2121
* @description Get AMT Profile associated proxy configs
22-
* @param {string} configName
22+
* @param {string} profileName
2323
* @returns {ProfileProxyConfigs[]} Return an array of proxy configs
2424
*/
25-
async getProfileProxyConfigs(configName: string, tenantId = ''): Promise<ProfileProxyConfigs[]> {
25+
async getProfileProxyConfigs(profileName: string, tenantId = ''): Promise<ProfileProxyConfigs[]> {
2626
const results = await this.db.query<ProfileProxyConfigs>(
2727
`
2828
SELECT
2929
priority as "priority",
30-
access_info as "configName"
30+
proxy_config_name as "profileName"
3131
FROM profiles_proxyconfigs
3232
WHERE profile_name = $1 and tenant_id = $2
3333
ORDER BY priority`,
34-
[configName, tenantId]
34+
[profileName, tenantId]
3535
)
3636
return results.rows
3737
}
3838

3939
/**
4040
* @description Insert proxy configs associated with AMT profile
4141
* @param {ProfileProxyConfigs[]} proxyConfigs
42-
* @param {string} configName
42+
* @param {string} profileName
4343
* @returns {ProfileProxyConfigs[]} Return an array of proxy configs
4444
*/
4545
async createProfileProxyConfigs(
4646
proxyConfigs: ProfileProxyConfigs[],
47-
configName: string,
47+
profileName: string,
4848
tenantId = ''
4949
): Promise<boolean> {
5050
try {
@@ -53,16 +53,16 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
5353
}
5454
// Preparing data for inserting multiple rows
5555
const configs = proxyConfigs.map((config) => [
56-
config.configName,
57-
configName,
56+
config.profileName,
57+
profileName,
5858
config.priority,
5959
tenantId
6060
])
6161
const proxyProfilesQueryResults = await this.db.query(
6262
format(
6363
`
6464
INSERT INTO
65-
profiles_proxyconfigs (access_info, profile_name, priority, tenant_id)
65+
profiles_proxyconfigs (proxy_config_name, profile_name, priority, tenant_id)
6666
VALUES %L`,
6767
configs
6868
)
@@ -75,7 +75,7 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
7575
if (error.code === PostgresErr.C23_FOREIGN_KEY_VIOLATION) {
7676
throw new RPSError(error.detail, 'Foreign key constraint violation')
7777
}
78-
throw new RPSError(API_UNEXPECTED_EXCEPTION(configName))
78+
throw new RPSError(API_UNEXPECTED_EXCEPTION(profileName))
7979
}
8080
return false
8181
}

src/data/postgres/tables/profiles.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('profiles tests', () => {
131131
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
132132
ip_sync_enabled as "ipSyncEnabled",
133133
local_wifi_sync_enabled as "localWifiSyncEnabled",
134-
COALESCE(json_agg(json_build_object('configName',pc.access_info, 'priority', pc.priority)) FILTER (WHERE pc.access_info IS NOT NULL), '[]') AS "proxyConfigs"
134+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
135135
FROM profiles p
136136
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
137137
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
@@ -191,7 +191,7 @@ describe('profiles tests', () => {
191191
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
192192
ip_sync_enabled as "ipSyncEnabled",
193193
local_wifi_sync_enabled as "localWifiSyncEnabled",
194-
COALESCE(json_agg(json_build_object('configName',pc.access_info, 'priority', pc.priority)) FILTER (WHERE pc.access_info IS NOT NULL), '[]') AS "proxyConfigs"
194+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
195195
FROM profiles p
196196
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
197197
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id

src/data/postgres/tables/profiles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class ProfilesTable implements IProfilesTable {
7979
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
8080
ip_sync_enabled as "ipSyncEnabled",
8181
local_wifi_sync_enabled as "localWifiSyncEnabled",
82-
COALESCE(json_agg(json_build_object('configName',pc.access_info, 'priority', pc.priority)) FILTER (WHERE pc.access_info IS NOT NULL), '[]') AS "proxyConfigs"
82+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
8383
FROM profiles p
8484
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
8585
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id
@@ -143,7 +143,7 @@ export class ProfilesTable implements IProfilesTable {
143143
COALESCE(json_agg(json_build_object('profileName',wc.wireless_profile_name, 'priority', wc.priority)) FILTER (WHERE wc.wireless_profile_name IS NOT NULL), '[]') AS "wifiConfigs",
144144
ip_sync_enabled as "ipSyncEnabled",
145145
local_wifi_sync_enabled as "localWifiSyncEnabled",
146-
COALESCE(json_agg(json_build_object('configName',pc.access_info, 'priority', pc.priority)) FILTER (WHERE pc.access_info IS NOT NULL), '[]') AS "proxyConfigs"
146+
COALESCE(json_agg(json_build_object('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
147147
FROM profiles p
148148
LEFT JOIN profiles_wirelessconfigs wc ON wc.profile_name = p.profile_name AND wc.tenant_id = p.tenant_id
149149
LEFT JOIN profiles_proxyconfigs pc ON pc.profile_name = p.profile_name AND pc.tenant_id = p.tenant_id

0 commit comments

Comments
 (0)