Beispiel #1
0
    def init_config(self, config):
        self.access_key = os.environ.get(u'PYU_AWS_ID')
        if self.access_key is None:
            raise UploaderError('Missing PYU_AWS_ID', expected=True)

        self.secret_key = os.environ.get(u'PYU_AWS_SECRET')
        if self.secret_key is None:
            raise UploaderError(u'Missing PYU_AWS_SECRET', expected=True)

        self.region = os.environ.get(u'PYU_REGION')

        self.url = os.environ.get('PYU_URL')

        self.secret_key = os.environ.get(u'PYU_AWS_SECRET')
        if self.secret_key is None:
            raise UploaderError(u'Missing PYU_AWS_SECRET', expected=True)

        self.session_token = os.environ.get(u'PYU_AWS_SESSION_TOKEN')

        # Try to get bucket from env var
        self.bucket_name = os.environ.get(u'PYU_AWS_BUCKET')
        bucket_name = config.get(u'bucket_name')

        # If there is a bucket name in the repo config we
        # override the env var
        if bucket_name is not None:
            self.bucket_name = bucket_name

        # If nothing is set throw an error
        if self.bucket_name is None:
            raise UploaderError(u'Bucket name is not set', expected=True)
        self._connect()
Beispiel #2
0
    def init_config(self, config):
        self.endpoint = os.environ.get('PYU_ENDPOINT')
        if self.endpoint is None:
            raise UploaderError('Missing PYU_ENDPOINT',
                                expected=True)
        self.access_key = os.environ.get(u'PYU_ACCESSKEY')
        if self.access_key is None:
            raise UploaderError('Missing PYU_ACCESSKEY',
                                expected=True)

        self.secret_key = os.environ.get(u'PYU_SECRET_KEY')
        if self.secret_key is None:
            raise UploaderError(u'Missing PYU_SECRET_KEY',
                                expected=True)

        self.session_token = os.environ.get(u'PYU_SESSION_TOKEN')

        # Try to get bucket from env var
        self.bucket_name = os.environ.get(u'PYU_BUCKET').lower()
        bucket_name = config.get(u'bucket_name')

        # If there is a bucket name in the repo config we
        # override the env var
        if bucket_name is not None:
            self.bucket_name = bucket_name

        # If nothing is set throw an error
        if self.bucket_name is None:
            raise UploaderError(u'Bucket name is not set',
                                expected=True)
        self._connect()
    def init_config(self, config):
        self.access_key = os.environ.get(u'PYU_AWS_ID')
        if self.access_key is None:
            raise UploaderError('Missing PYU_AWS_ID', expected=True)

        self.secret_key = os.environ.get(u'PYU_AWS_SECRET')
        if self.secret_key is None:
            raise UploaderError(u'Missing PYU_AWS_SECRET', expected=True)

        self.session_token = os.environ.get(u'PYU_AWS_SESSION_TOKEN')

        # Try to get bucket from env var
        self.bucket_name = os.environ.get(u'PYU_AWS_BUCKET')
        bucket_name = config.get(u'bucket_name')

        # If there is a bucket name in the repo config we
        # override the env var
        if bucket_name is not None:
            self.bucket_name = bucket_name

        # If nothing is set throw an error
        if self.bucket_name is None:
            raise UploaderError(u'Bucket name is not set', expected=True)

        # Try to get bucket key from env var
        self.bucket_key = os.environ.get(u'PYU_AWS_BUCKET_KEY')
        bucket_key = config.get(u'bucket_key')

        # If there is a bucket key in the repo config we
        # override the env var
        if bucket_key is not None:
            self.bucket_key = bucket_key

        # If nothing is set default to bucket root
        if self.bucket_key is None:
            self.bucket_key = ''

        # Strip slashes for sanity
        self.bucket_key = self.bucket_key.rstrip('/\\').lstrip('/\\')

        # Try to get bucket region
        self.bucket_region = os.environ.get(u'PYU_AWS_BUCKET_REGION')
        bucket_region = config.get(u'bucket_region')

        # If there is a bucket key in the repo config we
        # override the env var
        if bucket_region is not None:
            self.bucket_region = bucket_region

        # If nothing is set default to bucket root
        if self.bucket_region is None:
            self.bucket_region = 'us-west-2'

        self._connect()
    def init_config(self, config):

        # get the connection string
        # TODO: put this into environent variable
        self.connection_string = config["connection_string"]
        if self.connection_string is None:
            raise UploaderError("Missing connection_string", expected=True)

        # get the blob container name
        self.blob_container_name = config["blob_container_name"]
        if self.blob_container_name is None:
            raise UploaderError("Missing blob_container_name", expected=True)

        self._connect()
Beispiel #5
0
    def set_uploader(self, requested_uploader, keep=False):
        """Sets the named upload plugin.

        Args:

            requested_uploader (string): Either s3 or scp

        """
        self.keep = keep
        if isinstance(requested_uploader, six.string_types) is False:
            raise UploaderError('Must pass str to set_uploader', expected=True)

        self.uploader = self.mgr.get_plugin(requested_uploader, init=True)
        if self.uploader is None:
            log.debug('PLUGIN_NAMESPACE: %s', self.mgr.PLUGIN_NAMESPACE)
            raise UploaderPluginError('Requested uploader is not installed',
                                      expected=True)

        msg = 'Requested uploader: {}'.format(requested_uploader)
        log.debug(msg)

        # ToDo: Move this into it's own function.
        #            Call this new function in the upload method
        try:
            _files = os.listdir(self.deploy_dir)
        except OSError:
            _files = []

        files = []
        for f in _files:
            files.append(os.path.join(self.deploy_dir, f))

        self.files = remove_dot_files(files)
