Sign a remote file to distribute. The azure url format is https://myaccount.blob.core.windows.net/mycontainer/myblob.
         Args:
             remote_file(str): The blob that we want to sign.
352324
def generate_url(self, remote_file):
        
        parse_url = _parse_url(remote_file)
        key = self.storage_client.storage_accounts.list_keys(self.resource_group_name, parse_url.account).keys[0].value
        if parse_url.file_type == 'blob':
            bs = BlockBlobService(account_name=parse_url.account, account_key=key)

            sas_token = bs.generate_blob_shared_access_signature(parse_url.container_or_share_name,
                                                                 parse_url.file,
                                                                 permission=BlobPermissions.READ,
                                                                 expiry=datetime.utcnow() + timedelta(hours=24),
                                                                 )
            source_blob_url = bs.make_blob_url(container_name=parse_url.container_or_share_name,
                                               blob_name=parse_url.file,
                                               sas_token=sas_token)
            return source_blob_url
        elif parse_url.file_type == 'file':
            fs = FileService(account_name=parse_url.account, account_key=key)
            sas_token = fs.generate_file_shared_access_signature(share_name=parse_url.container_or_share_name,
                                                                 directory_name=parse_url.path,
                                                                 file_name=parse_url.file,
                                                                 permission=BlobPermissions.READ,
                                                                 expiry=datetime.utcnow() + timedelta(hours=24),
                                                                 )
            source_file_url = fs.make_file_url(share_name=parse_url.container_or_share_name,
                                               directory_name=parse_url.path,
                                               file_name=parse_url.file,
                                               sas_token=sas_token)
            return source_file_url
        else:
            raise ValueError("This azure storage type is not valid. It should be blob or file.")
486213
def copy_file_from_agent(
        host,
        remote_path,
        file_path='.',
        username=None,
        key_path=None
):
    

    return copy_file(host, file_path, remote_path, username, key_path, 'get')
355580
def _sign_url(self, base_url, params, security_key):
        
        import hashlib

        if six.PY3:
            from urllib.parse import urlencode, quote, quote_plus
        else:
            from urllib import urlencode, quote, quote_plus

        if not base_url or not self.security_key:
            return None

        params = params.copy()
        address = params.pop('address')

        url = base_url + '?address=' + address + '&' + urlencode(params)
        encoded_url = quote(url, safe="/:=&?#+!$,;'@()*[]")

        signature = quote_plus(encoded_url + self.security_key).encode('utf-8')
        encoded_signature = hashlib.md5(signature).hexdigest()

        return encoded_signature
949086
def sign(self, blob, identity):
        """"""
        conn = self.conn_factory()
        return conn.sign_ssh_challenge(blob=blob, identity=identity)
486090
def _sign_string(message, private_key_file=None, private_key_string=None):
        
        try:
            from M2Crypto import EVP
        except ImportError:
            raise NotImplementedError("Boto depends on the python M2Crypto "
                                      "library to generate signed URLs for "
                                      "CloudFront")
        # Make sure only one of private_key_file and private_key_string is set
        if private_key_file and private_key_string:
            raise ValueError("Only specify the private_key_file or the private_key_string not both")
        if not private_key_file and not private_key_string:
            raise ValueError("You must specify one of private_key_file or private_key_string")
        # if private_key_file is a file object read the key string from there
        if isinstance(private_key_file, file):
            private_key_string = private_key_file.read()
        # Now load key and calculate signature
        if private_key_string:
            key = EVP.load_key_string(private_key_string)
        else:
            key = EVP.load_key(private_key_file)
        key.reset_context(md='sha1')
        key.sign_init()
        key.sign_update(str(message))
        signature = key.sign_final()
        return signature
484822
def url(self, filetype, base_dir=None, sasdir='sas', **kwargs):
        

        location = self.location(filetype, **kwargs)
        return join(self.remote_base, sasdir, location) if self.remote_base and location else None
308073
def open_remote(cls, username, password, multifactor_password=None, client_id=None):
        """"""
        blob = cls.fetch_blob(username, password, multifactor_password, client_id)
        return cls.open(blob, username, password)
937588
def _add_to_transfer_queue(self, src_ase, dst_ase):
        # type: (SyncCopy, blobxfer.models.azure.StorageEntity,
        #        blobxfer.models.azure.StorageEntity) -> None
        
        # prepare remote file for download
        # if remote file is a block blob, need to retrieve block list
        if (src_ase.mode == dst_ase.mode ==
                blobxfer.models.azure.StorageModes.Block):
            bl = blobxfer.operations.azure.blob.block.get_committed_block_list(
                src_ase)
        else:
            bl = None
        # TODO future optimization for page blob synccopies: query
        # page ranges and omit cleared pages from being transferred
        sd = blobxfer.models.synccopy.Descriptor(
            src_ase, dst_ase, bl, self._spec.options, self._resume)
        # add download descriptor to queue
        self._transfer_queue.put(sd)
        if self._synccopy_start_time is None:
            with self._transfer_lock:
                if self._synccopy_start_time is None:
                    self._synccopy_start_time = blobxfer.util.datetime_now()
1135832
def get_remote_file(url):
    
    try:
        return requests.get(url)
    except requests.exceptions.ConnectionError as e:
        print("Connection error!")
        print(e.message.reason)
        exit(1)
