Beispiel #1
0
def create_swift_password(identity_client, user_id, description, module):
    result = {}
    try:
        cspd = CreateSwiftPasswordDetails()
        cspd.description = description
        # create_response = oci_utils.call_with_backoff(identity_client.create_swift_password, user_id=user_id,
        #                                               create_swift_password_details=cspd)
        # sw_pass_id = create_response.data.id
        result = oci_utils.create_resource(
            resource_type=RESOURCE_NAME,
            create_fn=identity_client.create_swift_password,
            kwargs_create={
                "user_id": user_id,
                "create_swift_password_details": cspd
            },
            module=module)
        resource = result[RESOURCE_NAME]
        sw_pass_id = resource['id']
        get_logger().info("Created Swift Password %s", to_dict(resource))

        response = identity_client.list_swift_passwords(user_id)
        # wait until the created Swift password reaches Active state
        oci.wait_until(identity_client,
                       response,
                       evaluate_response=lambda resp:
                       _is_swift_password_active(resp.data, sw_pass_id))

        result[RESOURCE_NAME] = to_dict(
            _get_swift_password_from_id(identity_client, user_id, sw_pass_id,
                                        module))
        return result
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as mwte:
        module.fail_json(msg=str(mwte))
def create_api_key(identity_client, user_id, key, module):
    try:
        cakd = CreateApiKeyDetails()
        cakd.key = key
        result = oci_utils.create_resource(
            resource_type=RESOURCE_NAME,
            create_fn=identity_client.upload_api_key,
            kwargs_create={
                "user_id": user_id,
                "create_api_key_details": cakd
            },
            module=module)
        resource = result[RESOURCE_NAME]
        api_key_id = resource["key_id"]
        get_logger().info("Created API signing key %s", to_dict(resource))

        # API keys don't have a get<resource> and so we can't use oci_utils.create_and_wait
        # The following logic manually checks if the API key in `list_api_keys` has reached the desired ACTIVE state
        response = identity_client.list_api_keys(user_id)
        # wait until the created API Key reaches Active state
        oci.wait_until(identity_client,
                       response,
                       evaluate_response=lambda resp: _is_api_key_active(
                           resp.data, api_key_id))

        result[RESOURCE_NAME] = to_dict(
            _get_api_key_from_id(identity_client, user_id, api_key_id, module))
        return result
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as mwte:
        module.fail_json(msg=str(mwte))
def create_customer_secret_key(identity_client, user_id, display_name, module):
    result = {}
    try:
        cskd = CreateCustomerSecretKeyDetails()
        cskd.display_name = display_name
        result = oci_utils.create_resource(
            resource_type=RESOURCE_NAME,
            create_fn=identity_client.create_customer_secret_key,
            kwargs_create={
                "user_id": user_id,
                "create_customer_secret_key_details": cskd
            },
            module=module)
        resource = result[RESOURCE_NAME]
        csk_id = resource["id"]
        get_logger().info("Created Customer Secret Key %s", to_dict(resource))

        response = identity_client.list_customer_secret_keys(user_id)
        # wait until the created Customer Secret Key reaches Active state
        oci.wait_until(identity_client,
                       response,
                       evaluate_response=lambda resp:
                       _is_customer_secret_key_active(resp.data, csk_id))

        # Reuse the CSK object returned by "create" API call as only that object has the "key" attribute defined.
        # Update the lifecycle_status to "ACTIVE"
        result[RESOURCE_NAME]["lifecycle_status"] = "ACTIVE"
        return result
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as mwte:
        module.fail_json(msg=str(mwte))
def create_suppression(email_client, module):
    create_suppression_details = CreateSuppressionDetails()
    for attribute in create_suppression_details.attribute_map:
        create_suppression_details.__setattr__(attribute, module.params.get(attribute))

    result = oci_utils.create_resource(
        resource_type="suppression",
        create_fn=email_client.create_suppression,
        kwargs_create={"create_suppression_details": create_suppression_details},
        module=module,
    )
    return result
Beispiel #5
0
def create_preauthenticated_request(object_storage_client, module):
    create_preauthenticated_request_details = CreatePreauthenticatedRequestDetails(
    )
    for attribute in create_preauthenticated_request_details.attribute_map:
        create_preauthenticated_request_details.__setattr__(
            attribute, module.params.get(attribute))
    result = oci_utils.create_resource(
        resource_type="preauthenticated_request",
        create_fn=object_storage_client.create_preauthenticated_request,
        kwargs_create={
            "namespace_name":
            module.params.get("namespace_name"),
            "bucket_name":
            module.params.get("bucket_name"),
            "create_preauthenticated_request_details":
            create_preauthenticated_request_details,
        },
        module=module,
    )
    return result
Beispiel #6
0
def create_swift_password(identity_client, user_id, description, module):
    result = {}
    try:
        cspd = CreateSwiftPasswordDetails()
        cspd.description = description

        result = oci_utils.create_resource(
            resource_type=RESOURCE_NAME,
            create_fn=identity_client.create_swift_password,
            kwargs_create={
                "user_id": user_id,
                "create_swift_password_details": cspd
            },
            module=module,
        )
        resource = result[RESOURCE_NAME]
        sw_pass_id = resource["id"]
        # cache the swift password's password as it is only provided during creation
        cached_pass = resource["password"]
        get_logger().info("Created Swift Password %s", to_dict(resource))

        response = identity_client.list_swift_passwords(user_id)
        # wait until the created Swift password reaches Active state
        oci.wait_until(
            identity_client,
            response,
            evaluate_response=lambda resp: _is_swift_password_active(
                resp.data, sw_pass_id),
        )

        sw_pass = _get_swift_password_from_id(identity_client, user_id,
                                              sw_pass_id, module)
        # stuff the cached password in the returned swift_password model
        sw_pass.password = cached_pass
        result[RESOURCE_NAME] = to_dict(sw_pass)
        return result
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as mwte:
        module.fail_json(msg=str(mwte))