Skip to content

Commit fd21de3

Browse files
committed
added second method to set up configuration
1 parent b175bc8 commit fd21de3

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

test/integration_new/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ Now select `Authorization` and submit application to be reviewed by account admi
1414

1515
### Export configuration
1616

17-
1. Select `Configuration` tab and in the bottom in the section `App Settings`
18-
download them as Json.
19-
2. Encode configuration file to Base64, e.g. using command: `base64 -i path_to_json_file`
20-
3. Set environment variable: `JWT_CONFIG_BASE_64` with base64 encoded jwt configuration file
17+
There are two ways to set up JWT configuration:
18+
1. First method:
19+
- Select `Configuration` tab and in the bottom in the section `App Settings`
20+
download your app configuration settings as JSON.
21+
- Specify the path to the JWT config file in `integration_tests.cfg`, e.g. `ConfigFilePath = /Users/me/jwt-config.json`
22+
2. Alternatively:
23+
- Select `Configuration` tab and in the bottom in the section `App Settings`
24+
download your app configuration settings as JSON.
25+
- Encode configuration file to Base64, e.g. using command: `base64 -i path_to_json_file`
26+
- Set environment variable: `JWT_CONFIG_BASE_64` with base64 encoded jwt configuration file
2127

2228
### Running Tests
2329

test/integration_new/__init__.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
import base64
2+
import configparser
23
import os
34
import json
5+
from pathlib import Path
6+
from typing import Optional
47

58
from boxsdk.auth.jwt_auth import JWTAuth
69
from boxsdk.client import Client
710

811

912
JWT_CONFIG_ENV_VAR_NAME = 'JWT_CONFIG_BASE_64'
13+
CURRENT_DIR_PATH = str(Path(os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))))
14+
CONFIG_PATH = f'{CURRENT_DIR_PATH}/integration_tests.cfg'
1015

1116

12-
def read_jwt_path_from_env_var() -> dict:
17+
def get_jwt_config() -> JWTAuth:
18+
jwt_config = read_jwt_config_from_env_var() or read_jwt_config_from_file()
1319

14-
jwt_config_base64 = os.getenv(JWT_CONFIG_ENV_VAR_NAME)
15-
if not jwt_config_base64:
20+
if not jwt_config:
1621
raise RuntimeError(
17-
f'JWT config cannot be loaded. Missing required environment variable: {JWT_CONFIG_ENV_VAR_NAME}.'
22+
f'JWT config cannot be loaded. Missing environment variable: {JWT_CONFIG_ENV_VAR_NAME} or JWT config path.'
1823
)
24+
return jwt_config
25+
26+
27+
def read_jwt_config_from_env_var() -> Optional[JWTAuth]:
28+
29+
jwt_config_base64 = os.getenv(JWT_CONFIG_ENV_VAR_NAME)
30+
if not jwt_config_base64:
31+
return None
1932
jwt_config_str = base64.b64decode(jwt_config_base64)
33+
jwt_config_json = json.loads(jwt_config_str)
34+
return JWTAuth.from_settings_dictionary(jwt_config_json)
35+
2036

21-
return json.loads(jwt_config_str)
37+
def read_jwt_config_from_file():
38+
config_parser = configparser.ConfigParser()
39+
config_parser.read(CONFIG_PATH)
40+
jwt_config_file_path = config_parser["JWT"].get('ConfigFilePath')
41+
if not jwt_config_file_path:
42+
return None
43+
return JWTAuth.from_settings_file(jwt_config_file_path)
2244

2345

24-
jwt_config_json = read_jwt_path_from_env_var()
25-
jwt_config = JWTAuth.from_settings_dictionary(jwt_config_json)
26-
CLIENT = Client(jwt_config)
46+
CLIENT = Client(get_jwt_config())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[JWT]
2+
ConfigFilePath =

0 commit comments

Comments
 (0)