Skip to content

Commit

Permalink
add import aliases to auth logic so our main readme uses them
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsy-opal committed Nov 27, 2024
1 parent 2fda909 commit cbaed38
Show file tree
Hide file tree
Showing 19 changed files with 487 additions and 190 deletions.
1 change: 0 additions & 1 deletion .openapi-generator/templates/common_README.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
```python
{{#apiInfo}}{{#apis}}{{#-last}}{{#hasHttpSignatureMethods}}import datetime{{/hasHttpSignatureMethods}}{{/-last}}{{/apis}}{{/apiInfo}}
import {{{packageName}}} as {{{packageShorthand}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
Expand Down
111 changes: 111 additions & 0 deletions .openapi-generator/templates/python_doc_auth_partial.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Defining the host is optional and defaults to {{{basePath}}}
# See configuration.py for a list of all supported configuration parameters.
import {{{packageName}}} as {{{packageShorthand}}}

configuration = {{{packageShorthand}}}.Configuration(
host = "{{{basePath}}}"
)

{{#hasAuthMethods}}
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}

# Configure HTTP basic authorization: {{{name}}}
configuration = {{{packageShorthand}}}.Configuration(
username = os.environ["USERNAME"],
password = os.environ["PASSWORD"]
)
{{/isBasicBasic}}
{{#isBasicBearer}}

# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
configuration = {{{packageShorthand}}}.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)
{{/isBasicBearer}}
{{#isHttpSignature}}

# Configure HTTP message signature: {{{name}}}
# The HTTP Signature Header mechanism that can be used by a client to
# authenticate the sender of a message and ensure that particular headers
# have not been modified in transit.
#
# You can specify the signing key-id, private key path, signing scheme,
# signing algorithm, list of signed headers and signature max validity.
# The 'key_id' parameter is an opaque string that the API server can use
# to lookup the client and validate the signature.
# The 'private_key_path' parameter should be the path to a file that
# contains a DER or base-64 encoded private key.
# The 'private_key_passphrase' parameter is optional. Set the passphrase
# if the private key is encrypted.
# The 'signed_headers' parameter is used to specify the list of
# HTTP headers included when generating the signature for the message.
# You can specify HTTP headers that you want to protect with a cryptographic
# signature. Note that proxies may add, modify or remove HTTP headers
# for legitimate reasons, so you should only add headers that you know
# will not be modified. For example, if you want to protect the HTTP request
# body, you can specify the Digest header. In that case, the client calculates
# the digest of the HTTP request body and includes the digest in the message
# signature.
# The 'signature_max_validity' parameter is optional. It is configured as a
# duration to express when the signature ceases to be valid. The client calculates
# the expiration date every time it generates the cryptographic signature
# of an HTTP request. The API server may have its own security policy
# that controls the maximum validity of the signature. The client max validity
# must be lower than the server max validity.
# The time on the client and server must be synchronized, otherwise the
# server may reject the client signature.
#
# The client must use a combination of private key, signing scheme,
# signing algorithm and hash algorithm that matches the security policy of
# the API server.
#
# See {{{packageName}}}.signing for a list of all supported parameters.
from {{{packageName}}} import signing
import {{{packageName}}} as {{{packageShorthand}}}
import datetime

configuration = {{{packageShorthand}}}.Configuration(
host = "{{{basePath}}}",
signing_info = {{{packageShorthand}}}.HttpSigningConfiguration(
key_id = 'my-key-id',
private_key_path = 'private_key.pem',
private_key_passphrase = 'YOUR_PASSPHRASE',
signing_scheme = {{{packageShorthand}}}.signing.SCHEME_HS2019,
signing_algorithm = {{{packageShorthand}}}.signing.ALGORITHM_ECDSA_MODE_FIPS_186_3,
hash_algorithm = {{{packageShorthand}}}.signing.SCHEME_RSA_SHA256,
signed_headers = [
{{{packageShorthand}}}.signing.HEADER_REQUEST_TARGET,
{{{packageShorthand}}}.signing.HEADER_CREATED,
{{{packageShorthand}}}.signing.HEADER_EXPIRES,
{{{packageShorthand}}}.signing.HEADER_HOST,
{{{packageShorthand}}}.signing.HEADER_DATE,
{{{packageShorthand}}}.signing.HEADER_DIGEST,
'Content-Type',
'Content-Length',
'User-Agent'
],
signature_max_validity = datetime.timedelta(minutes=5)
)
)
{{/isHttpSignature}}
{{/isBasic}}
{{#isApiKey}}

# Configure API key authorization: {{{name}}}
configuration.api_key['{{{name}}}'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{name}}'] = 'Bearer'
{{/isApiKey}}
{{#isOAuth}}

configuration.access_token = os.environ["ACCESS_TOKEN"]
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ Please follow the [installation procedure](#installation--usage) and then run th

```python

import opal_security as opal
from opal_security.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -71,7 +72,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down
12 changes: 8 additions & 4 deletions docs/AppsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -37,7 +39,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -105,7 +107,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -115,7 +119,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down
24 changes: 16 additions & 8 deletions docs/ConfigurationTemplatesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -40,7 +42,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -106,7 +108,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -116,7 +120,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -181,7 +185,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -191,7 +197,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -255,7 +261,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -265,7 +273,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down
6 changes: 4 additions & 2 deletions docs/EventsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -36,7 +38,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down
30 changes: 20 additions & 10 deletions docs/GroupBindingsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -41,7 +43,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -107,7 +109,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -117,7 +121,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -182,7 +186,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -192,7 +198,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -259,7 +265,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -269,7 +277,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down Expand Up @@ -338,7 +346,9 @@ from pprint import pprint

# Defining the host is optional and defaults to https://api.opal.dev/v1
# See configuration.py for a list of all supported configuration parameters.
configuration = opal_security.Configuration(
import opal_security as opal

configuration = opal.Configuration(
host = "https://api.opal.dev/v1"
)

Expand All @@ -348,7 +358,7 @@ configuration = opal_security.Configuration(
# satisfies your auth use case.

# Configure Bearer authorization: BearerAuth
configuration = opal_security.Configuration(
configuration = opal.Configuration(
access_token = os.environ["BEARER_TOKEN"]
)

Expand Down
Loading

0 comments on commit cbaed38

Please sign in to comment.