PagerDuty/pdpyras

Rewrite examples to use env vars

Deconstrained opened this issue · 1 comments

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')

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"
    )