Skip to content

Commit 69ef622

Browse files
ch2 region fix (flavors) (#92)
ch2 region fix (flavors) Added other type of auth in helpers Changed re to support non-standard region names Update packages Reviewed-by: Artem Lifshits
1 parent 518e222 commit 69ef622

File tree

12 files changed

+6832
-11348
lines changed

12 files changed

+6832
-11348
lines changed

.yarn/releases/yarn-3.0.0-rc.1.cjs

Lines changed: 0 additions & 591 deletions
This file was deleted.

.yarn/releases/yarn-3.6.4.cjs

Lines changed: 874 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ plugins:
44
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
55
spec: "@yarnpkg/plugin-typescript"
66

7-
yarnPath: .yarn/releases/yarn-3.0.0-rc.1.cjs
7+
yarnPath: .yarn/releases/yarn-3.6.4.cjs

.zuul.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
- job:
1212
name: "simple"
1313
parent: "simpleton"
14+
nodeset: ubuntu-jammy
1415
vars:
15-
simple_source_image: "node:latest"
16+
simple_source_image: "node:20"
1617
simple_prerun:
1718
- yarn install
1819
simple_run:

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devDependencies": {
1818
"@types/eslint": "^7",
1919
"@types/jest": "^26.0.22",
20+
"@types/json-schema": "^7.0.15",
2021
"@types/lodash": "^4",
2122
"@types/node": "^14.11.2",
2223
"@types/query-string": "^6",
@@ -79,8 +80,10 @@
7980
"release": "yarn clean && yarn build && webpack --mode production"
8081
},
8182
"dependencies": {
83+
"@types/json-schema": "^7.0.15",
8284
"cross-fetch": "^3.1.4",
8385
"is-cidr": "^4.0.2",
86+
"json-schema": "^0.4.0",
8487
"lodash": "^4.17.20",
8588
"query-string": "^6.13.2"
8689
},

src/oms/core/http.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ export default class HttpClient {
185185
*
186186
* #### NB! this method can return object not matching given type value
187187
*/
188-
async request<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
188+
// eslint-disable-next-line @typescript-eslint/ban-types
189+
async request<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
189190
let merged = new RequestOpts(opts)
190191
if (!merged.baseURL) {
191192
merged.baseURL = this.baseConfig.baseURL
@@ -265,17 +266,20 @@ export default class HttpClient {
265266
return response
266267
}
267268

268-
async get<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
269+
// eslint-disable-next-line @typescript-eslint/ban-types
270+
async get<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
269271
opts.method = 'GET'
270272
return await this.request(opts)
271273
}
272274

273-
async post<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
275+
// eslint-disable-next-line @typescript-eslint/ban-types
276+
async post<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
274277
opts.method = 'POST'
275278
return await this.request(opts)
276279
}
277280

278-
async put<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
281+
// eslint-disable-next-line @typescript-eslint/ban-types
282+
async put<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
279283
opts.method = 'PUT'
280284
return await this.request(opts)
281285
}

src/oms/core/signer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,13 @@ function getSigningKey(params: SigningKeyParams) {
182182
const kRegion = hmac(kDate, encoder.encode(params.regionName))
183183
const kService = hmac(kRegion, encoder.encode(params.serviceName))
184184
return hmac(kService, encoder.encode('sdk_request'))
185-
} catch (e) {
186-
throw new Error(`Failed to generate signature key: ${e.message}`)
185+
} catch (e: unknown) {
186+
if (e instanceof Error) {
187+
throw new Error(`Failed to generate signature key: ${e.message}`)
188+
} else {
189+
// Handle the unknown error case
190+
throw new Error('An unknown error occurred');
191+
}
187192
}
188193
}
189194

src/oms/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CatalogEntity, IdentityV3, ResponseToken } from './services'
77
export * from './core'
88
export * from './services'
99

10-
const defaultRegion = 'eu-de'
10+
export const defaultRegion = 'eu-de'
1111

1212
/**
1313
* Client is base provider client

src/oms/services/compute/v1/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Service from '../../base'
22
import HttpClient from '../../../core/http'
33
import { Flavor, listFlavors } from './flavors'
44

5-
const groupInfoRe = /([\w-]+\d+)\((\w+)\)/
5+
const groupInfoRe = /^(.*?)\((.*?)\)$/
66
const normal = 'normal'
77

88
/**

tests/functional/helpers.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { Client, cloud } from '../../src/oms'
1+
import { Client, cloud, defaultRegion } from '../../src/oms'
22

3-
export const authUrl = 'https://iam.eu-de.otc.t-systems.com/v3'
3+
export let authUrl = 'https://iam.eu-de.otc.t-systems.com/v3'
44

5-
export const authCases = ['ak/sk', 'token']
5+
export const authCases = ['ak/sk', 'token', 'cloud']
66

77
export async function commonBeforeAll(authType: string): Promise<Client> {
8+
let region = defaultRegion
9+
if (process.env.OS_REGION) {
10+
region = String(process.env.OS_REGION)
11+
}
12+
authUrl = 'https://iam.' + region + '.otc.t-systems.com/v3'
13+
if (region === 'eu-ch2'){
14+
authUrl = 'https://iam-pub.' + region + '.sc.otc.t-systems.com/v3'
15+
}
16+
const projectName = process.env.OS_PROJECT_NAME
817
const config = cloud(authUrl)
918
switch (authType) {
1019
case 'ak/sk':
1120
const ak = process.env.AWS_ACCESS_KEY_ID
1221
const sk = process.env.AWS_SECRET_ACCESS_KEY
13-
const projectName = process.env.OS_PROJECT_NAME
1422
if (!ak || !sk || !projectName) {
1523
throw 'Missing AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and OS_PROJECT_NAME required for tests'
1624
}
@@ -23,7 +31,20 @@ export async function commonBeforeAll(authType: string): Promise<Client> {
2331
}
2432
config.withToken(t)
2533
break
34+
case 'cloud':
35+
const domainName = process.env.OS_DOMAIN_NAME
36+
const password = process.env.OS_PASSWORD
37+
const username = process.env.OS_USERNAME
38+
if (!username || !password || !domainName || !projectName) {
39+
throw 'Missing OS_DOMAIN_NAME, OS_PASSWORD, OS_USERNAME and OS_PROJECT_NAME required for tests'
40+
}
41+
config
42+
.withRegion(region)
43+
.withProject(projectName)
44+
.withPassword(domainName, username, password)
45+
break
2646
}
47+
2748
const client = new Client(config.config)
2849
await client.authenticate()
2950
return client

0 commit comments

Comments
 (0)