Skip to content

Commit 09cd0d4

Browse files
authored
feat: load from env (#363)
* feat: load from env * fix: tests * feat: add var
1 parent 9d15988 commit 09cd0d4

File tree

8 files changed

+18
-9
lines changed

8 files changed

+18
-9
lines changed

.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
JWT_SECRET_KEY="secret"
22
NODE_ENV="development"
33

4-
PROVIDER_KEYFILE=accounts/provider.json
4+
#PROVIDER_KEYFILE=accounts/provider.json
55
RSA_PRIVKEY_FILE=accounts/rsa_priv_key.pem
66
RSA_PUBKEY_FILE=accounts/rsa_pub_key.pem
77
AUTHLIB_INSECURE_TRANSPORT=true

.github/workflows/testing-integration.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ jobs:
3737
env:
3838
IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }}
3939
IPFS_PROJECT_SECRET: ${{ secrets.IPFS_PROJECT_SECRET }}
40+
PROVIDER_KEYFILE: ${{ secrets.PROVIDER_KEYFILE }}
4041
run: |
4142
yarn setup:dev
4243
yarn start &
4344
4445
# wait for node to start
4546
wget --retry-connrefused --tries=20 http://localhost:8030
4647
- name: Run tests
48+
env:
49+
PROVIDER_KEYFILE: ${{ secrets.PROVIDER_KEYFILE }}
4750
run: |
4851
# HDWalletProvider keeps jest from exiting
4952
yarn integration --detectOpenHandles

.github/workflows/testing-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
./scripts/wait-nevermined.sh
3838
- name: Start node
3939
env:
40-
PROVIDER_KEYFILE: accounts/provider.json
40+
PROVIDER_KEYFILE: ${{ secrets.PROVIDER_KEYFILE }}
4141
RSA_PRIVKEY_FILE: accounts/rsa_priv_key.pem
4242
RSA_PUBKEY_FILE: accounts/rsa_pub_key.pem
4343
PROVIDER_BABYJUB_SECRET: ${{ secrets.PROVIDER_BABYJUB_SECRET }}

.github/workflows/testing.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- name: Check code formatting
2222
run: yarn format:check
2323
- name: Run tests
24+
env:
25+
PROVIDER_KEYFILE: ${{ secrets.PROVIDER_KEYFILE }}
2426
run: |
2527
yarn setup:dev
2628
yarn test --detectOpenHandles

config/nevermined.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ const configBase = {
1919
configBase.accounts = []
2020

2121
if (process.env.PROVIDER_KEYFILE) {
22-
const str = fs.readFileSync(process.env.PROVIDER_KEYFILE).toString()
23-
configBase.accounts = [ethers.Wallet.fromEncryptedJsonSync(str, process.env.PROVIDER_PASSWORD)]
22+
configBase.accounts = [
23+
ethers.Wallet.fromEncryptedJsonSync(
24+
process.env.PROVIDER_KEYFILE,
25+
process.env.PROVIDER_PASSWORD,
26+
),
27+
]
2428
}
2529

2630
const config = configBase

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-ts",
3-
"version": "3.0.20",
3+
"version": "3.0.21",
44
"description": "Nevermined Node",
55
"main": "main.ts",
66
"scripts": {

src/encrypt/encrypt.controller.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EncryptController } from './encrypt.controller'
66
import request from 'supertest'
77
import { ConfigModule } from '../shared/config/config.module'
88
import { ConfigService } from '../shared/config/config.service'
9-
import { accountFromCredentialsFile, decrypt } from '../common/helpers/encryption.helper'
9+
import { accountFromCredentialsData, decrypt } from '../common/helpers/encryption.helper'
1010

1111
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument */
1212

@@ -47,8 +47,8 @@ describe('Info', () => {
4747
expect(await decrypt(config.cryptoConfig(), result, 'PSK-RSA')).toBe('msg')
4848
})
4949

50-
it('load NvmAccount from credentials file', async () => {
51-
const account = await accountFromCredentialsFile(
50+
it('load NvmAccount from credentials data', async () => {
51+
const account = await accountFromCredentialsData(
5252
process.env.PROVIDER_KEYFILE as string,
5353
process.env.PROVIDER_PASSWORD as string,
5454
)

src/shared/config/config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class ConfigService {
154154
this.envConfig = this.validateInput(configProfile)
155155
this.crypto = {
156156
provider_password: this.get('PROVIDER_PASSWORD') || '',
157-
provider_key: readFileSync(this.get('PROVIDER_KEYFILE') || '').toString(),
157+
provider_key: this.get('PROVIDER_KEYFILE') || '',
158158
provider_rsa_public: readFileSync(this.get('RSA_PUBKEY_FILE') || '').toString(),
159159
provider_rsa_private: readFileSync(this.get('RSA_PRIVKEY_FILE') || '').toString(),
160160
}

0 commit comments

Comments
 (0)