def create_user(): request = CreateUserDetails() request.compartment_id = compartment_id request.name = ''.join( random.sample(string.ascii_letters + string.digits, 8)) request.description = "The user " + request.name + " was created with Python SDK" user = identity.create_user(request) return user
def create_soc_user(): """Create a SOC user, upload public key and add the user to the SOC group""" # Load Public Key apikeydetails = CreateApiKeyDetails() with open(fileName, "r") as certfile: data = certfile.read() apikeydetails.key = data # Populate a user request request = CreateUserDetails() request.compartment_id = compartment_id request.name = userName request.description = "SOC User created For WAF Access" try: user = identity.create_user(request) uid = user.data.id except oci.exceptions.ServiceError as e: if e.status == 409: print("User '" + request.name + "' already exists.") structured_user_search = oci.resource_search.models.StructuredSearchDetails( query="query user resources where name = '" + userName + "'", type='Structured', matching_context_type=oci.resource_search.models.SearchDetails. MATCHING_CONTEXT_TYPE_NONE) results = search_client.search_resources(structured_user_search) for result in results.data.items: if debug: print("User ID : " + result.identifier) uid = result.identifier else: print(e) # Upload the user's public cert for API Access try: identity.upload_api_key(uid, apikeydetails) print("User's public key is uploaded successfully") except oci.exceptions.ServiceError as e: if e.status == 409: print("User " + userName + " already has a public key associated, do nothing") else: print(e) # Add the newly created user to the SOC Group try: add_soc_member(uid) except oci.exceptions.ServiceError as e: if e.status == 409: print("User" + userName + " has been already added to the group :" + groupName) else: print(e)
# to be performed in the home region. response = identity.list_region_subscriptions(compartment_id) for region in response.data: if region.is_home_region: identity.base_client.set_region(region.region_name) break user_name = "python-sdk-example-user" group_name = "python-sdk-example-group" print("Creating a new user {!r} in compartment {!r}".format( user_name, compartment_id)) request = CreateUserDetails() request.compartment_id = compartment_id request.name = user_name request.description = "Created by a Python SDK example" user = identity.create_user(request) print(user.data) print("Creating a new group {!r} in compartment {!r}".format( group_name, compartment_id)) request = CreateGroupDetails() request.compartment_id = compartment_id request.name = group_name request.description = "Created by a Python SDK example" group = identity.create_group(request) print(group.data) print("Adding new user to the new group")
# Creating an OCI user in Python import oci config = oci.config.from_file() identity_client = oci.identity.IdentityClient(config) compartment_id = config["tenancy"] #prepare OCI request by assigning the desired user parameters from oci.identity.models import CreateUserDetails request = CreateUserDetails() request.compartment_id = compartment_id request.name = "python-user" request.description = "Created with the Python SDK" user = identity_client.create_user(request) print(user.data.id)
import oci import os from oci.identity.models import CreateUserDetails os.environ['http_proxy'] = 'http://www-proxy-hqdc.us.oracle.com:80' os.environ['https_proxy'] = 'http://www-proxy-hqdc.us.oracle.com:80' config=oci.config.from_file() identity=oci.identity.IdentityClient(config) compartment_id=config["tenancy"] request = CreateUserDetails() request.compartment_id=compartment_id request.name="my-test-user-sdk-1" request.description="Created with Python SDK1" user=identity.create_user(request) print(user.data)