mds_plugin/object_store.py
def create_bucket_object_par(**kwargs):
    """Get a preauthenticated request for the given bucket object

    Args:
        **kwargs: Additional options

    Keyword Args:
        bucket_object_name (str): If set to JSON, output is formated that way.
        bucket_name (str): The name of the bucket
        access_type (str): The type of access to grant ('r', 'w', 'rw')
        valid_till (str): The point in time until the PAR is valid using the 
            format YYYY-MM-DD HH:MM:SS. If not specified it is now + 7 days.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        return_object (bool): If the object should be returned

    Returns:
        The link or the object
    """

    bucket_object_name = kwargs.get('bucket_object_name')
    bucket_name = kwargs.get('bucket_name')
    access_type = kwargs.get('access_type')
    valid_till = kwargs.get('valid_till')
    compartment_id = kwargs.get('compartment_id')
    config = kwargs.get('config')
    return_object = kwargs.get('return_object', False)

    # Get the active config and compartment
    try:
        config = configuration.get_current_config(config=config)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        bucket_name = configuration.get_current_bucket_name(
            bucket_name=bucket_name, config=config)

        import oci.object_storage
        import oci.util
        import os.path
        import io
        import mysqlsh
        import datetime
        import time

        # Get bucket
        bucket = get_bucket(
            bucket_name=bucket_name, compartment_id=compartment_id, config=config)
        if bucket is None:
            print("Operation cancelled.")
            return

        # Get bucket object name
        if bucket_object_name is None:
            bucket_object_name = mysqlsh.globals.shell.prompt(
                "Please enter the name of the bucket object: ",
                {'defaultValue': ''}).strip()
            if bucket_object_name == "":
                print("Operation cancelled.")
                return

        # Initialize the  Object Store client
        os_client = core.get_oci_object_storage_client(config=config)

        # Get Object Store namespace
        namespace_name = get_object_store_namespace(config)

        # PAR valid till now + 7 day
        if valid_till is None:
            valid_till = datetime.datetime.now() + datetime.timedelta(days=7)
        elif type(valid_till) is str:
            try:
                valid_till = datetime.datetime(*(time.strptime(
                    valid_till, f"%Y-%m-%d %H:%M:%S")[0:6]))
            except ValueError as e:
                print("Invalid datetime format. Use YYYY-MM-DD HH:MM:SS")
                return

        # Get access type
        access_type = access_type.lower() if access_type is not None else "r"
        if access_type == "w":
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.ACCESS_TYPE_OBJECT_WRITE
        elif access_type == "rw":
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.\
                ACCESS_TYPE_OBJECT_READ_WRITE
        else:
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.ACCESS_TYPE_OBJECT_READ

        details = oci.object_storage.models.\
            CreatePreauthenticatedRequestDetails(
                name=f"PAR-{bucket.name}-{bucket_object_name}-R",
                object_name=bucket_object_name,
                access_type=access,
                time_expires=f"{valid_till:%Y-%m-%dT%H:%M:%SZ}")

        par = os_client.create_preauthenticated_request(
            namespace_name=namespace_name, bucket_name=bucket_name,
            create_preauthenticated_request_details=details).data

        if return_object:
            return par
        else:
            return get_par_url_prefix(config) + par.access_uri
    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except Exception as e:
        print(f'ERROR: {e}')
        return
Get a preauthenticated request for the given bucket object

    Args:
        **kwargs: Additional options

    Keyword Args:
        bucket_object_name (str): If set to JSON, output is formated that way.
        bucket_name (str): The name of the bucket
        access_type (str): The type of access to grant ('r', 'w', 'rw')
        valid_till (str): The point in time until the PAR is valid using the 
            format YYYY-MM-DD HH:MM:SS. If not specified it is now + 7 days.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        return_object (bool): If the object should be returned

    Returns:
        The link or the object
    
