コード例 #1
0
ファイル: test_util.py プロジェクト: tjegbejimba/azure-cli
    def test_scopes_to_resource(self):
        from azure.cli.core.util import scopes_to_resource
        # scopes as a list
        self.assertEqual(
            scopes_to_resource(
                ['https://management.core.windows.net//.default']),
            'https://management.core.windows.net/')
        # scopes as a tuple
        self.assertEqual(
            scopes_to_resource(('https://storage.azure.com/.default', )),
            'https://storage.azure.com')

        # resource with trailing slash
        self.assertEqual(
            scopes_to_resource(('https://management.azure.com//.default', )),
            'https://management.azure.com/')
        self.assertEqual(
            scopes_to_resource(['https://datalake.azure.net//.default']),
            'https://datalake.azure.net/')

        # resource without trailing slash
        self.assertEqual(
            scopes_to_resource(('https://managedhsm.azure.com/.default', )),
            'https://managedhsm.azure.com')

        # VM SSH
        self.assertEqual(
            scopes_to_resource(
                ["https://pas.windows.net/CheckMyAccess/Linux/.default"]),
            'https://pas.windows.net/CheckMyAccess/Linux')
        self.assertEqual(
            scopes_to_resource([
                "https://pas.windows.net/CheckMyAccess/Linux/user_impersonation"
            ]), 'https://pas.windows.net/CheckMyAccess/Linux')
コード例 #2
0
    def test_scopes_to_resource(self):
        from azure.cli.core.util import scopes_to_resource
        # scopes as a list
        self.assertEqual(scopes_to_resource(['https://management.core.windows.net//.default']),
                         'https://management.core.windows.net/')
        # scopes as a tuple
        self.assertEqual(scopes_to_resource(('https://storage.azure.com/.default',)),
                         'https://storage.azure.com')

        # resource with trailing slash
        self.assertEqual(scopes_to_resource(('https://management.azure.com//.default',)),
                         'https://management.azure.com/')
        self.assertEqual(scopes_to_resource(['https://datalake.azure.net//.default']),
                         'https://datalake.azure.net/')

        # resource without trailing slash
        self.assertEqual(scopes_to_resource(('https://managedhsm.azure.com/.default',)),
                         'https://managedhsm.azure.com')
コード例 #3
0
def _try_scopes_to_resource(scopes):
    """Wrap scopes_to_resource to workaround some SDK issues."""

    # Track 2 SDKs generated before https://github.com/Azure/autorest.python/pull/239 don't maintain
    # credential_scopes and call `get_token` with empty scopes.
    # As a workaround, return None so that the CLI-managed resource is used.
    if not scopes:
        logger.debug("No scope is provided by the SDK, use the CLI-managed resource.")
        return None

    # Track 2 SDKs generated before https://github.com/Azure/autorest.python/pull/745 extend default
    # credential_scopes with custom credential_scopes. Instead, credential_scopes should be replaced by
    # custom credential_scopes. https://github.com/Azure/azure-sdk-for-python/issues/12947
    # As a workaround, remove the first one if there are multiple scopes provided.
    if len(scopes) > 1:
        logger.debug("Multiple scopes are provided by the SDK, discarding the first one: %s", scopes[0])
        return scopes_to_resource(scopes[1:])

    # Exactly only one scope is provided
    return scopes_to_resource(scopes)