Beispiel #6
0
    def set_uploader(self, requested_uploader, keep=False):
        """Returns an uploader object. 1 of S3, SCP, SFTP.
        SFTP uploaders not supported at this time.

        Args:

            requested_uploader (string): Either s3 or scp

        Returns:

            object (instance): Uploader object
        """
        self.keep = keep
        if isinstance(requested_uploader, six.string_types) is False:
            raise UploaderError('Must pass str to set_uploader',
                                expected=True)

        self.uploader = self.mgr.get_plugin(requested_uploader, init=True)
        if self.uploader is None:
            log.debug('PLUGIN_NAMESPACE: %s', self.mgr.PLUGIN_NAMESPACE)
            raise UploaderPluginError('Requested uploader is not installed',
                                      expected=True)

        msg = 'Requested uploader: {}'.format(requested_uploader)
        log.debug(msg)
        try:
            _files = os.listdir(self.deploy_dir)
        except OSError:
            _files = []

        files = []
        for f in _files:
            files.append(os.path.join(self.deploy_dir, f))

        self.files = remove_dot_files(files)
Beispiel #7
0
    def init_config(self, config):
        # Used to set global configs.
        # Will be overridden with repo specific config
        self.username = os.environ.get(u'PYU_SSH_USERNAME')
        self.password = os.environ.get(u'PYU_SSH_PASSWORD')
        self.keyfile = os.environ.get(u'PYU_SSH_KEYFILE')
        self.host = os.environ.get(u'PYU_SSH_HOST')
        self.port = os.environ.get(u'PYU_SSH_PORT', 22)
        self.remote_dir = os.environ.get(u'PYU_SSH_REMOTE_PATH')

        username = config.get(u'username')
        if username is not None:
            self.username = username
        else:
            if self.username is None:
                raise UploaderError(u'Username is not set')

        password = config.get(u'password')
        if password is not None:
            self.password = password

        keyfile = config.get(u'keyfile')
        if keyfile is not None:
            self.keyfile = keyfile
            log.info(self.keyfile)
        else:
            if self.keyfile is None and self.password is None:
                raise UploaderError(u'Key file and password are not set')

        host = config.get(u'host')
        if host is not None:
            self.host = host
        else:
            if self.host is None:
                raise UploaderError(u'Host is not set')

        port = config.get(u'port')
        if port is not None:
            self.port = port

        remote_dir = config.get(u'remote_dir')
        if remote_dir is not None:
            self.remote_dir = remote_dir
        else:
            if self.remote_dir is None:
                raise UploaderError(u'Remote directory is not set')
        self.connect()
Beispiel #8
0
    def set_uploader(self, requested_uploader):
        """Returns an uploader object. 1 of S3, SCP, SFTP.
        SFTP uploaders not supported at this time.

        Args:

            requested_uploader (string): Either s3 or scp

        Returns:

            object (instance): Uploader object
        """
        if isinstance(requested_uploader, six.string_types) is False:
            raise UploaderError('Must pass str to set_uploader',
                                expected=True)

        try:
            plugin = self.mgr[requested_uploader]
        except KeyError:
            log.debug('EP CACHE: {}'.format(self.mgr.ENTRY_POINT_CACHE))
            raise UploaderPluginError('Requested uploader is not installed',
                                      expected=True)
        except Exception as err:  # pragma: no cover
            log.debug('EP CACHE: {}'.format(self.mgr.ENTRY_POINT_CACHE))
            log.error(str(err))
            log.debug(str(err), exc_info=True)
            raise UploaderError('Requested uploader is not installed',
                                expected=True)

        self.uploader = plugin.plugin()
        msg = 'Requested uploader: {}'.format(requested_uploader)
        log.debug(msg)
        try:
            files = os.listdir(self.deploy_dir)
        except OSError:
            files = []
        files = remove_dot_files(files)
        self.uploader.init(object_bucket=self.object_bucket,
                           ssh_username=self.ssh_username,
                           ssh_remote_dir=self.ssh_remote_dir,
                           ssh_host=self.ssh_host,
                           files=files)
Beispiel #9
0
 def upload(self):
     """Proxy function that calls the upload method on the received
     uploader. Only calls the upload method if an uploader is set.
     """
     if self.uploader is not None:
         self.uploader.deploy_dir = self.deploy_dir
         try:
             self.uploader.upload()
         except Exception as err:  # pragma: no cover
             log.error('Failed to upload: {}'.format(str(err)))
             log.debug(str(err), exc_info=True)
             sys.exit(str(err))
     else:
         raise UploaderError('Must call set_uploader first', expected=True)
    def set_uploader(self, requested_uploader, keep=False):
        """Sets the named upload plugin.

        Args:

            requested_uploader (string): Either s3 or scp

            keep (bool): False to delete files after upload.
                         True to keep files. Default False.

        """
        self.keep = keep
        if isinstance(requested_uploader, six.string_types) is False:
            raise UploaderError('Must pass str to set_uploader', expected=True)

        self.uploader = self.plg_mgr.get_plugin(requested_uploader, init=True)
        if self.uploader is None:
            log.debug('PLUGIN_NAMESPACE: %s', self.plg_mgr.PLUGIN_NAMESPACE)
            raise UploaderPluginError('Requested uploader is not installed',
                                      expected=True)

        msg = 'Requested uploader: {}'.format(requested_uploader)
        log.debug(msg)