Skip to content

Commit

Permalink
refactor env
Browse files Browse the repository at this point in the history
  • Loading branch information
0xverin committed Oct 31, 2024
1 parent 77e7e27 commit 13377c4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 33 deletions.
23 changes: 9 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ jobs:
runs-on: ubuntu-latest
needs:
- contracts-uint-tests

env:
TWITTER_AUTH_TOKEN_V2: ${{ secrets.TWITTER_AUTH_TOKEN_V2 }}
DISCORD_AUTH_TOKEN: ${{ secrets.DISCORD_AUTH_TOKEN }}
ACHAINABLE_AUTH_KEY: ${{ secrets.ACHAINABLE_AUTH_KEY }}
ONEBLOCK_NOTION_KEY: ${{ secrets.ONEBLOCK_NOTION_KEY }}
NODEREAL_API_KEY: ${{ secrets.NODEREAL_API_KEY }}
GENIIDATA_API_KEY: ${{ secrets.GENIIDATA_API_KEY }}
MORALIS_API_KEY: ${{ secrets.MORALIS_API_KEY }}
MAGIC_CRAFT_API_KEY: ${{ secrets.MAGIC_CRAFT_API_KEY }}
steps:
- uses: actions/checkout@v4

Expand All @@ -77,13 +67,18 @@ jobs:
docker pull litentry/identity-worker:latest
docker pull litentry/identity-cli:latest
docker pull litentry/litentry-chain-aio:latest
- name: Create env file with secrets
run: |
mkdir -p /opt/worker_configs
for key in TWITTER_AUTH_TOKEN_V2 DISCORD_AUTH_TOKEN ACHAINABLE_AUTH_KEY ONEBLOCK_NOTION_KEY NODEREAL_API_KEY GENIIDATA_API_KEY MORALIS_API_KEY MAGIC_CRAFT_API_KEY; do
echo "$key=${{ secrets[$key] }}" >> /opt/worker_configs/worker_env
done
echo "TWITTER_AUTH_TOKEN_V2=${{ secrets.TWITTER_AUTH_TOKEN_V2 }}" >> /opt/worker_configs/worker_env
echo "DISCORD_AUTH_TOKEN=${{ secrets.DISCORD_AUTH_TOKEN }}" >> /opt/worker_configs/worker_env
echo "ACHAINABLE_AUTH_KEY=${{ secrets.ACHAINABLE_AUTH_KEY }}" >> /opt/worker_configs/worker_env
echo "ONEBLOCK_NOTION_KEY=${{ secrets.ONEBLOCK_NOTION_KEY }}" >> /opt/worker_configs/worker_env
echo "NODEREAL_API_KEY=${{ secrets.NODEREAL_API_KEY }}" >> /opt/worker_configs/worker_env
echo "GENIIDATA_API_KEY=${{ secrets.GENIIDATA_API_KEY }}" >> /opt/worker_configs/worker_env
echo "MORALIS_API_KEY=${{ secrets.MORALIS_API_KEY }}" >> /opt/worker_configs/worker_env
echo "MAGIC_CRAFT_API_KEY=${{ secrets.MAGIC_CRAFT_API_KEY }}" >> /opt/worker_configs/worker_env
- name: Start parachain-worker
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions vc-di-tests/integration-tests/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
NODE_ENV=local

TWITTER_AUTH_TOKEN_V2=''
DISCORD_AUTH_TOKEN=''
ACHAINABLE_AUTH_KEY=''
ONEBLOCK_NOTION_KEY=''
NODEREAL_API_KEY=''
Expand Down
1 change: 1 addition & 0 deletions vc-di-tests/integration-tests/.env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=staging
21 changes: 4 additions & 17 deletions vc-di-tests/integration-tests/assertion_contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { byId } from '@litentry/chaindata'
import { $ as zx } from 'zx'
import { CredentialDefinition, credentialsJson } from './common/credential-json'
import { Keyring } from '@polkadot/keyring'

import { env } from './common/loadEnv'
function randomContractId(): string {
const bytes = randomBytes(20)
return '0x' + bytes.toString('hex')
Expand Down Expand Up @@ -224,19 +224,6 @@ describe('Test Vc (direct request)', function () {
}
}
before(async () => {
console.log(
`process.env.GENIIDATA_API_KEY!`,
process.env.GENIIDATA_API_KEY!
)
console.log(
`process.env.NODEREAL_API_KEY!`,
process.env.NODEREAL_API_KEY!
)
console.log(
`process.env.MORALIS_API_KEY!`,
process.env.MORALIS_API_KEY!
)

context = await initIntegrationTestContext(
nodeEndpoint,
enclaveEndpoint
Expand All @@ -251,9 +238,9 @@ describe('Test Vc (direct request)', function () {
path: '../../artifacts/contracts/token_holding_amount/TokenMapping.sol/TokenMapping.json',
secrets: [
// The order is very important, refer to the order of secrets(/contracts/token_holding_amount/TokenQueryLogic.sol:queryBalance(...secrets)).
generateSecrets(process.env.GENIIDATA_API_KEY!, context),
generateSecrets(process.env.NODEREAL_API_KEY!, context),
generateSecrets(process.env.MORALIS_API_KEY!, context),
generateSecrets(env.GENIIDATA_API_KEY, context),
generateSecrets(env.NODEREAL_API_KEY, context),
generateSecrets(env.MORALIS_API_KEY, context),
],
bytecode: '',
contractId: randomContractId(),
Expand Down
43 changes: 43 additions & 0 deletions vc-di-tests/integration-tests/common/loadEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import dotenv from 'dotenv'
import path from 'path'
import { z } from 'zod'

const envSchema = z.object({
TWITTER_AUTH_TOKEN_V2: z.string(),
DISCORD_AUTH_TOKEN: z.string(),
ACHAINABLE_AUTH_KEY: z.string(),
ONEBLOCK_NOTION_KEY: z.string(),
NODEREAL_API_KEY: z.string(),
GENIIDATA_API_KEY: z.string(),
MORALIS_API_KEY: z.string(),
MAGIC_CRAFT_API_KEY: z.string(),
})

export type EnvConfig = z.infer<typeof envSchema>

export const loadEnv = (): EnvConfig => {
const envPath =
process.env.NODE_ENV === 'local'
? path.resolve(process.cwd(), '.env.local')
: '/opt/worker_configs/worker_env'

const result = dotenv.config({ path: envPath })

if (result.error) {
throw new Error(
`Failed to load environment variables: ${result.error.message}`
)
}

const parsed = envSchema.safeParse(result.parsed)

if (!parsed.success) {
throw new Error(
`Invalid environment variables: ${parsed.error.message}`
)
}

return parsed.data
}

export const env = loadEnv()
5 changes: 3 additions & 2 deletions vc-di-tests/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"check-types": "tsc --noEmit"
},
"dependencies": {
"@litentry/parachain-api": "latest",
"@litentry/sidechain-api": "latest",
"@litentry/vc-schema-validator": "latest",
"@noble/ed25519": "^1.7.3",
"@polkadot/api": "^10.9.1",
Expand Down Expand Up @@ -37,13 +39,12 @@
"micro-base58": "^0.5.1",
"mocha": "^10.1.0",
"mocha-steps": "^1.3.0",
"@litentry/parachain-api": "latest",
"scale-ts": "^0.2.11",
"@litentry/sidechain-api": "latest",
"tiny-secp256k1": "^2.2.3",
"tweetnacl": "^1.0.3",
"websocket-as-promised": "^2.0.1",
"ws": "^8.17.1",
"zod": "^3.23.8",
"zx": "^7.2.3"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions vc-di-tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13377c4

Please sign in to comment.