Skip to content

Commit 5b9ede0

Browse files
feat: enable http proxy for cira (#2352)
1 parent dfbe8f9 commit 5b9ede0

28 files changed

Lines changed: 1484 additions & 187 deletions

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"ci-prettify": "npx prettier --check '**/*.{ts,js,yaml,css,scss,json}'"
4747
},
4848
"dependencies": {
49-
"@device-management-toolkit/wsman-messages": "^5.12.0",
49+
"@device-management-toolkit/wsman-messages": "^5.13.0",
5050
"body-parser": "^2.2.0",
5151
"consul": "^2.0.1",
5252
"cors": "^2.8.5",
@@ -93,7 +93,7 @@
9393
"prettier-plugin-multiline-arrays": "^4.0.3",
9494
"sinon": "^21.0.0",
9595
"ts-jest": "^29.4.1",
96-
"ts-jest-mock-import-meta": "^1.3.1",
96+
"ts-jest-mock-import-meta": "^1.3.0",
9797
"ts-node": "^10.9.2",
9898
"typescript": "^5.8.3",
9999
"typescript-eslint": "8.45.0"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('profileproxyconfig tests', () => {
1515
let profilesProxyConfigsTable: ProfileProxyConfigsTable
1616
let querySpy: SpyInstance<any>
1717
const proxyConfigs: ProfileProxyConfigs[] = [
18-
{ profileName: 'proxyConfig', priority: 1 } as any
18+
{ name: 'proxyConfig', priority: 1 } as any
1919
]
2020
const profileName = 'profileName'
2121
const tenantId = 'tenantId'
@@ -38,7 +38,7 @@ describe('profileproxyconfig tests', () => {
3838
`
3939
SELECT
4040
priority as "priority",
41-
proxy_config_name as "profileName"
41+
proxy_config_name as "name"
4242
FROM profiles_proxyconfigs
4343
WHERE profile_name = $1 and tenant_id = $2
4444
ORDER BY priority`,

src/data/postgres/tables/profileProxyConfigs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
2727
`
2828
SELECT
2929
priority as "priority",
30-
proxy_config_name as "profileName"
30+
proxy_config_name as "name"
3131
FROM profiles_proxyconfigs
3232
WHERE profile_name = $1 and tenant_id = $2
3333
ORDER BY priority`,
@@ -53,7 +53,7 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
5353
}
5454
// Preparing data for inserting multiple rows
5555
const configs = proxyConfigs.map((config) => [
56-
config.profileName,
56+
config.name,
5757
profileName,
5858
config.priority,
5959
tenantId

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('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
134+
COALESCE(json_agg(json_build_object('name',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('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
194+
COALESCE(json_agg(json_build_object('name',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('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
82+
COALESCE(json_agg(json_build_object('name',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('profileName',pc.proxy_config_name, 'priority', pc.priority)) FILTER (WHERE pc.proxy_config_name IS NOT NULL), '[]') AS "proxyConfigs"
146+
COALESCE(json_agg(json_build_object('name',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

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ describe('proxy configs tests', () => {
2424
let proxyConfigsTable: ProxyConfigsTable
2525
let querySpy: SpyInstance<any>
2626
let proxyConfig: ProxyConfig
27-
const profileName = 'proxyName'
27+
const profileName = 'name'
2828
beforeEach(() => {
2929
proxyConfig = {
30-
proxyName: 'proxy profile',
30+
name: 'proxy profile',
3131
address: 'proxy.com',
3232
infoFormat: 201, // FQDN (201)
3333
port: 1000,
@@ -97,7 +97,7 @@ describe('proxy configs tests', () => {
9797
expect(querySpy).toBeCalledWith(
9898
`
9999
SELECT
100-
proxy_config_name as "proxyName",
100+
proxy_config_name as "name",
101101
address as "address",
102102
info_format as "infoFormat",
103103
port as "port",
@@ -123,7 +123,7 @@ describe('proxy configs tests', () => {
123123
expect(querySpy).toBeCalledWith(
124124
`
125125
SELECT
126-
proxy_config_name as "proxyName",
126+
proxy_config_name as "name",
127127
address as "address",
128128
info_format as "infoFormat",
129129
port as "port",
@@ -226,15 +226,15 @@ describe('proxy configs tests', () => {
226226
const result = await proxyConfigsTable.insert(proxyConfig)
227227

228228
expect(result).toBe(proxyConfig)
229-
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.proxyName, proxyConfig.tenantId)
229+
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.name, proxyConfig.tenantId)
230230
expect(querySpy).toBeCalledTimes(1)
231231
expect(querySpy).toBeCalledWith(
232232
`
233233
INSERT INTO proxyconfigs
234234
(proxy_config_name, address, info_format, port, network_dns_suffix, creation_date, tenant_id)
235235
values($1, $2, $3, $4, $5, $6, $7)`,
236236
[
237-
proxyConfig.proxyName,
237+
proxyConfig.name,
238238
proxyConfig.address,
239239
proxyConfig.infoFormat,
240240
proxyConfig.port,
@@ -256,13 +256,13 @@ describe('proxy configs tests', () => {
256256
test('should NOT insert when duplicate name', async () => {
257257
querySpy.mockRejectedValueOnce({ code: '23505' })
258258
await expect(proxyConfigsTable.insert(proxyConfig)).rejects.toThrow(
259-
NETWORK_CONFIG_INSERTION_FAILED_DUPLICATE('Proxy', proxyConfig.proxyName)
259+
NETWORK_CONFIG_INSERTION_FAILED_DUPLICATE('Proxy', proxyConfig.name)
260260
)
261261
})
262262
test('should NOT insert when unexpected exception', async () => {
263263
querySpy.mockRejectedValueOnce(new Error('unknown'))
264264
await expect(proxyConfigsTable.insert(proxyConfig)).rejects.toThrow(
265-
NETWORK_CONFIG_ERROR('Proxy', proxyConfig.proxyName)
265+
NETWORK_CONFIG_ERROR('Proxy', proxyConfig.name)
266266
)
267267
})
268268
})
@@ -273,15 +273,15 @@ describe('proxy configs tests', () => {
273273
getByNameSpy.mockResolvedValue(proxyConfig)
274274
const result = await proxyConfigsTable.update(proxyConfig)
275275
expect(result).toBe(proxyConfig)
276-
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.proxyName, proxyConfig.tenantId)
276+
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.name, proxyConfig.tenantId)
277277
expect(querySpy).toBeCalledTimes(1)
278278
expect(querySpy).toBeCalledWith(
279279
`
280280
UPDATE proxyconfigs
281281
SET address=$2, info_format=$3, port=$4, network_dns_suffix=$5
282282
WHERE proxy_config_name=$1 and tenant_id = $6`,
283283
[
284-
proxyConfig.proxyName,
284+
proxyConfig.name,
285285
proxyConfig.address,
286286
proxyConfig.infoFormat,
287287
proxyConfig.port,
@@ -307,7 +307,7 @@ describe('proxy configs tests', () => {
307307
const getByNameSpy = spyOn(proxyConfigsTable, 'getByName')
308308
getByNameSpy.mockResolvedValue(proxyConfig)
309309
await expect(proxyConfigsTable.update(proxyConfig)).rejects.toThrow(
310-
NETWORK_CONFIG_ERROR('Proxy', proxyConfig.proxyName)
310+
NETWORK_CONFIG_ERROR('Proxy', proxyConfig.name)
311311
)
312312
})
313313

@@ -316,15 +316,15 @@ describe('proxy configs tests', () => {
316316
const getByNameSpy = spyOn(proxyConfigsTable, 'getByName')
317317
getByNameSpy.mockResolvedValue(proxyConfig)
318318
await expect(proxyConfigsTable.update(proxyConfig)).rejects.toThrow(CONCURRENCY_MESSAGE)
319-
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.proxyName, proxyConfig.tenantId)
319+
expect(getByNameSpy).toHaveBeenCalledWith(proxyConfig.name, proxyConfig.tenantId)
320320
expect(querySpy).toBeCalledTimes(1)
321321
expect(querySpy).toBeCalledWith(
322322
`
323323
UPDATE proxyconfigs
324324
SET address=$2, info_format=$3, port=$4, network_dns_suffix=$5
325325
WHERE proxy_config_name=$1 and tenant_id = $6`,
326326
[
327-
proxyConfig.proxyName,
327+
proxyConfig.name,
328328
proxyConfig.address,
329329
proxyConfig.infoFormat,
330330
proxyConfig.port,

src/data/postgres/tables/proxyConfigs.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
5757
const results = await this.db.query<ProxyConfig>(
5858
`
5959
SELECT
60-
proxy_config_name as "proxyName",
60+
proxy_config_name as "name",
6161
address as "address",
6262
info_format as "infoFormat",
6363
port as "port",
@@ -78,22 +78,22 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
7878

7979
/**
8080
* @description Get proxy profile from DB by name
81-
* @param {string} proxyName
81+
* @param {string} name
8282
* @returns {ProxyConfig} ProxyConfig object
8383
*/
84-
async getByName(proxyName: string, tenantId = ''): Promise<ProxyConfig | null> {
84+
async getByName(name: string, tenantId = ''): Promise<ProxyConfig | null> {
8585
const results = await this.db.query<ProxyConfig>(
8686
`
8787
SELECT
88-
proxy_config_name as "proxyName",
88+
proxy_config_name as "name",
8989
address as "address",
9090
info_format as "infoFormat",
9191
port as "port",
9292
network_dns_suffix as "networkDnsSuffix",
9393
tenant_id as "tenantId"
9494
FROM proxyconfigs
9595
WHERE proxy_config_name = $1 and tenant_id = $2`,
96-
[proxyName, tenantId]
96+
[name, tenantId]
9797
)
9898

9999
if ((results?.rowCount ?? 0) > 0) {
@@ -105,16 +105,16 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
105105

106106
/**
107107
* @description Check proxy profile exists in DB by name
108-
* @param {string} proxyName
108+
* @param {string} name
109109
* @returns {string[]}
110110
*/
111-
async checkProfileExits(proxyName: string, tenantId = ''): Promise<boolean> {
111+
async checkProfileExits(name: string, tenantId = ''): Promise<boolean> {
112112
const results = await this.db.query(
113113
`
114114
SELECT 1
115115
FROM proxyconfigs
116116
WHERE proxy_config_name = $1 and tenant_id = $2`,
117-
[proxyName, tenantId]
117+
[name, tenantId]
118118
)
119119

120120
if ((results?.rowCount ?? 0) > 0) {
@@ -126,37 +126,37 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
126126

127127
/**
128128
* @description Delete proxy profile from DB by name
129-
* @param {string} proxyName
129+
* @param {string} name
130130
* @returns {boolean} Return true on successful deletion
131131
*/
132-
async delete(proxyName: string, tenantId = ''): Promise<boolean> {
132+
async delete(name: string, tenantId = ''): Promise<boolean> {
133133
const profiles = await this.db.query(
134134
`
135135
SELECT 1
136136
FROM profiles_proxyconfigs
137137
WHERE proxy_config_name = $1 and tenant_id = $2`,
138-
[proxyName, tenantId]
138+
[name, tenantId]
139139
)
140140
if ((profiles?.rowCount ?? 0) > 0) {
141-
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', proxyName), 'Foreign key violation')
141+
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', name), 'Foreign key violation')
142142
}
143143
try {
144144
const results = await this.db.query(
145145
`
146146
DELETE
147147
FROM proxyconfigs
148148
WHERE proxy_config_name = $1 and tenant_id = $2`,
149-
[proxyName, tenantId]
149+
[name, tenantId]
150150
)
151151
if (results?.rowCount) {
152152
return results.rowCount > 0
153153
}
154154
} catch (error) {
155-
this.log.error(`Failed to delete proxy configuration : ${proxyName}`, error)
155+
this.log.error(`Failed to delete proxy configuration : ${name}`, error)
156156
if (error.code === PostgresErr.C23_FOREIGN_KEY_VIOLATION) {
157-
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', proxyName))
157+
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', name))
158158
}
159-
throw new RPSError(API_UNEXPECTED_EXCEPTION(`Delete proxy configuration : ${proxyName}`))
159+
throw new RPSError(API_UNEXPECTED_EXCEPTION(`Delete proxy configuration : ${name}`))
160160
}
161161
return false
162162
}
@@ -175,7 +175,7 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
175175
(proxy_config_name, address, info_format, port, network_dns_suffix, creation_date, tenant_id)
176176
values($1, $2, $3, $4, $5, $6, $7)`,
177177
[
178-
proxyConfig.proxyName,
178+
proxyConfig.name,
179179
proxyConfig.address,
180180
proxyConfig.infoFormat,
181181
proxyConfig.port,
@@ -186,17 +186,14 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
186186
)
187187

188188
if ((results?.rowCount ?? 0) > 0) {
189-
const config = await this.getByName(proxyConfig.proxyName, proxyConfig.tenantId)
189+
const config = await this.getByName(proxyConfig.name, proxyConfig.tenantId)
190190
return config
191191
}
192192
} catch (error) {
193193
if (error.code === PostgresErr.C23_UNIQUE_VIOLATION) {
194-
throw new RPSError(
195-
NETWORK_CONFIG_INSERTION_FAILED_DUPLICATE('Proxy', proxyConfig.proxyName),
196-
'Unique key violation'
197-
)
194+
throw new RPSError(NETWORK_CONFIG_INSERTION_FAILED_DUPLICATE('Proxy', proxyConfig.name), 'Unique key violation')
198195
}
199-
throw new RPSError(NETWORK_CONFIG_ERROR('Proxy', proxyConfig.proxyName))
196+
throw new RPSError(NETWORK_CONFIG_ERROR('Proxy', proxyConfig.name))
200197
}
201198
return null
202199
}
@@ -216,7 +213,7 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
216213
SET address=$2, info_format=$3, port=$4, network_dns_suffix=$5
217214
WHERE proxy_config_name=$1 and tenant_id = $6`,
218215
[
219-
proxyConfig.proxyName,
216+
proxyConfig.name,
220217
proxyConfig.address,
221218
proxyConfig.infoFormat,
222219
proxyConfig.port,
@@ -225,12 +222,12 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
225222
]
226223
)
227224

228-
latestItem = await this.getByName(proxyConfig.proxyName, proxyConfig.tenantId)
225+
latestItem = await this.getByName(proxyConfig.name, proxyConfig.tenantId)
229226
if ((results?.rowCount ?? 0) > 0) {
230227
return latestItem
231228
}
232229
} catch (error) {
233-
throw new RPSError(NETWORK_CONFIG_ERROR('Proxy', proxyConfig.proxyName))
230+
throw new RPSError(NETWORK_CONFIG_ERROR('Proxy', proxyConfig.name))
234231
}
235232
// making assumption that if no records are updated, that it is due to concurrency. We've already checked for if it doesn't exist before calling update.
236233
throw new RPSError(CONCURRENCY_MESSAGE, CONCURRENCY_EXCEPTION, latestItem)

0 commit comments

Comments
 (0)