Esempio n. 1
0
    def _set_ssh_url(self):
        """
        Replace instance URL with SSH substitution result and report to log.
        According to ``man ssh-add``, ``SSH_AUTH_SOCK`` must be set in order for ``ssh-add`` to work.
        """
        if self.session.config.get('agent.force_git_ssh_protocol',
                                   None) and self.url:
            parsed_url = furl(self.url)
            if parsed_url.scheme == "https":
                new_url = self.replace_http_url(self.url)
                if new_url != self.url:
                    print(
                        "Using SSH credentials - replacing https url '{}' with ssh url '{}'"
                        .format(self.url, new_url))
                    self.url = new_url
                return

        if not self.session.config.agent.translate_ssh:
            return

        ssh_agent_variable = "SSH_AUTH_SOCK"
        if not getenv(ssh_agent_variable) and (
            (ENV_AGENT_GIT_USER.get()
             or self.session.config.get('agent.git_user', None)) and
            (ENV_AGENT_GIT_PASS.get()
             or self.session.config.get('agent.git_pass', None))):
            new_url = self.replace_ssh_url(self.url)
            if new_url != self.url:
                print(
                    "Using user/pass credentials - replacing ssh url '{}' with https url '{}'"
                    .format(self.url, new_url))
                self.url = new_url
Esempio n. 2
0
 def add_auth(cls, config, url):
     """
     Add username and password to URL if missing from URL and present in config.
     Does not modify ssh URLs.
     """
     parsed_url = furl(url)
     if parsed_url.scheme in ["", "ssh"
                              ] or parsed_url.scheme.startswith("git"):
         return parsed_url.url
     config_user = ENV_AGENT_GIT_USER.get() or config.get(
         "agent.{}_user".format(cls.executable_name), None)
     config_pass = ENV_AGENT_GIT_PASS.get() or config.get(
         "agent.{}_pass".format(cls.executable_name), None)
     if ((not (parsed_url.username and parsed_url.password)) and config_user
             and config_pass):
         parsed_url.set(username=config_user, password=config_pass)
     return parsed_url.url
Esempio n. 3
0
 def add_auth(cls, config, url):
     """
     Add username and password to URL if missing from URL and present in config.
     Does not modify ssh URLs.
     """
     try:
         parsed_url = furl(url)
     except ValueError:
         return url
     if parsed_url.scheme in ["", "ssh"] or parsed_url.scheme.startswith("git"):
         return parsed_url.url
     config_user = ENV_AGENT_GIT_USER.get() or config.get("agent.{}_user".format(cls.executable_name), None)
     config_pass = ENV_AGENT_GIT_PASS.get() or config.get("agent.{}_pass".format(cls.executable_name), None)
     config_domain = ENV_AGENT_GIT_HOST.get() or config.get("agent.{}_host".format(cls.executable_name), None)
     if (
         (not (parsed_url.username and parsed_url.password))
         and config_user
         and config_pass
         and (not config_domain or config_domain.lower() == parsed_url.host)
     ):
         parsed_url.set(username=config_user, password=config_pass)
     return parsed_url.url
Esempio n. 4
0
    def _set_ssh_url(self):
        """
        Replace instance URL with SSH substitution result and report to log.
        According to ``man ssh-add``, ``SSH_AUTH_SOCK`` must be set in order for ``ssh-add`` to work.
        """
        if self.session.config.get('agent.force_git_ssh_protocol', None) and self.url:
            parsed_url = furl(self.url)
            # only apply to a specific domain (if requested)
            config_domain = \
                ENV_AGENT_GIT_HOST.get() or self.session.config.get("agent.git_host", None)
            if config_domain and config_domain != parsed_url.host:
                return
            if parsed_url.scheme == "https":
                new_url = self.replace_http_url(
                    self.url, port=self.session.config.get('agent.force_git_ssh_port', None))
                if new_url != self.url:
                    print("Using SSH credentials - replacing https url '{}' with ssh url '{}'".format(
                        self.url, new_url))
                    self.url = new_url
                return

        if not self.session.config.agent.translate_ssh:
            return

        # if we have git_user / git_pass replace ssh credentials with https authentication
        if (ENV_AGENT_GIT_USER.get() or self.session.config.get('agent.git_user', None)) and \
                (ENV_AGENT_GIT_PASS.get() or self.session.config.get('agent.git_pass', None)):
            # only apply to a specific domain (if requested)
            config_domain = \
                ENV_AGENT_GIT_HOST.get() or self.session.config.get("git_host", None)
            if config_domain and config_domain != furl(self.url).host:
                return

            new_url = self.replace_ssh_url(self.url)
            if new_url != self.url:
                print("Using user/pass credentials - replacing ssh url '{}' with https url '{}'".format(
                    self.url, new_url))
                self.url = new_url