Ejemplo n.º 1
0
def test_load_base64_encoded_private_key():
    """
    We can load a base64 encoded private key.
    """
    private_key, public_key = generate_keypair()
    rsa_private_key = load_private_key(base64.b64encode(private_key).decode())
    assert private_key == rsa_private_key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=serialization.NoEncryption(),
    )
Ejemplo n.º 2
0
def test_keypair_generator():
    """
    Keypair generator produces a valid key pair, and we can load it from a string.
    """
    private_key, public_key = generate_keypair()
    rsa_private_key = load_private_key(private_key.decode())
    assert private_key == rsa_private_key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=serialization.NoEncryption(),
    )
    rsa_public_key = load_public_key(public_key.decode())
    assert public_key == (rsa_public_key.public_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PublicFormat.SubjectPublicKeyInfo,
    ))
Ejemplo n.º 3
0
# Format pandas tables nicely


def to_md(self):
    return tabulate.tabulate(self.head(), self.columns, tablefmt="pipe")


def format_dict(x):
    return f'><div class="codehilite"><pre>{pprint.pformat(x)}</pre></div>'


get_ipython().display_formatter.formatters["text/html"].for_type(
    pd.DataFrame, to_md)
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    dict, format_dict)
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    str, lambda x: f">`{x}`")
get_ipython().display_formatter.formatters["text/markdown"].for_type(
    list, lambda x: f">`{x}`")

# Create an API access token

TOKEN = generate_token(
    username="******",
    private_key=load_private_key(os.environ["PRIVATE_JWT_SIGNING_KEY"]),
    lifetime=timedelta(days=1),
    claims=get_all_claims_from_flowapi(flowapi_url="http://localhost:9090"),
    flowapi_identifier=os.environ["FLOWAPI_IDENTIFIER"],
)