Skip to content

Commit

Permalink
change vault write secret return status code
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmssdish committed Dec 18, 2023
1 parent cda5b0b commit 5c9b6b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions findr/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,12 @@ class Oracle {
const vaultUrl = process.env.VAULT_URL ?? ''
const vaultToken = process.env.VAULT_TOKEN ?? ''
const vaultPath = `${deviceId}-${this.uuid}`
console.log('vaultPath:', vaultPath)
const vaultValue = this.messageToSent
const vaultClient = new VaultClient(vaultUrl)
await vaultClient.authenticate(vaultToken)
await vaultClient.writeSecret(vaultPath, vaultValue)
console.log('vaultPath:', vaultPath)
const vaultWriteResponse = await vaultClient.writeSecret(vaultPath, vaultValue)
console.log('vaultWriteResponse:', vaultWriteResponse)

const sendOrchestratorRequestUrl = process.env.FINDR_ORCHESTRATOR_URL ?? ''
const sendOrchestratorRequestResponse = await this.sendOrchestratorRequest(
Expand Down
6 changes: 4 additions & 2 deletions findr/oracle/vault-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ class VaultClient {
* @param secretData - The data to be written as the secret.
* @throws {Error} - If the client is not authenticated.
*/
async writeSecret (path: string, secretData: any): Promise<void> {
async writeSecret (path: string, secretData: any): Promise<any> {
if (this.token === null || this.token === undefined) {
throw new Error('Client is not authenticated')
}

const encodedPath = this.encodeSpecialCharacters(path)

await axios.post(`${this.vaultUrl}/v1/cubbyhole/${encodedPath}`, secretData, {
const response: AxiosResponse = await axios.post(`${this.vaultUrl}/v1/cubbyhole/${encodedPath}`, secretData, {
headers: { 'X-Vault-Token': this.token, 'Content-Type': 'application/json', accept: '*/*' }
})

return response.status
}

/**
Expand Down

0 comments on commit 5c9b6b4

Please sign in to comment.