Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 1 | Contributing |
| 2 | ============ |
| 3 | |
| 4 | #. **Please sign one of the contributor license agreements below.** |
| 5 | #. Fork the repo, develop and test your code changes, add docs. |
| 6 | #. Make sure that your commit messages clearly describe the changes. |
| 7 | #. Send a pull request. |
| 8 | |
| 9 | Here are some guidelines for hacking on ``google-auth-library-python``. |
| 10 | |
| 11 | Making changes |
| 12 | -------------- |
| 13 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 14 | A few notes on making changes to ``google-auth-library-python``. |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | - If you've added a new feature or modified an existing feature, be sure to |
| 17 | add or update any applicable documentation in docstrings and in the |
| 18 | documentation (in ``docs/``). You can re-generate the reference documentation |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 19 | using ``nox -s docgen``. |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 20 | |
Tres Seaver | 560cf1e | 2021-08-03 16:35:54 -0400 | [diff] [blame] | 21 | - The change must work fully on the following CPython versions: |
Tres Seaver | 19d41f8 | 2021-10-07 13:05:19 -0400 | [diff] [blame] | 22 | 3.6, 3.7, 3.8, 3.9, 3.10 across macOS, Linux, and Windows. |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | - The codebase *must* have 100% test statement coverage after each commit. |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 25 | You can test coverage via ``nox -e cover``. |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | Testing changes |
| 28 | --------------- |
| 29 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 30 | To test your changes, run unit tests with ``nox``:: |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 31 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 32 | $ nox -s unit |
| 33 | |
| 34 | |
| 35 | Running system tests |
| 36 | -------------------- |
| 37 | |
| 38 | You can run the system tests with ``nox``:: |
| 39 | |
| 40 | $ nox -f system_tests/noxfile.py |
| 41 | |
| 42 | To run a single session, specify it with ``nox -s``:: |
| 43 | |
| 44 | $ nox -f system_tests/noxfile.py -s service_account |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 45 | |
| 46 | First, set the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` to a valid service account. |
| 47 | See `Creating and Managing Service Account Keys`_ for how to obtain a service account. |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 48 | |
| 49 | Project and Credentials Setup |
| 50 | ------------------------------- |
| 51 | |
| 52 | Enable the IAM Service Account Credentials API on the project. |
| 53 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 54 | To run system tests locally, you will need to set up a data directory :: |
| 55 | |
| 56 | $ mkdir system_tests/data |
| 57 | |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 58 | Your directory should look like this. Follow the instructions below for creating each file. :: |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 59 | |
| 60 | system_tests/ |
| 61 | data/ |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 62 | authorized_user.json |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 63 | impersonated_service_account.json |
| 64 | service_account.json |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 65 | |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 66 | |
| 67 | ``authorized_user.json`` |
| 68 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 69 | |
| 70 | Use the `gcloud CLI`_ to get an authorized user file :: |
| 71 | |
| 72 | $ gcloud auth application-default login --scopes=https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,openid |
| 73 | |
| 74 | You will see something like:: |
| 75 | |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 76 | Credentials saved to file: [/usr/local/home/.config/gcloud/application_default_credentials.json] |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 77 | |
| 78 | Copy the contents of the file to ``authorized_user.json``. |
| 79 | |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 80 | Open the IAM page of the Google Cloud Console. Grant the user the `Service Account Token Creator Role`. |
| 81 | This will allow the user to impersonate service accounts on the project. |
| 82 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 83 | .. _gcloud CLI: https://cloud.google.com/sdk/gcloud/ |
| 84 | |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 85 | |
| 86 | ``service_account.json`` |
| 87 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 89 | Follow `Creating and Managing Service Account Keys`_ to create a service account. |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 90 | |
| 91 | Copy the credentials file to ``service_account.json``. |
| 92 | |
| 93 | Grant the account associated with ``service_account.json`` the following roles. |
| 94 | |
| 95 | - App Engine Admin (for App Engine tests) |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 96 | - Service Account Token Creator (for impersonated credentials and workload identity federation tests) |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 97 | - Pub/Sub Viewer (for gRPC tests) |
| 98 | - Storage Object Viewer (for impersonated credentials tests) |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 99 | - DNS Viewer (for workload identity federation tests) |
bojeil-google | ed8e035 | 2021-08-16 12:34:28 -0700 | [diff] [blame] | 100 | - GCE Storage Bucket Admin (for downscoping tests) |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 101 | |
| 102 | ``impersonated_service_account.json`` |
| 103 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 104 | |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 105 | Follow `Creating and Managing Service Account Keys`_ to create a service account. |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 106 | |
| 107 | Copy the credentials file to ``impersonated_service_account.json``. |
| 108 | |
| 109 | .. _Creating and Managing Service Account Keys: https://cloud.google.com/iam/docs/creating-managing-service-account-keys |
| 110 | |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 111 | ``setup_external_accounts`` |
| 112 | ~~~~~~~~~~~~~~~~ |
| 113 | |
| 114 | In order to run the workload identity federation tests, you will need to set up |
| 115 | a Workload Identity Pool, as well as attach relevant policy bindings for this |
| 116 | new resource to our service account. To do this, make sure you have IAM Workload |
| 117 | Identity Pool Admin and Security Admin permissions, and then run: |
| 118 | |
| 119 | $ ./scripts/setup_external_accounts.sh |
| 120 | |
| 121 | and then use the output to replace the variables near |
| 122 | the top of system_tests/system_tests_sync/test_external_accounts.py |
| 123 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 124 | App Engine System Tests |
Bu Sun Kim | 82e224b | 2020-03-13 13:21:18 -0700 | [diff] [blame] | 125 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 126 | |
| 127 | To run the App Engine tests, you wil need to deploy a default App Engine service. |
| 128 | If you already have a default service associated with your project, you can skip this step. |
| 129 | |
| 130 | Edit ``app.yaml`` so ``service`` is ``default`` instead of ``google-auth-system-tests``. |
| 131 | From ``system_tests/app_engine_test_app`` run the following commands :: |
| 132 | |
Bu Sun Kim | 8374e21 | 2020-03-20 18:10:05 -0700 | [diff] [blame] | 133 | $ pip install --target lib -r requirements.txt |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 134 | $ gcloud app deploy -q app.yaml |
| 135 | |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 136 | After the app is deployed, change ``service`` in ``app.yaml`` back to ``google-auth-system-tests``. |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 137 | You can now run the App Engine tests: :: |
| 138 | |
| 139 | $ nox -f system_tests/noxfile.py -s app_engine |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 140 | |
Bu Sun Kim | 8374e21 | 2020-03-20 18:10:05 -0700 | [diff] [blame] | 141 | Compute Engine Tests |
| 142 | ^^^^^^^^^^^^^^^^^^^^ |
| 143 | |
| 144 | These tests cannot be run locally and will be skipped if they are run outside of Google Compute Engine. |
Ryan Kohler | 48e8be3 | 2021-03-25 17:35:43 -0700 | [diff] [blame] | 145 | |
Bu Sun Kim | 8374e21 | 2020-03-20 18:10:05 -0700 | [diff] [blame] | 146 | grpc Tests |
| 147 | ^^^^^^^^^^^^ |
| 148 | |
| 149 | These tests use the Pub/Sub API. Grant the service account specified by `GOOGLE_APPLICATION_CREDENTIALS` |
| 150 | permissions to list topics. The service account should have at least `roles/pubsub.viewer`. |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | Coding Style |
| 153 | ------------ |
| 154 | |
| 155 | This library is PEP8 & Pylint compliant. Our Pylint config is defined at |
| 156 | ``pylintrc`` for package code and ``pylintrc.tests`` for test code. Use |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 157 | ``nox`` to check for non-compliant code:: |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 158 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 159 | $ nox -s lint |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | Documentation Coverage and Building HTML Documentation |
| 162 | ------------------------------------------------------ |
| 163 | |
| 164 | If you fix a bug, and the bug requires an API or behavior modification, all |
| 165 | documentation in this package which references that API or behavior must be |
| 166 | changed to reflect the bug fix, ideally in the same commit that fixes the bug |
| 167 | or adds the feature. |
| 168 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 169 | To build and review docs use ``nox``:: |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 170 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 171 | $ nox -s docs |
Jon Wayne Parrott | 377f293 | 2016-10-04 10:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | The HTML version of the docs will be built in ``docs/_build/html`` |
| 174 | |
| 175 | Versioning |
| 176 | ---------- |
| 177 | |
| 178 | This library follows `Semantic Versioning`_. |
| 179 | |
| 180 | .. _Semantic Versioning: http://semver.org/ |
| 181 | |
| 182 | It is currently in major version zero (``0.y.z``), which means that anything |
| 183 | may change at any time and the public API should not be considered |
| 184 | stable. |
| 185 | |
| 186 | Contributor License Agreements |
| 187 | ------------------------------ |
| 188 | |
| 189 | Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA): |
| 190 | |
| 191 | - **If you are an individual writing original source code** and **you own the intellectual property**, then you'll need to sign an `individual CLA <https://developers.google.com/open-source/cla/individual>`__. |
| 192 | - **If you work for a company that wants to allow you to contribute your work**, then you'll need to sign a `corporate CLA <https://developers.google.com/open-source/cla/corporate>`__. |
| 193 | |
| 194 | You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests. |