Skip to content

Commit

Permalink
# updated ChapterReader with env vars and authentication
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed May 29, 2024
1 parent 18f7c15 commit d415287
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 11 additions & 2 deletions tools/src/tester/ChapterReader.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import axios from 'axios'
import { type ChapterRequest, type ActualResponse, type Parameter } from './types/story.types'
import { Agent } from 'https'

// A lightweight client for testing the API
export default class ChapterReader {
url: string
admin_password: string

constructor (url: string) {
this.url = url
constructor () {
this.url = process.env.OPENSEARCH_URL ?? 'https://localhost:9200'
if (process.env.OPENSEARCH_PASSWORD == null) throw new Error('OPENSEARCH_PASSWORD is not set')
this.admin_password = process.env.OPENSEARCH_PASSWORD
}

async read (chapter: ChapterRequest): Promise<ActualResponse> {
const response: Record<string, any> = {}
const [url, params] = this.#parse_url(chapter.path, chapter.parameters ?? {})
await axios.request({
url,
auth: {
username: 'admin',
password: this.admin_password
},
httpsAgent: new Agent({ rejectUnauthorized: false }),
method: chapter.method,
params,
data: chapter.request_body?.payload
Expand Down
3 changes: 1 addition & 2 deletions tools/src/tester/TestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default class TestsRunner {
this.path = resolve(path)
this.opts = opts

// TODO: Grab server URL from environment variable and add authentication.
const chapter_reader = new ChapterReader('http://localhost:9200')
const chapter_reader = new ChapterReader()
const spec_parser = new SpecParser(spec)
const schema_validator = new SchemaValidator(spec)
SharedResources.create_instance({ chapter_reader, schema_validator, spec_parser })
Expand Down

0 comments on commit d415287

Please sign in to comment.