Get a preauthenticated request for the given bucket object
Get a preauthenticated request for the given bucket object
def create_bucket_object_par(**kwargs):
    bucket_object_name = kwargs.get('bucket_object_name')
    bucket_name = kwargs.get('bucket_name')
    access_type = kwargs.get('access_type')
    valid_till = kwargs.get('valid_till')
    compartment_id = kwargs.get('compartment_id')
    config = kwargs.get('config')
    return_object = kwargs.get('return_object', False)
    try:
        config = configuration.get_current_config(config=config)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        bucket_name = configuration.get_current_bucket_name(
            bucket_name=bucket_name, config=config)
        import oci.object_storage
        import oci.util
        import os.path
        import io
        import mysqlsh
        import datetime
        import time
        bucket = get_bucket(
            bucket_name=bucket_name, compartment_id=compartment_id, config=config)
        if bucket is None:
            print("Operation cancelled.")
            return
        if bucket_object_name is None:
            bucket_object_name = mysqlsh.globals.shell.prompt(
                "Please enter the name of the bucket object: ",
                {'defaultValue': ''}).strip()
            if bucket_object_name == "":
                print("Operation cancelled.")
                return
        os_client = core.get_oci_object_storage_client(config=config)
        namespace_name = get_object_store_namespace(config)
        if valid_till is None:
            valid_till = datetime.datetime.now() + datetime.timedelta(days=7)
        elif type(valid_till) is str:
            try:
                valid_till = datetime.datetime(*(time.strptime(
                    valid_till, f"%Y-%m-%d %H:%M:%S")[0:6]))
            except ValueError as e:
                print("Invalid datetime format. Use YYYY-MM-DD HH:MM:SS")
                return
        access_type = access_type.lower() if access_type is not None else "r"
        if access_type == "w":
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.ACCESS_TYPE_OBJECT_WRITE
        elif access_type == "rw":
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.\
                ACCESS_TYPE_OBJECT_READ_WRITE
        else:
            access = oci.object_storage.models.\
                CreatePreauthenticatedRequestDetails.ACCESS_TYPE_OBJECT_READ
        details = oci.object_storage.models.\
            CreatePreauthenticatedRequestDetails(
                name=f"PAR-{bucket.name}-{bucket_object_name}-R",
                object_name=bucket_object_name,
                access_type=access,
                time_expires=f"{valid_till:%Y-%m-%dT%H:%M:%SZ}")
        par = os_client.create_preauthenticated_request(
            namespace_name=namespace_name, bucket_name=bucket_name,
            create_preauthenticated_request_details=details).data
        if return_object:
            return par
        else:
            return get_par_url_prefix(config) + par.access_uri
    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except Exception as e:
        print(f'ERROR: {e}')
        return
def create_bucket_object_par ( ** kwargs ) : bucket_object_name = kwargs . get ( 'bucket_object_name' ) bucket_name = kwargs . get ( 'bucket_name' ) access_type = kwargs . get ( 'access_type' ) valid_till = kwargs . get ( 'valid_till' ) compartment_id = kwargs . get ( 'compartment_id' ) config = kwargs . get ( 'config' ) return_object = kwargs . get ( 'return_object' , False ) try : config = configuration . get_current_config ( config = config ) compartment_id = configuration . get_current_compartment_id ( compartment_id = compartment_id , config = config ) bucket_name = configuration . get_current_bucket_name ( bucket_name = bucket_name , config = config ) import oci . object_storage import oci . util import os . path import io import mysqlsh import datetime import time bucket = get_bucket ( bucket_name = bucket_name , compartment_id = compartment_id , config = config ) if bucket is None : print ( "Operation cancelled." ) return if bucket_object_name is None : bucket_object_name = mysqlsh . globals . shell . prompt ( "Please enter the name of the bucket object: " , { 'defaultValue' : '' } ) . strip ( ) if bucket_object_name == "" : print ( "Operation cancelled." ) return os_client = core . get_oci_object_storage_client ( config = config ) namespace_name = get_object_store_namespace ( config ) if valid_till is None : valid_till = datetime . datetime . now ( ) + datetime . timedelta ( days = 7 ) elif type ( valid_till ) is str : try : valid_till = datetime . datetime ( * ( time . strptime ( valid_till , f"%Y-%m-%d %H:%M:%S" ) [ 0 : 6 ] ) ) except ValueError as e : print ( "Invalid datetime format. Use YYYY-MM-DD HH:MM:SS" ) return access_type = access_type . lower ( ) if access_type is not None else "r" if access_type == "w" : access = oci . object_storage . models . CreatePreauthenticatedRequestDetails . ACCESS_TYPE_OBJECT_WRITE elif access_type == "rw" : access = oci . object_storage . models . CreatePreauthenticatedRequestDetails . ACCESS_TYPE_OBJECT_READ_WRITE else : access = oci . object_storage . models . CreatePreauthenticatedRequestDetails . ACCESS_TYPE_OBJECT_READ details = oci . object_storage . models . CreatePreauthenticatedRequestDetails ( name = f"PAR-{bucket.name}-{bucket_object_name}-R" , object_name = bucket_object_name , access_type = access , time_expires = f"{valid_till:%Y-%m-%dT%H:%M:%SZ}" ) par = os_client . create_preauthenticated_request ( namespace_name = namespace_name , bucket_name = bucket_name , create_preauthenticated_request_details = details ) . data if return_object : return par else : return get_par_url_prefix ( config ) + par . access_uri except oci . exceptions . ServiceError as e : print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) return except Exception as e : print ( f'ERROR: {e}' ) return
Get a preauthenticated request for the given bucket object
Get a preauthenticated request for the given bucket object
"""Get a preauthenticated request for the given bucket object

    Args:
        **kwargs: Additional options

    Keyword Args:
        bucket_object_name (str): If set to JSON, output is formated that way.
        bucket_name (str): The name of the bucket
        access_type (str): The type of access to grant ('r', 'w', 'rw')
        valid_till (str): The point in time until the PAR is valid using the 
            format YYYY-MM-DD HH:MM:SS. If not specified it is now + 7 days.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        return_object (bool): If the object should be returned

    Returns:
        The link or the object
    """ # Get the active config and compartment
 # Get bucket
 # Get bucket object name
 # Initialize the  Object Store client
 # Get Object Store namespace
 # PAR valid till now + 7 day
 # Get access type

The link or the object
The link or the object
**kwargs
None