Skip to content

Commit

Permalink
ch2 region fix (flavors) (#92)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anton-sidelnikov authored Dec 5, 2023
1 parent 518e222 commit 69ef622
Show file tree
Hide file tree
Showing 12 changed files with 6,832 additions and 11,348 deletions.
591 changes: 0 additions & 591 deletions .yarn/releases/yarn-3.0.0-rc.1.cjs

This file was deleted.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"

yarnPath: .yarn/releases/yarn-3.0.0-rc.1.cjs
yarnPath: .yarn/releases/yarn-3.6.4.cjs
3 changes: 2 additions & 1 deletion .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
- job:
name: "simple"
parent: "simpleton"
nodeset: ubuntu-jammy
vars:
simple_source_image: "node:latest"
simple_source_image: "node:20"
simple_prerun:
- yarn install
simple_run:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"@types/eslint": "^7",
"@types/jest": "^26.0.22",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4",
"@types/node": "^14.11.2",
"@types/query-string": "^6",
Expand Down Expand Up @@ -79,8 +80,10 @@
"release": "yarn clean && yarn build && webpack --mode production"
},
"dependencies": {
"@types/json-schema": "^7.0.15",
"cross-fetch": "^3.1.4",
"is-cidr": "^4.0.2",
"json-schema": "^0.4.0",
"lodash": "^4.17.20",
"query-string": "^6.13.2"
},
Expand Down
12 changes: 8 additions & 4 deletions src/oms/core/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export default class HttpClient {
*
* #### NB! this method can return object not matching given type value
*/
async request<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
// eslint-disable-next-line @typescript-eslint/ban-types
async request<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
let merged = new RequestOpts(opts)
if (!merged.baseURL) {
merged.baseURL = this.baseConfig.baseURL
Expand Down Expand Up @@ -265,17 +266,20 @@ export default class HttpClient {
return response
}

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

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

async put<T>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
// eslint-disable-next-line @typescript-eslint/ban-types
async put<T extends {}>(opts: RequestOptsAbs): Promise<JSONResponse<T>> {
opts.method = 'PUT'
return await this.request(opts)
}
Expand Down
9 changes: 7 additions & 2 deletions src/oms/core/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ function getSigningKey(params: SigningKeyParams) {
const kRegion = hmac(kDate, encoder.encode(params.regionName))
const kService = hmac(kRegion, encoder.encode(params.serviceName))
return hmac(kService, encoder.encode('sdk_request'))
} catch (e) {
throw new Error(`Failed to generate signature key: ${e.message}`)
} catch (e: unknown) {
if (e instanceof Error) {
throw new Error(`Failed to generate signature key: ${e.message}`)
} else {
// Handle the unknown error case
throw new Error('An unknown error occurred');
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/oms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CatalogEntity, IdentityV3, ResponseToken } from './services'
export * from './core'
export * from './services'

const defaultRegion = 'eu-de'
export const defaultRegion = 'eu-de'

/**
* Client is base provider client
Expand Down
2 changes: 1 addition & 1 deletion src/oms/services/compute/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Service from '../../base'
import HttpClient from '../../../core/http'
import { Flavor, listFlavors } from './flavors'

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

/**
Expand Down
29 changes: 25 additions & 4 deletions tests/functional/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Client, cloud } from '../../src/oms'
import { Client, cloud, defaultRegion } from '../../src/oms'

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

export const authCases = ['ak/sk', 'token']
export const authCases = ['ak/sk', 'token', 'cloud']

export async function commonBeforeAll(authType: string): Promise<Client> {
let region = defaultRegion
if (process.env.OS_REGION) {
region = String(process.env.OS_REGION)
}
authUrl = 'https://iam.' + region + '.otc.t-systems.com/v3'
if (region === 'eu-ch2'){
authUrl = 'https://iam-pub.' + region + '.sc.otc.t-systems.com/v3'
}
const projectName = process.env.OS_PROJECT_NAME
const config = cloud(authUrl)
switch (authType) {
case 'ak/sk':
const ak = process.env.AWS_ACCESS_KEY_ID
const sk = process.env.AWS_SECRET_ACCESS_KEY
const projectName = process.env.OS_PROJECT_NAME
if (!ak || !sk || !projectName) {
throw 'Missing AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and OS_PROJECT_NAME required for tests'
}
Expand All @@ -23,7 +31,20 @@ export async function commonBeforeAll(authType: string): Promise<Client> {
}
config.withToken(t)
break
case 'cloud':
const domainName = process.env.OS_DOMAIN_NAME
const password = process.env.OS_PASSWORD
const username = process.env.OS_USERNAME
if (!username || !password || !domainName || !projectName) {
throw 'Missing OS_DOMAIN_NAME, OS_PASSWORD, OS_USERNAME and OS_PROJECT_NAME required for tests'
}
config
.withRegion(region)
.withProject(projectName)
.withPassword(domainName, username, password)
break
}

const client = new Client(config.config)
await client.authenticate()
return client
Expand Down
12 changes: 11 additions & 1 deletion tests/functional/services/compute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ describe.each(authCases)(
const all = await ecs.listFlavors()
expect(all).toBeDefined()
expect(all[0]).toHaveProperty('id')
const az02flavs = await ecs.listFlavors('eu-de-02')
const az02flavs = await ecs.listFlavors('eu-de-01')
expect(az02flavs).toBeDefined()
expect(az02flavs[0]).toHaveProperty('id')
expect(az02flavs.length < all.length).toBeTruthy()
})

test('ECS: list flavors in swiss region', async () => {
const ecs = client.getService(ComputeV1)
const all = await ecs.listFlavors()
expect(all).toBeDefined()
expect(all[0]).toHaveProperty('id')
const az02flavs = await ecs.listFlavors('eu-ch2b')
expect(az02flavs).toBeDefined()
expect(az02flavs[0]).toHaveProperty('id')
expect(az02flavs.length = all.length).toBeTruthy()
})
},
)
Loading

0 comments on commit 69ef622

Please sign in to comment.