def get_conf_dict(self):
        """
            Build up a configuration dictionary that is standard for ALL IEs.

            TODO: replace hashed password with plaintext.
        """
        trans = self.trans
        request = trans.request
        api_key = api_keys.ApiKeyManager(trans.app).get_or_create_api_key(trans.user)
        conf_file = {
            'history_id': self.attr.history_id,
            'api_key': api_key,
            'remote_host': request.remote_addr,
            # DOCKER_PORT is NO LONGER AVAILABLE. All IEs must update.
            'cors_origin': request.host_url,
            'user_email': self.trans.user.email,
            'proxy_prefix': self.attr.proxy_prefix,
        }

        web_port = self.attr.galaxy_config.galaxy_infrastructure_web_port
        conf_file['galaxy_web_port'] = web_port or self.attr.galaxy_config.guess_galaxy_port()

        if self.attr.viz_config.has_option("docker", "galaxy_url"):
            conf_file['galaxy_url'] = self.attr.viz_config.get("docker", "galaxy_url")
        elif self.attr.galaxy_config.galaxy_infrastructure_url_set:
            conf_file['galaxy_url'] = self.attr.galaxy_config.galaxy_infrastructure_url.rstrip('/') + '/'
        else:
            conf_file['galaxy_url'] = request.application_url.rstrip('/') + '/'
            # Galaxy paster port is deprecated
            conf_file['galaxy_paster_port'] = conf_file['galaxy_web_port']

        return conf_file
예제 #2
0
파일: users.py 프로젝트: msauria/galaxy
 def create_api_key(self, user):
     """
     Create and return an API key for `user`.
     """
     # TODO: seems like this should return the model
     # Also TODO: seems unused? drop and see what happens? -John
     return api_keys.ApiKeyManager(self.app).create_api_key(user)
예제 #3
0
    def __build_environment_variables(self):
        param_dict = self.param_dict
        environment_variables = []
        for environment_variable_def in self.tool.environment_variables:
            directory = self.local_working_directory
            environment_variable = environment_variable_def.copy()
            environment_variable_template = environment_variable_def[
                "template"]
            inject = environment_variable_def.get("inject")
            if inject == "api_key":
                if self._user:
                    from galaxy.managers import api_keys
                    environment_variable_template = api_keys.ApiKeyManager(
                        self.app).get_or_create_api_key(self._user)
                else:
                    environment_variable_template = ""
                is_template = False
            else:
                is_template = True
            with tempfile.NamedTemporaryFile(dir=directory,
                                             prefix="tool_env_",
                                             delete=False) as temp:
                config_filename = temp.name
            self.__write_workdir_file(config_filename,
                                      environment_variable_template,
                                      param_dict,
                                      is_template=is_template,
                                      strip=environment_variable_def.get(
                                          "strip", False))
            config_file_basename = os.path.basename(config_filename)
            # environment setup in job file template happens before `cd $working_directory`
            environment_variable["value"] = '`cat "%s/%s"`' % (
                self.compute_environment.env_config_directory(),
                config_file_basename)
            environment_variable["raw"] = True
            environment_variable["job_directory_path"] = config_filename
            environment_variables.append(environment_variable)

        home_dir = self.compute_environment.home_directory()
        tmp_dir = self.compute_environment.tmp_directory()
        if home_dir:
            environment_variable = dict(name="HOME",
                                        value='"%s"' % home_dir,
                                        raw=True)
            environment_variables.append(environment_variable)
        if tmp_dir:
            for tmp_directory_var in self.tool.tmp_directory_vars:
                environment_variable = dict(name=tmp_directory_var,
                                            value='"%s"' % tmp_dir,
                                            raw=True)
                environment_variables.append(environment_variable)
        self.environment_variables = environment_variables
        return environment_variables
    def write_conf_file(self, output_directory, extra={}):
        """
            Build up a configuration file that is standard for ALL IEs.

            TODO: replace hashed password with plaintext.
        """
        trans = self.trans
        request = trans.request
        api_key = api_keys.ApiKeyManager(trans.app).get_or_create_api_key(
            trans.user)
        conf_file = {
            'history_id': self.attr.history_id,
            'api_key': api_key,
            'remote_host': request.remote_addr,
            'docker_port': self.attr.PORT,
            'cors_origin': request.host_url,
        }

        if self.attr.viz_config.has_option("docker", "galaxy_url"):
            conf_file['galaxy_url'] = self.attr.viz_config.get(
                "docker", "galaxy_url")
        elif self.attr.galaxy_config.galaxy_infrastructure_url_set:
            conf_file[
                'galaxy_url'] = self.attr.galaxy_config.galaxy_infrastructure_url.rstrip(
                    '/') + '/'
        else:
            conf_file['galaxy_url'] = request.application_url.rstrip('/') + '/'
            web_port = self.attr.galaxy_config.galaxy_infrastructure_web_port
            conf_file[
                'galaxy_paster_port'] = web_port or self.attr.galaxy_config.guess_galaxy_port(
                )

        if self.attr.PASSWORD_AUTH:
            # Generate a random password + salt
            notebook_pw_salt = self.generate_password(length=12)
            notebook_pw = self.generate_password(length=24)
            m = hashlib.sha1()
            m.update(notebook_pw + notebook_pw_salt)
            conf_file['notebook_password'] = '******' % (notebook_pw_salt,
                                                             m.hexdigest())
            # Should we use password based connection or "default" connection style in galaxy
        else:
            notebook_pw = "None"

        # Some will need to pass extra data
        for extra_key in extra:
            conf_file[extra_key] = extra[extra_key]

        self.attr.notebook_pw = notebook_pw
        # Write conf
        with open(os.path.join(output_directory, 'conf.yaml'), 'wb') as handle:
            handle.write(yaml.dump(conf_file, default_flow_style=False))
예제 #5
0
 def get_api_key():
     return api_keys.ApiKeyManager(trans.app).get_or_create_api_key(
         trans.user)
예제 #6
0
 def __init__(self, app):
     super().__init__(app)
     self.user_manager = users.UserManager(app)
     self.user_serializer = users.UserSerializer(app)
     self.user_deserializer = users.UserDeserializer(app)
     self.api_key_manager = api_keys.ApiKeyManager(app)
예제 #7
0
 def create_api_key(self, user):
     """
     Create and return an API key for `user`.
     """
     # TODO: seems like this should return the model
     return api_keys.ApiKeyManager(self.app).create_api_key(user)
예제 #8
0
 def __init__(self, app):
     super(AuthenticationController, self).__init__(app)
     self.api_keys_manager = api_keys.ApiKeyManager(app)
예제 #9
0
 def __init__(self, app):
     super().__init__(app)
     self.user_manager = users.UserManager(app)
     self.api_keys_manager = api_keys.ApiKeyManager(app)