예제 #1
0
def region_from_key_id(signingKeyId, default_region=None):
    try:
        region_name = signingKeyId.split(":", 4)[3]
    except IndexError:
        if default_region is None:
            raise UnknownRegionError(
                "No default region found and no region determinable from key id: {}"
                .format(signingKeyId))
        region_name = default_region
    return region_name
    def __call__(self, region_name):
        # type: (Union[None, str]) -> BaseClient
        """Return a client for the requested region.

        :rtype: BaseClient
        :raises UnknownRegionError: if a region is requested that is in ``denied_regions``
        """
        if region_name in self.denied_regions:
            raise UnknownRegionError(
                "Unable to provide client for region '{}'".format(region_name))

        return self._client_supplier(region_name)
예제 #3
0
    def _client(self, key_id):
        """Returns a Boto3 KMS client for the appropriate region.

        :param str key_id: KMS CMK ID
        """
        try:
            region_name = key_id.split(':', 4)[3]
            if self.default_region is None:
                self.default_region = region_name
        except IndexError:
            if self.default_region is None:
                raise UnknownRegionError(
                    'No default region found and no region determinable from key id: {}'
                    .format(key_id))
            region_name = self.default_region
        self.add_regional_client(region_name)
        return self._regional_clients[region_name]
예제 #4
0
def _region_from_key_id(key_id, default_region=None):
    """Determine the target region from a key ID, falling back to a default region if provided.

    :param str key_id: AWS KMS key ID
    :param str default_region: Region to use if no region found in key_id
    :returns: region name
    :rtype: str
    :raises UnknownRegionError: if no region found in key_id and no default_region provided
    """
    try:
        region_name = key_id.split(":", 4)[3]
    except IndexError:
        if default_region is None:
            raise UnknownRegionError(
                "No default region found and no region determinable from key id: {}"
                .format(key_id))
        region_name = default_region
    return region_name