Skip to content

Conversation

@jonavellecuerdo
Copy link
Contributor

@jonavellecuerdo jonavellecuerdo commented Aug 23, 2023

What does this PR do?

Refactor Carbon to use the JSON formatted secret in Secrets Manager to obtain the credentials for the Data Warehouse.
This will make future management of the Data Warehouse password a bit easier, since we will have just one secret in Secrets Manager instead of two.

Helpful background context

Updating Carbon to use Python 3.11 meant replacing cx-oracle with oracledb (i.e., python-oracledb) because as this page reads: cx_Oracle 8.3 has been tested [only] with Python versions 3.6 through 3.10.

The Oracle database version used by the Data Warehouse requires "thick" mode when connecting to a database. This page describes how to do that using sqlalchemy.create_engine() and oracledb.init_oracle_client().

I chose the solution to use sqlalchemy.create_engine() since that is the method currently used by the application, and the latter method would involve more changes that--in my perspective--would better suit a separate ticket/effort to replace all sqlalchemy commands with oracledb.

How can a reviewer manually see the effects of these changes?

Review the CloudWatch log generated by running make database-connection-test-stage

If you'd like to run it

  1. Clone the repo.
  2. Check into this branch IN-886-use-new-data-warehouse-secret.
  3. Create a new virtual environment.
  4. Install dependencies: make install.
  5. Run linters: make lint.
  6. Run test: make database-connection-test-stage.

Includes new or updated dependencies?

NO

Developer

  • README is updated to reflect all changes as needed
  • All related Jira tickets are linked in commit message(s)

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • There are appropriate tests covering any new functionality
  • The documentation has been updated to reflect all changes or is not needed
  • The changes have been verified
  • New dependencies are appropriate or there were no changes

@jonavellecuerdo jonavellecuerdo force-pushed the IN-886-use-new-data-warehouse-secret branch from 892743b to a3e21ae Compare August 23, 2023 16:32
@jonavellecuerdo jonavellecuerdo self-assigned this Aug 23, 2023
@jonavellecuerdo jonavellecuerdo marked this pull request as ready for review August 23, 2023 16:35
Why these changes are being introduced:
* Use the JSON formatted secret in Secrets Manager to obtain
credentials for the Data Warehouse and remove redundant secrets.

How this addresses that need:
* Configure the engine with 'CONNECTION_STRING'
* Create database connection test and add CLI option to run test
* Add Make command to run database connection test
* Remove unused 'click.echo' commands
* Add error handling when retrieving database versions

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/IN-886
@jonavellecuerdo jonavellecuerdo force-pushed the IN-886-use-new-data-warehouse-secret branch from a3e21ae to 6388c9b Compare August 23, 2023 17:28
Copy link
Contributor

@ehanson8 ehanson8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, 2 requested changes!

carbon/db.py Outdated
Comment on lines 108 to 111
def configure(self, conn: str, **kwargs: Any) -> None: # noqa: ANN401
self._engine = self._engine or create_engine(conn, **kwargs)

def run_connection_test(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings would be beneficial for clarifying what's happening here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring has been added. ✍🏼

carbon/db.py Outdated

def configure(self, conn: str) -> None:
self._engine = self._engine or create_engine(conn)
def configure(self, conn: str, **kwargs: Any) -> None: # noqa: ANN401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start expanding some of these variable names like conn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the latest commit! The only line of code where I kept conn was in CarbonCopyFTPS.storbinary; the class inherits from FTP_TLS, which uses the conn naming convention.

* Update README
* Clean up variable name 'conn'
* Add docstring to DatabaseEngine.run_connection_test
5. Run any `make` commands for testing the application.

2. Run `make dist-dev` to build the container.
Any tests that involve connecting to the Data Warehouse will need to be run as an ECS task in `stage`, which requires building and publishing the Docker container image to ECR for the `stage` environment. As noted in step 1, the appropriate AWS credentials for the `stage` must be set to run the commands for building and publishing the Docker container image. The `ECR_NAME_STAGE` and `ECR_URL_STAGE` environment variables must also be set; the values correspond to the 'Repository name' and 'URI' indicated on ECR for the container image, respectively.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent description

@jonavellecuerdo jonavellecuerdo merged commit 35e4c43 into main Aug 25, 2023
@jonavellecuerdo jonavellecuerdo deleted the IN-886-use-new-data-warehouse-secret branch August 25, 2023 13:32
jonavellecuerdo added a commit that referenced this pull request Aug 25, 2023
Why these changes are being introduced:
* Simplify management of FTP credentials by storing
components in a JSON formatted string

How this addresses that need:
* Expand connection tests for Data Warehouse and Symplectic Elements FTP server
* Update CLI tests
* Update README

Side effects of this change:
* None

Relevant ticket(s):
* #94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants