def get_rover_node_certificate_extended(ctx, **kwargs):
    rover_node_id = kwargs['node_id']
    output_file_path = kwargs['output_file_path']

    if isinstance(rover_node_id, six.string_types) and len(
            rover_node_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --node-id cannot be whitespace or empty string')

    if isinstance(output_file_path, six.string_types) and len(
            output_file_path.strip()) == 0:
        raise click.UsageError(
            'Parameter --output-file-path cannot be whitespace or empty string'
        )

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])
    client = cli_util.build_client('rover', 'rover_node', ctx)
    result = client.get_rover_node_certificate(rover_node_id=rover_node_id,
                                               **kwargs)

    crt_data = cli_util.to_dict(result.data)
    with open(output_file_path, "w") as f:
        for key, val in crt_data.items():
            f.write(str(key) + str(val))
示例#2
0
def export_dashboard(ctx, from_json, export_dashboard_id):

    if isinstance(export_dashboard_id, six.string_types) and len(
            export_dashboard_id.strip()) == 0:
        raise click.UsageError(
            'Parameter --export-dashboard-id cannot be whitespace or empty string'
        )

    kwargs = {}
    kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(
        ctx.obj['request_id'])
    client = cli_util.build_client('management_dashboard', 'dashx_apis', ctx)
    result = client.export_dashboard(export_dashboard_id=export_dashboard_id,
                                     **kwargs)

    if result.data:
        try:
            data = cli_util.to_dict(result.data)

            for dashboard in data["dashboards"]:
                for saved_search in dashboard["saved-searches"]:
                    if "widget-vm" in saved_search:

                        saved_search["widget-v-m"] = saved_search["widget-vm"]
                        del saved_search["widget-vm"]
            result.data = data
        except Exception:
            pass
    cli_util.render_response(result, ctx)
示例#3
0
def get_db_token(ctx, from_json, scope, db_token_location):

    if scope and "urn:oracle:db:" not in scope:
        click.echo(
            "scope must be a db scope i.e --scope 'urn:oracle:db::id::*'")
        ctx.exit(1)

    kwargs = {}
    private_key = cli_util.generate_key()
    public_key = private_key.public_key()
    db_token_path = os.path.normpath(os.path.expanduser(db_token_location))
    Path(db_token_path).mkdir(parents=True, exist_ok=True)
    private_key_file_path = os.path.join(db_token_path, "oci_db_key.pem")
    public_key_file_path = os.path.join(db_token_path, "oci_db_key_public.pem")
    if not cli_setup.write_public_key_to_file(public_key_file_path, public_key,
                                              True, True):
        click.echo("Error: Unable to write public key at {}".format(
            public_key_file_path))
        ctx.exit(1)

    with open(public_key_file_path, mode='r') as public_file:
        public_key_from_file = public_file.read()
    _details = {'scope': scope, 'publicKey': public_key_from_file}

    client = cli_util.build_client('identity_data_plane', 'dataplane', ctx)
    result = client.generate_scoped_access_token(
        generate_scoped_access_token_details=_details, **kwargs)
    response = cli_util.to_dict(result.data)

    # persist private key and result db_token
    if not cli_setup.write_private_key_to_file(private_key_file_path,
                                               private_key, '', True, True):
        click.echo("Error: Unable to write private key at: {}".format(
            private_key_file_path))
        ctx.exit(1)
    else:
        click.echo("Private key written at {}".format(private_key_file_path))
    db_token_path = os.path.join(db_token_path, "token")
    with open(db_token_path, "w") as f:
        f.write(response['token'])
        click.echo('db-token written at: {}'.format(db_token_path))
    cli_setup.apply_user_only_access_permissions(db_token_path)
    with open(db_token_path, 'r') as db_token_file:
        token = db_token_file.read()

    db_token_container = oci.auth.security_token_container.SecurityTokenContainer(
        None, token)

    db_token_file = db_token_container.get_jwt()
    expiry_time = datetime.datetime.fromtimestamp(
        db_token_file['exp']).strftime("%Y-%m-%d %H:%M:%S")
    click.echo("db-token is valid until " + expiry_time, file=sys.stderr)