Skip to content

Commit 40058db

Browse files
authored
Feature/run environment variable (#64)
* adding issuer loader * refactoring test and integrating lazyload for vaccinecode * referring to cached issuers map * run environment variable - updating resources
1 parent 867b243 commit 40058db

36 files changed

+625
-120
lines changed

.env.sample

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
API_URL=https://shcv-services.tcpdev.org
2+
API_VERSION=v1
3+
API_PATH=api
4+
ISSUER_PATH=vci-directory
5+
LOCALE_PATH=locales
6+
VCCODE_PATH=vaccinecodes
7+
8+
# Please contact us for api key
9+
API_KEY=12345678-0000-0000-0000-000000000000

.github/workflows/deploy-s3.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Deploy files to S3'
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
7+
env:
8+
S3_BUCKET_DEV: shc-verifier-services-dev
9+
S3_BUCKET_TEST: shc-verifier-services-test
10+
S3_BUCKET_PROD: shc-verifier-services-prod
11+
S3_LOCALE_DIR: locales
12+
S3_VACCINE_CODES_DIR: vaccine-codes
13+
LOCAL_SOURCE_FILE: vci-issuers.json
14+
REGION: us-east-1
15+
ROLE_TO_ASSUME: arn:aws:iam::789379687343:role/GithubECSRole
16+
ROLE_SESSION_NAME: GithubActionsECSDev
17+
18+
jobs:
19+
deployDev:
20+
if: contains(github.ref, '-locale-dev')
21+
name: 'Deploy locale file to TCP dev'
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@master
25+
- name: 'Configure Dev AWS Role'
26+
uses: aws-actions/configure-aws-credentials@v1
27+
with:
28+
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
29+
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
30+
aws-region: ${{ env.REGION }}
31+
role-to-assume: ${{ env.ROLE_TO_ASSUME }}
32+
role-duration-seconds: 1200
33+
role-session-name: ${{ env.ROLE_SESSION_NAME }}
34+
- name: 'Sync locale files to S3'
35+
run: |
36+
cd resources/public/locals; aws s3 sync . 's3://${{ env.S3_BUCKET_DEV }}/${{ env.S3_LOCALE_DIR }}'
37+
38+
deployTest:
39+
if: contains(github.ref, '-locale-test')
40+
name: 'Deploy locale file to TCP test'
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@master
44+
- name: 'Configure Dev AWS Role'
45+
uses: aws-actions/configure-aws-credentials@v1
46+
with:
47+
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
48+
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
49+
aws-region: ${{ env.REGION }}
50+
role-to-assume: ${{ env.ROLE_TO_ASSUME }}
51+
role-duration-seconds: 1200
52+
role-session-name: ${{ env.ROLE_SESSION_NAME }}
53+
- name: 'Sync locale files to S3'
54+
run: |
55+
cd resources/public/locals; aws s3 sync . 's3://${{ env.S3_BUCKET_TEST }}/${{ env.S3_LOCALE_DIR }}'
56+
57+
deployProd:
58+
if: contains(github.ref, '-locale-prod')
59+
name: 'Deploy locale file to TCP production
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@master
63+
- name: 'Configure Dev AWS Role'
64+
uses: aws-actions/configure-aws-credentials@v1
65+
with:
66+
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
67+
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
68+
aws-region: ${{ env.REGION }}
69+
role-to-assume: ${{ env.ROLE_TO_ASSUME }}
70+
role-duration-seconds: 1200
71+
role-session-name: ${{ env.ROLE_SESSION_NAME }}
72+
- name: 'Sync issuers file to S3'
73+
run: |
74+
cd resources/public/locals; aws s3 sync . 's3://${{ env.S3_BUCKET_PROD }}/${{ env.S3_LOCALE_DIR }}'

.github/workflows/test-readiness.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: learn-github-actions
1+
name: 'Linting CI'
22
on:
33
push:
44
types: [opened, synchronize]
@@ -12,3 +12,4 @@ jobs:
1212
node-version: '16'
1313
- run: npm install
1414
- run: npm test
15+

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ buck-out/
6363

6464
# CocoaPods
6565
/ios/Pods/
66+
67+
68+
#env
69+
.env.development
70+
.env.production

App.tsx

+16-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { SafeAreaProvider } from 'react-native-safe-area-context'
1313
import { getProvider as getLocalProvider } from './src/contexts/LocaleContext'
1414
import { NavigationContainer } from '@react-navigation/native'
1515
import { createStackNavigator } from '@react-navigation/stack'
16+
import { getProvider as getRemoteDataSyncProvider } from './src/contexts/RemoteDataSyncContext'
1617

1718
import { Buffer } from 'buffer'
1819

@@ -58,22 +59,25 @@ const App = () => {
5859

5960
const isDarkMode = useColorScheme() === 'dark'
6061
const [ LocaleProvider ] = getLocalProvider()
62+
const [ RemoteDataSyncProvider ] = getRemoteDataSyncProvider()
6163
const backgroundStyle = {
6264
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
6365
}
6466
return (
65-
<LocaleProvider>
66-
<SafeAreaProvider>
67-
<NavigationContainer>
68-
<Stack.Navigator screenOptions={ { headerShown: false } }>
69-
<Stack.Screen name="Welcome" component={ WelcomePage } />
70-
<Stack.Screen name="ScanQR" component={ ScanQRPage } />
71-
<Stack.Screen name="VerificationResult" component={ VerificationResultPage } />
72-
<Stack.Screen name="Error" component={ ErrorPage } />
73-
</Stack.Navigator>
74-
</NavigationContainer>
75-
</SafeAreaProvider>
76-
</LocaleProvider>
67+
<RemoteDataSyncProvider>
68+
<LocaleProvider>
69+
<SafeAreaProvider>
70+
<NavigationContainer>
71+
<Stack.Navigator screenOptions={ { headerShown: false } }>
72+
<Stack.Screen name="Welcome" component={ WelcomePage } />
73+
<Stack.Screen name="ScanQR" component={ ScanQRPage } />
74+
<Stack.Screen name="VerificationResult" component={ VerificationResultPage } />
75+
<Stack.Screen name="Error" component={ ErrorPage } />
76+
</Stack.Navigator>
77+
</NavigationContainer>
78+
</SafeAreaProvider>
79+
</LocaleProvider>
80+
</RemoteDataSyncProvider>
7781
)
7882
}
7983

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ Node **v14.17.X** (LTS/fermium)
4848
[Android Studio](https://developer.android.com/studio/install)
4949
Android Studio SDK 30 download through android studio
5050

51-
52-
### Platform base setup
51+
### Environment File setup
52+
copy .env.sample and change it to .env.development
53+
for API_KEY for production, please contact us.
5354

5455

56+
### Platform base setup
5557
For Android
5658
make sure you download sdk using android studio SDK 30
5759

__tests__/VaccineCodes-test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import { getVaccineCodesHash, loadVaccineCodes } from '../src/services/helpers/getVaccineCodesHash'
3+
const fs = require('fs')
4+
const path = require('path')
5+
6+
it('VaccineCode retrieved Correctly', async () => {
7+
await loadVaccineCodes()
8+
var codes = getVaccineCodesHash();
9+
expect(codes!=null).toEqual(true)
10+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {} from '@react-native-async-storage/async-storage/jest/async-storage-mock';

__tests__/__mock__/barcode.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jest.mock('../../src/components/BarCodeScanner', () => "Barcode" )
2+
jest.mock('react-native-qrcode-scanner', () => "Barcode" )
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const API_URL="https://shcv-services.tcpdev.org"
2+
export const API_VERSION="v1"
3+
export const API_PATH="api"
4+
export const ISSUER_PATH="vci-directory"
5+
export const LOCALE_PATH="locales"
6+
export const VCCODE_PATH="vaccinecodes"
7+
export const API_KEY="12345678-0000-0000-0000-000000000000"
8+
9+
const env = {
10+
API_URL,
11+
API_VERSION,
12+
API_PATH,
13+
ISSUER_PATH,
14+
LOCALE_PATH,
15+
VCCODE_PATH,
16+
API_KEY
17+
}
18+
19+
export default env;

__tests__/__mock__/setup.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
jest.mock('react-native-device-info', () => {
2+
return {
3+
getVersion: () => 4,
4+
getUniqueId: async ()=> '7291383138913323',
5+
getBundleId: async ()=> 'com.thecommonsproject.smarthealthcardverifier'
6+
}
7+
})
8+
9+
jest.mock('uuid', ()=>{
10+
return {
11+
v5:()=>"testuuid"
12+
}
13+
})

android/app/build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
44

5+
6+
57
/**
68
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
79
* and bundleReleaseJsAndAssets).
@@ -77,11 +79,19 @@ import com.android.build.OutputFile
7779
* ]
7880
*/
7981

82+
83+
project.ext.envConfigFiles = [
84+
debug : ".env.development",
85+
release : ".env.production"
86+
]
87+
8088
project.ext.react = [
8189
enableHermes: false, // clean and rebuild if changing
8290
]
8391

8492
apply from: "../../node_modules/react-native/react.gradle"
93+
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
94+
8595

8696
/**
8797
* Set this to true to create two separate APKs instead of one:

android/settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ include ':react-native-camera'
99
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
1010
include ':react-native-permissions'
1111
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
12+
include ':react-native-config'
13+
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
1214
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
1315
include ':app'

config/jest/jest.config.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ const config: Config.InitialOptions = {
2424
coveragePathIgnorePatterns: [
2525
'*node_modules*'
2626
],
27+
testPathIgnorePatterns: [
28+
'<rootDir>/__tests__/__mock__'
29+
],
2730
rootDir: rootPath,
2831
setupFiles:[
29-
'<rootDir>/config/jest/setup.js',
30-
'<rootDir>/config/jest/mock/mockPermissions.js',
31-
'<rootDir>/config/jest/mock/barcode.js',
32-
'<rootDir>/config/jest/mock/netinfo.js',
32+
'<rootDir>/__tests__/__mock__/setup.js',
33+
'<rootDir>/__tests__/__mock__/mockPermissions.js',
34+
'<rootDir>/__tests__/__mock__/barcode.js',
35+
'<rootDir>/__tests__/__mock__/netinfo.js',
3336
'<rootDir>/node_modules/react-native-gesture-handler/jestSetup.js'
3437
],
38+
moduleNameMapper:{
39+
'@react-native-async-storage/async-storage': "<rootDir>/__tests__/__mock__/@react-native-async-storage/async-storage",
40+
'react-native-config': "<rootDir>/__tests__/__mock__/react-native-config/react-native-config"
41+
},
3542
preset: 'react-native',
3643
moduleFileExtensions: [
3744
'ts',

config/jest/mock/barcode.js

-2
This file was deleted.

config/jest/setup.js

-5
This file was deleted.

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
"version": "1.0.39",
44
"description": "SMART Health Card Verifier",
55
"scripts": {
6-
"android": "react-native run-android",
7-
"ios": "react-native run-ios",
8-
"start": "react-native start",
6+
"android": "export ENVFILE=.env.development && react-native run-android",
7+
"build-dev:android": "export ENVFILE=.env.development && cd android && ./gradlew assembleDebug",
8+
"ios": "ENVFILE=.env.staging react-native run-ios",
9+
"start": "export ENVFILE=.env.staging && react-native start",
910
"test": "jest -c ./config/jest/jest.config.ts",
1011
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1112
"lint:fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
1213
"bundle-service": "tsc-bundle ./resources/apis/src/index.ts --outFile ./resources/apis/output/bundle.js",
1314
"generateAndroid": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res"
1415
},
1516
"dependencies": {
17+
"@react-native-async-storage/async-storage": "^1.16.1",
1618
"@react-native-community/netinfo": "^7.1.9",
1719
"@react-navigation/native": "^6.0.6",
1820
"@react-navigation/stack": "^6.0.11",
@@ -25,6 +27,7 @@
2527
"react-i18next": "^11.15.3",
2628
"react-native": "0.66.2",
2729
"react-native-camera": "^4.2.1",
30+
"react-native-config": "^1.4.5",
2831
"react-native-device-info": "^8.4.5",
2932
"react-native-gesture-handler": "^1.10.3",
3033
"react-native-jose": "git+https://github.com/hellojoko/react-native-jose.git",

resources/public/locales/en/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"key":"en",
3-
"lang":"en",
3+
"language":"en",
44
"region":"default",
55
"data": {
66
"default": {

resources/public/locales/fr/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"key":"fr",
3-
"lang":"fr",
3+
"language":"fr",
44
"region":"default",
55
"data": {
66
"default": {

resources/public/locales/ja/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"key":"ja",
3-
"lang":"ja",
3+
"language":"ja",
44
"region":"default",
55
"data": {
66
"default": {

src/config/config.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import env from 'react-native-config'
2+
3+
console.info("Env: " + JSON.stringify( env ) )
4+
const config = {
5+
api: {
6+
uri: env.API_URL,
7+
key: env.API_KEY,
8+
backupURL: env.AFFINIDI_SERVICE_SERVICE_URL,
9+
version: env.API_VERSION,
10+
path: env.API_PATH,
11+
services: {
12+
issuers: env.ISSUER_PATH,
13+
locale: env.LOCALE_PATH,
14+
vaccienCodes: env.VCCODE_PATH
15+
}
16+
},
17+
};
18+
19+
console.info("CONFIG: " + JSON.stringify( config ) )
20+
21+
const API_HOST = config.api.uri;
22+
const API_PATH = `${config.api.path}/${config.api.version}`
23+
const API_KEY = config.api.key;
24+
const API_VERSION = config.api.version;
25+
const AFFINIDI_HOST = env.AFFINIDI_SERVICE_SERVICE_URL;
26+
const API_ISSUERS_PATH = config.api.services.issuers;
27+
const API_LOCALE_PATH = config.api.services.locale;
28+
const API_VCCODE_PATH = config.api.services.vaccienCodes;
29+
30+
export {
31+
API_PATH,
32+
API_HOST,
33+
API_KEY,
34+
API_VERSION,
35+
AFFINIDI_HOST,
36+
API_ISSUERS_PATH,
37+
API_LOCALE_PATH,
38+
API_VCCODE_PATH,
39+
}
40+
41+
export default config

src/contexts/LocaleContext.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import RNLocalize from 'react-native-localize'
33
import { createContext } from './Context'
44
import i18nUtils from '../services/i18n/i18nUtils'
55
import LoadingSpinner from '../components/LoadingSpinner'
6-
76
const i18n = i18nUtils.initailize()
87

98
interface localeType {

0 commit comments

Comments
 (0)