Skip to content

Commit

Permalink
refactor to pass environment vars to hbs calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Paterick committed Sep 12, 2023
1 parent afd58aa commit dcf39f4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/services/hbs.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import axios from 'axios'
import { AUTH_SERVICE_URL, AUTH_SERVICE_VERSION } from '../utils/hbsConfiguration'
import { authServiceUrl, authServiceVersion } from '../utils/hbsConfiguration'
import { httpCall } from '../utils/httpProvider'

export const kycLevel1 = 'holo_kyc_1'
export const kycLevel2 = 'holo_kyc_2'

async function authCall(args) {
async function authCall(args, envirionment, hbsServicePort) {
return httpCall({
serviceUrl: AUTH_SERVICE_URL,
version: AUTH_SERVICE_VERSION,
serviceUrl: authServiceUrl(envirionment),
version: authServiceVersion(hbsServicePort),
method: 'post',
...args
})
}

export async function authenticateAgent(payload, signature) {
export async function authenticateAgent(payload, signature, envirionment, hbsServicePort) {
try {
const result = await authCall({
params: payload,
endpoint: 'holo-client',
headers: {
'X-Signature': signature
}
},
envirionment,
hbsServicePort
})

return result.data
Expand All @@ -34,8 +36,8 @@ export async function authenticateAgent(payload, signature) {
}
}

export async function loadAgentKycLevel(payload, signature) {
const authResult = await authenticateAgent(payload, signature)
export async function loadAgentKycLevel(payload, signature, envirionment, hbsServicePort) {
const authResult = await authenticateAgent(payload, signature, envirionment, hbsServicePort)
return (authResult && authResult.kyc) ? (authResult.kyc === kycLevel2) ? 2 : 1 : null
}

4 changes: 2 additions & 2 deletions src/stores/useClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const makeUseClientStore = ({ useInterfaceStore, onInit }) => defineStore('clien
return result
},

async getKycLevel() {
const kycLevel = await useInterfaceStore().getKycLevel()
async getKycLevel(envirionment, hbsServicePort) {
const kycLevel = await useInterfaceStore().getKycLevel(envirionment, hbsServicePort)
this.agentKyc = kycLevel
return kycLevel
}
Expand Down
4 changes: 2 additions & 2 deletions src/stores/useHoloStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo',
this.appInfo = await client.appInfo()
return this.appInfo
},
async getKycLevel() {
async getKycLevel(envirionment, hbsServicePort) {
const payload = {
"email": this.agentEmail,
"timestamp": Date.now() - (30 * 1000), // Subtract 30 sec to prevent "future" timestamp error from API
"pubKey": this.agentId
}

const { _, signature } = await client.signPayload(payload)
const kycLevel = await loadAgentKycLevel(payload, signature)
const kycLevel = await loadAgentKycLevel(payload, signature, envirionment, hbsServicePort)
this.kycLevel = kycLevel
return kycLevel
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useHolochainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, is_hpos_served, h
resolve()
})
},
async getKycLevel() {
async getKycLevel(_, _) {
return null // raw holochain doesn't have a mechanism for fetching agent's kyc level
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useHoloportAPIStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const makeUseHoloportAPIStore = ({ useHolochainStore }) => defineStore('holoport
throw new Error(`No case in hposCall for ${method} method`)
}
},
async getKycLevel() {
async getKycLevel(_, _) {
const kycLevel = await this.hposHolochainCall({path: 'kyc', headers: {}, params: {}, method: 'get'})
return kycLevel ? (kycLevel === kycLevel2) ? 2 : 1 : null
},
Expand Down
22 changes: 12 additions & 10 deletions src/utils/hbsConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ const HbsServiceURL = (service, key, port) => {
[Environment.qa]: 'v1',
[Environment.production]: 'v1'
}
const CONFIG_ENVIRONMENT = ( import.meta.env ) ? import.meta.env.VITE_ENV : process.env.VUE_ENV
const HBS_SERVICE_PORT = ( import.meta.env ) ? import.meta.env.VITE_OPS_SERVICE_PORT : process.env.VUE_OPS_SERVICE_PORT

export const AUTH_SERVICE_URL = HbsServiceURL(
'auth',
CONFIG_ENVIRONMENT || Environment.localNoBackend,
HBS_SERVICE_PORT || '3003'
)

export const AUTH_SERVICE_VERSION = CONFIG_ENVIRONMENT
? AuthServiceVersion[CONFIG_ENVIRONMENT]
export const authServiceVersion = function(envirionment) {
return (envirionment)
? AuthServiceVersion[envirionment]
: AuthServiceVersion[Environment.local]
}

export const authServiceUrl = function(envirionment, hbsServicePort) {
return HbsServiceURL(
'auth',
envirionment || Environment.localNoBackend,
hbsServicePort || '3003'
)
}


0 comments on commit dcf39f4

Please sign in to comment.