PagerDuty / pdpyras

Low-level PagerDuty REST/Events API client for Python
MIT License
129 stars 29 forks source link

Rewrite examples to use env vars #81

Closed Deconstrained closed 2 years ago

Deconstrained commented 2 years ago

It's really bad practice to hard-code API keys. Our code examples should reflect that.

We could just do this to begin with:

api_key = os.env.get('PD_API_KEY')
jwrobb commented 2 years ago

I use something similar to this approach for indicating API Key and user (when necessary). The environment variable is the default but I allow for overrides at the command line on startup

    parser.add_argument(
        "--apikey",
        default=os.environ.get("PD_API_KEY"),
        help="API Key can be specified by env variable PD_API_KEY"
    )

    parser.add_argument(
        "--user",
        default=os.environ.get("PD_USER_ID"),
        help="Overrides the user email in the env PD_USER_ID"
    )