def create_workspace(self) -> Workspace: """Create workspace using credentials stored in config file :return: Workspace :rtype: Workspace """ workspace = Workspace( subscription_id=self.subscription_id, resource_group=self.resource_group, name=self.workspace_name, ) if self.is_live or self.in_recording: workspace.credentials = ServicePrincipalCredentials( tenant=self.tenant_id, client_id=self.client_id, secret=self.client_secret, resource="https://quantum.microsoft.com") workspace.login(False) else: workspace.credentials = BasicTokenAuthentication( token=self.dummy_auth_token) return workspace
def create_workspace() -> Workspace: """Create workspace using credentials stored in config file :return: Workspace :rtype: Workspace """ client_id = os.environ.get("AZURE_CLIENT_ID", "") client_secret = os.environ.get("AZURE_CLIENT_SECRET", "") tenant_id = os.environ.get("AZURE_TENANT_ID", "") resource_group = os.environ.get("RESOURCE_GROUP", "") subscription_id = os.environ.get("SUBSCRIPTION_ID", "") workspace_name = os.environ.get("WORKSPACE_NAME", "") assert len( client_id) > 0, "AZURE_CLIENT_ID not found in environment variables." assert len(client_secret ) > 0, "AZURE_CLIENT_SECRET not found in environment variables." assert len( tenant_id) > 0, "AZURE_TENANT_ID not found in environment variables." assert len(resource_group ) > 0, "RESOURCE_GROUP not found in environment variables." assert len(subscription_id ) > 0, "SUBSCRIPTION_ID not found in environment variables." assert len(workspace_name ) > 0, "WORKSPACE_NAME not found in environment variables." if len(client_secret) > 0: workspace = Workspace( subscription_id=subscription_id, resource_group=resource_group, name=workspace_name, ) workspace.credentials = ServicePrincipalCredentials( tenant=tenant_id, client_id=client_id, secret=client_secret, resource="https://quantum.microsoft.com") workspace.login() return workspace
def SPLogin(): quantumWorkspace = {} try: quantumWorkspace = Workspace( subscription_id=os.environ.get( 'subscriptionId'), # Add your subscription_id resource_group=os.environ.get( 'resourceGroup'), # Add your resource_group name=os.environ.get( 'quantumWorkspaceName'), # Add your workspace name location=os.environ.get( 'quantumLocation' ) # Add the workspace location, for example, westus ) if (os.environ.get('loginMethod') == 'servicePrincipal'): quantumWorkspace.credentials = ServicePrincipalCredentials( tenant=os.environ.get( 'directoryId' ), # From service principal creation, your Directory (tenant) ID client_id=os.environ.get( 'appId' ), # From service principal creation, your Application (client) ID secret=os.environ.get( 'appsecret' ), # From service principal creation, your secret resource= "https://quantum.microsoft.com" # Do not change! This is the resource you want to authenticate against - the Azure Quantum service ) else: quantumWorkspace.login( ) #If you do not want to use service prinipal login you can use the interactive browser login except: KeyError('Failed to login with service principal') quantumWorkspace.login() return quantumWorkspace