848610
def _add_to_download_queue(self, lpath, rfile):
        # type: (Downloader, pathlib.Path,
        #        blobxfer.models.azure.StorageEntity) -> None
        
        # prepare remote file for download
        dd = blobxfer.models.download.Descriptor(
            lpath, rfile, self._spec.options, self._general_options,
            self._resume)
        with self._transfer_lock:
            self._transfer_cc[dd.entity.path] = 0
            if dd.entity.is_encrypted:
                self._dd_map[str(dd.final_path)] = dd
        # add download descriptor to queue
        self._transfer_queue.put(dd)
        if self._download_start_time is None:
            with self._transfer_lock:
                if self._download_start_time is None:
                    self._download_start_time = blobxfer.util.datetime_now()
837370
def connect(cls, resource):
        
        from azure import storage as azure_storage
        file_info = cls.parse_remote(resource)
        return azure_storage.BlobService(file_info.storage)
472861
def send_file_to_remote(dev, src_file, dst_filename, filesize, dst_mode='wb'):
    
    bytes_remaining = filesize
    save_timeout = dev.timeout
    dev.timeout = 1
    while bytes_remaining > 0:
        # Wait for ack so we don't get too far ahead of the remote
        ack = dev.read(1)
        if ack is None or ack != b'\x06':
            sys.stderr.write("timed out or error in transfer to remote\n")
            sys.exit(2)

        if HAS_BUFFER:
            buf_size = BUFFER_SIZE
        else:
            buf_size = BUFFER_SIZE // 2
        read_size = min(bytes_remaining, buf_size)
        buf = src_file.read(read_size)
        #sys.stdout.write('\r%d/%d' % (filesize - bytes_remaining, filesize))
        #sys.stdout.flush()
        if HAS_BUFFER:
            dev.write(buf)
        else:
            dev.write(binascii.hexlify(buf))
        bytes_remaining -= read_size
    #sys.stdout.write('\r')
    dev.timeout = save_timeout
443757
def create_ssl_certificate(cert_params)
      file_path = cert_params[:output_file].sub(/\.(\w+)$/, "")
      path = prompt_for_file_path
      file_path = File.join(path, file_path) unless path.empty?
      cert_params[:domain] = prompt_for_domain

      rsa_key = generate_keypair cert_params[:key_length]
      cert = generate_certificate(rsa_key, cert_params)
      write_certificate_to_file cert, file_path, rsa_key, cert_params
      puts "*" * 70
      puts "Generated Certificates:"
      puts "- #{file_path}.pfx - PKCS12 format keypair. Contains both the public and private keys, usually used on the server."
      puts "- #{file_path}.b64 - Base64 encoded PKCS12 keypair. Contains both the public and private keys, for upload to the Azure REST API."
      puts "- #{file_path}.pem - Base64 encoded public certificate only. Required by the client to connect to the server."
      puts "Certificate Thumbprint: #{@thumbprint.to_s.upcase}"
      puts "*" * 70

      Chef::Config[:knife][:ca_trust_file] = file_path + ".pem" if Chef::Config[:knife][:ca_trust_file].nil?
      cert_data = File.read (file_path + ".b64")
      add_certificate cert_data, @winrm_cert_passphrase, "pfx", cert_params[:azure_dns_name]
      @thumbprint
    end
668744
def _sign(self, data: bytes) -> bytes:
        
        assert self._raiden_service is not None
        return self._raiden_service.signer.sign(data=data)
228236
def recv_file_from_remote(dev, src_filename, dst_file, filesize):
    
    bytes_remaining = filesize
    if not HAS_BUFFER:
        bytes_remaining *= 2  # hexlify makes each byte into 2
    buf_size = BUFFER_SIZE
    write_buf = bytearray(buf_size)
    while bytes_remaining > 0:
        read_size = min(bytes_remaining, buf_size)
        buf_remaining = read_size
        buf_index = 0
        while buf_remaining > 0:
            read_buf = dev.read(buf_remaining)
            bytes_read = len(read_buf)
            if bytes_read:
                write_buf[buf_index:bytes_read] = read_buf[0:bytes_read]
                buf_index += bytes_read
                buf_remaining -= bytes_read
        if HAS_BUFFER:
            dst_file.write(write_buf[0:read_size])
        else:
            dst_file.write(binascii.unhexlify(write_buf[0:read_size]))
        # Send an ack to the remote as a form of flow control
        dev.write(b'\x06')   # ASCII ACK is 0x06
        bytes_remaining -= read_size
400594
def _get_signed_url(self, params):
        
        params['client'] = self.client_id

        if self.channel:
            params['channel'] = self.channel

        path = "?".join((self.api_path, urlencode(params)))
        signature = hmac.new(
            base64.urlsafe_b64decode(self.secret_key),
            path.encode('utf-8'),
            hashlib.sha1
        )
        signature = base64.urlsafe_b64encode(
            signature.digest()
        ).decode('utf-8')
        return '%s://%s%s&signature=%s' % (
            self.scheme, self.domain, path, signature
        )
809522
def _sign(self, data):
        

        # Python2/3 urlencode aren't good enough for this task.
        params = "&".join(
            "=".join((key, cs_encode(value)))
            for key, value in sorted(data.items())
        )

        digest = hmac.new(
            self.secret.encode('utf-8'),
            msg=params.lower().encode('utf-8'),
            digestmod=hashlib.sha1).digest()

        return base64.b64encode(digest).decode('utf-8').strip()