コード例 #1
0
    def __init__(
        self,
        account_name: str,
        account_key: str = None,
        connection_string: str = None,
        credential: str = None,
        sas_token: str = None,
        request_session=None,
        socket_timeout: int = None,
        blocksize: int = create_configuration(
            storage_sdk="blob").max_block_size,
        client_id: str = None,
        client_secret: str = None,
        tenant_id: str = None,
    ):
        AbstractFileSystem.__init__(self)
        self.account_name = account_name
        self.account_key = account_key
        self.connection_string = connection_string
        self.credential = credential
        self.sas_token = sas_token
        self.request_session = request_session
        self.socket_timeout = socket_timeout
        self.blocksize = blocksize
        self.client_id = client_id
        self.client_secret = client_secret
        self.tenant_id = tenant_id

        if (self.credential is None and self.account_key is None
                and self.sas_token is None and self.client_id is not None):
            self.credential = self._get_credential_from_service_principal()
        self.do_connect()
コード例 #2
0
    def init(self):
        if ContainerClient is None or create_configuration is None:
            raise MissingDependencyError("azure.storage", version='>=12.0.0')

        self.config = create_configuration(storage_sdk='blob')
        if hasattr(self, 'https_proxy'):
            # Create a storage configuration object and update the proxy policy
            self.config.proxy_policy.proxies = {
                'http': self.http_proxy,
                'https': self.https_proxy,
            }
コード例 #3
0
ファイル: collector_azure.py プロジェクト: tomas321/intelmq
    def init(self):
        if ContainerClient is None or create_configuration is None:
            raise MissingDependencyError("azure.storage")

        self.config = create_configuration(storage_sdk='blob')
        if hasattr(self.parameters, 'https_proxy'):
            # Create a storage configuration object and update the proxy policy
            self.config.proxy_policy.proxies = {
                'http': self.parameters.http_proxy,
                'https': self.parameters.https_proxy,
            }

        self.cache = Cache(
            self.parameters.redis_cache_host,
            self.parameters.redis_cache_port,
            self.parameters.redis_cache_db,
            getattr(self.parameters, 'redis_cache_ttl', 864000),  # 10 days
            getattr(self.parameters, "redis_cache_password", None))
connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', None)
if not connection_string:
    print('AZURE_STORAGE_CONNECTION_STRING required.')
    sys.exit(1)

# configure logging
logger = logging.getLogger('azure')
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
logger.setLevel(logging.DEBUG)

# TODO: Update this with your actual proxy information.
http_proxy = 'http://10.10.1.10:1180'
https_proxy = 'http://*****:*****@10.10.1.10:1180/'

# Create a storage Configuration object and update the proxy policy.
config = create_configuration(storage_sdk='blob')
config.proxy_policy.proxies = {'http': http_proxy, 'https': https_proxy}
# Construct the BlobServiceClient, including the customized configuation.
service_client = BlobServiceClient.from_connection_string(
    connection_string, _configuration=config)
containers = list(service_client.list_containers(logging_enable=True))
print("{} containers.".format(len(containers)))

# Alternatively, proxy settings can be set using environment variables, with no
# custom configuration necessary.
HTTP_PROXY_ENV_VAR = 'HTTP_PROXY'
HTTPS_PROXY_ENV_VAR = 'HTTPS_PROXY'
os.environ[HTTPS_PROXY_ENV_VAR] = https_proxy

service_client = BlobServiceClient.from_connection_string(connection_string)
containers = list(service_client.list_containers(logging_enable=True))