Beispiel #1
0
def vault_import(vault, input_='-'):
    """A generic method for importing data into Vault

    Note: input data should be Json encoded

    Args:
        input_ (string) : Input path to read data from ('-' for stdin)
    """
    with open_(input_) as fh:
        exported = json.load(fh)

    vault.import_(exported)
Beispiel #2
0
def vault_import(vault, input_='-'):
    """A generic method for importing data into Vault

    Note: input data should be Json encoded

    Args:
        input_ (string) : Input path to read data from ('-' for stdin)
    """
    with open_(input_) as fh:
        exported = json.load(fh)

    vault.import_(exported)
Beispiel #3
0
def vault_export(vault, output='-', path="secret/"):
    """A generic method for exporting data from Vault

    Note: output data is Json encoded

    Args:
        vault (Vault) : Vault connection to use
        output (string) : Output path to save the data ('-' for stdout)
        path (string) : Vault path to export data from
    """
    rtn = vault.export(path)

    with open_(output, 'w') as fh:
        json.dump(rtn, fh, indent=3, sort_keys=True)
Beispiel #4
0
def vault_export(vault, output='-', path="secret/"):
    """A generic method for exporting data from Vault

    Note: output data is Json encoded

    Args:
        vault (Vault) : Vault connection to use
        output (string) : Output path to save the data ('-' for stdout)
        path (string) : Vault path to export data from
    """
    rtn = vault.export(path)

    with open_(output, 'w') as fh:
        json.dump(rtn, fh, indent=3, sort_keys=True)
        print("Hostname doesn't start with 'auth'", file=sys.stderr)

    url = "https://" + args.hostname + "/auth/realms/BOSS/protocol/openid-connect/token"
    print(url)
    params = {
        "grant_type": "password",
        "client_id": "endpoint",
        "username": username,
        "password": password,
    }
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
    }

    response = request(url, params, headers)
    if response is None:
        sys.exit(1)

    # DP NOTE: Prints are done to stderr so that stdout can be redirected / piped
    #          without capturing status information from the program
    response = json.loads(response)
    if "access_token" not in response:
        print("Didn't get a token, exiting...", file=sys.stderr)
        sys.exit(1)

    token = response["access_token"]
    with utils.open_(args.output, "w") as fh:
        fh.write(token)
        print("Token writen to '{}'".format(args.output), file=sys.stderr)
        sys.exit(0)
        print("Hostname doesn't start with 'auth'", file=sys.stderr)

    url = "https://" + args.hostname + "/auth/realms/BOSS/protocol/openid-connect/token"
    print(url)
    params = {
        "grant_type": "password",
        "client_id": "endpoint",
        "username": username,
        "password": password,
    }
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
    }

    response = request(url, params, headers)
    if response is None:
        sys.exit(1)

    # DP NOTE: Prints are done to stderr so that stdout can be redirected / piped
    #          without capturing status information from the program
    response = json.loads(response)
    if "access_token" not in response:
        print("Didn't get a token, exiting...", file=sys.stderr)
        sys.exit(1)

    token = response["access_token"]
    with utils.open_(args.output, "w") as fh:
        fh.write(token)
        print("Token writen to '{}'".format(args.output), file=sys.stderr)
        sys.exit(0)