Skip to content

Commit 6d501bb

Browse files
authored
Merge pull request #48 from CMSgov/brandon/BB2-4376-v3-changes
Brandon/bb2 4376 v3 changes
2 parents 1218d0e + b291354 commit 6d501bb

5 files changed

Lines changed: 54 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,6 @@ bb2_venv/
169169
# BB2 ignores
170170
.bluebutton-config.json
171171
.bluebutton-config.yaml
172+
173+
# Snyk Security Extension - AI Rules (auto-generated)
174+
.github/instructions/snyk_rules.instructions.md

README-sdk-dev.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,50 @@ To do this, edit the following line in the `./cms_bluebutton/version.py` file wi
315315
__version__ = "1.0.0",
316316
```
317317
318+
### Testing Locally
319+
320+
The current method for seeing the SDK in action is fairly complex, as it requires also setting up the Python sample client (https://github.com/CMSgov/bluebutton-sample-client-python-react/tree/main). These both, of course, depend upon the web-server repo for most of their logic. It is possible that in order to fully understand an issue that arises within the SDK or the sample client, a developer would have to track changes across 3 separate projects. There should be some future work to simplify this process as it is very manual and laborious.
321+
322+
The steps listed here are listed elsewhere in the documentation but for the sake of convenience, they are partially repeated here
323+
and written together so that a developer should be able to follow this step by step.
324+
325+
The overall goals are to:
326+
327+
- Build a local version of the SDK
328+
- Run a local version of sample client that consumes a local version of the SDK
329+
330+
### Building a local version of the SDK
331+
332+
Run the following commands in the base of this SDK repository. The commands suppose that you have the Python sample client cloned in the same folder as this SDK repo. Do not be in a virtualenv while running these commands.
333+
334+
```
335+
rm -rf build/
336+
python -m build --wheel --o ../bluebutton-sample-client-python-react/server
337+
```
338+
339+
The --o (or outdir) command should effectively 'copy paste' the built version of the .whl file into where it would be needed for the sample client. If you do not want it in the sample client, omit the --o and file path.
340+
341+
### Run a local version of sample client that consumes a local version of the SDK
342+
343+
Ensure that in bluebutton-sample-client-python-react/server/Dockerfile, uncomment the following line. Replace the version number (1.0.4 in the example) of the .whl file with what has been generated from the previous build command.
344+
345+
```
346+
RUN pip install cms_bluebutton_sdk-1.0.4-py3-none-any.whl
347+
```
348+
349+
In bluebutton-sample-client-python-react/server/Pipfile, add this line:
350+
351+
```
352+
cms-bluebutton-sdk = {file = "./cms_bluebutton_sdk-1.0.4-py3-none-any.whl"}
353+
```
354+
355+
In the base repository of bluebutton-sample-client-python-react, run the following commands. Ensure that you have no currently running containers or images of the sample client.
356+
357+
```
358+
cd server
359+
unzip -l cms_bluebutton_sdk-1.0.4-py3-none-any.whl
360+
pip install cms_bluebutton_sdk-1.0.4-py3-none-any.whl
361+
docker compose up
362+
```
363+
364+
Each time a change is made in the SDK, you must repeat all of the previous steps of building and re-running a local sample client. You must also ensure that the containers and images are removed each time.

bluebutton-sample-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"client_id": "<your BB2 client_id here>",
44
"client_secret": "<your BB2 client_secret here.>",
55
"callback_url": "https://www.fake.com/your/callback/here",
6-
"version": 2
6+
"version": 3
77
}

cms_bluebutton/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def generate_pkce_data() -> dict:
9595
code_challenge = base64.urlsafe_b64encode(
9696
hashlib.sha256(verifier.encode("ASCII")).digest()
9797
)
98-
return {"code_challenge": code_challenge.decode("utf-8"), "verifier": verifier}
98+
return {"code_challenge": code_challenge.decode("utf-8"), "code_challenge_method": "S256", "verifier": verifier}
9999

100100

101101
def generate_random_state(num) -> str:
@@ -116,7 +116,6 @@ def get_access_token_from_code(bb, auth_data, callback_code) -> dict:
116116
"grant_type": "authorization_code",
117117
"redirect_uri": bb.callback_url,
118118
"code_verifier": auth_data["verifier"],
119-
"code_challenge": auth_data["code_challenge"],
120119
}
121120

122121
token_response = _do_post(data, bb, None)
@@ -146,10 +145,11 @@ def _do_post(data, bb, auth):
146145
mp_encoder = MultipartEncoder(data)
147146
headers = SDK_HEADERS
148147
headers["content-type"] = mp_encoder.content_type
148+
149149
return requests.post(
150150
url=bb.auth_token_url,
151151
data=mp_encoder,
152-
headers=headers
152+
headers=headers,
153153
) if not auth else requests.post(
154154
url=bb.auth_token_url,
155155
data=mp_encoder,

cms_bluebutton/cms_bluebutton.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
ROOT_DIR = os.path.abspath(os.curdir) + "/"
2121
DEFAULT_CONFIG_FILE_LOCATION = ROOT_DIR + "./.bluebutton-config.json"
2222

23-
2423
class BlueButton:
2524

2625
def __init__(self, config=DEFAULT_CONFIG_FILE_LOCATION):

0 commit comments

Comments
 (0)