def _get_remote_env_vars(auth_key=None): """Generate environment variables include SSH command for Git clone. :param auth_key: If supplied results in using SSH to clone the repository with the specified key. If the value is None, SSH is not used. :returns: Dictionary of key-value pairs for Git clone. :rtype: dict :raises GitSSHException: If the SSH key specified by ``CONF.ssh_key_path`` could not be found and ``auth_method`` is "SSH". """ auth_key = auth_key or config.get_repo_key() env_vars = {'GIT_TERMINAL_PROMPT': '0'} if auth_key: if os.path.exists(auth_key): # Ensure that host checking is ignored, to avoid unnecessary # required CLI input. ssh_cmd = ( 'ssh -i {} -o ConnectionAttempts=20 -o ConnectTimeout=10 -o ' 'StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'. format(os.path.expanduser(auth_key))) env_vars.update({'GIT_SSH_COMMAND': ssh_cmd}) else: msg = "The auth_key path '%s' was not found" % auth_key LOG.error(msg) raise exceptions.GitSSHException(ssh_key_path=auth_key) return env_vars
def _process_site_repository(repo_url_or_path, repo_revision): """Process the primary or site repository located at ``repo_url_or_path``. Also validate that the provided ``repo_url_or_path`` is a valid Git repository. If ``repo_url_or_path`` doesn't already exist, clone it. If it does, extract the appropriate revision and check it out. :param repo_url_or_path: Repo path or URL and associated auth information. If URL, examples include: * ssh://REPO_USERNAME@<GIT_URL>:29418/global-manifests.git@<ref> * https://<GIT_URL>/global-manifests.git@<ref> * http://<GIT_URL>/global-manifests.git@<ref> * <LOCAL_REPO_PATH>@<ref> * same values as above without @<ref> :param str repo_revision: branch, commit or ref in the repo to checkout. """ repo_alias = 'site' # We are processing the site repo necessarily. repo_key = config.get_repo_key() repo_user = config.get_repo_username() LOG.info( "Processing repository %s with url=%s, repo_key=%s, " "repo_username=%s, revision=%s", repo_alias, repo_url_or_path, repo_key, repo_user, repo_revision) return _handle_repository(repo_url_or_path, ref=repo_revision, auth_key=repo_key)
def process_repositories(site_name): """Process and setup all repositories including ensuring we are at the right revision based on the site's own site-definition.yaml file. :param site_name: Site name for which to clone relevant repos. """ # Only tracks extra repositories - not the site (primary) repository. extra_repos = [] site_repo = process_site_repository() # Retrieve extra repo data from site-definition.yaml files. site_data = util.definition.load_as_params(site_name, primary_repo_base=site_repo) site_def_repos = _get_and_validate_site_repositories(site_name, site_data) # Dict mapping repository names to associated URL/revision info for clone. repo_overrides = _process_repository_overrides(site_def_repos) if not site_def_repos: LOG.info( 'No repositories found in site-definition.yaml for site: %s. ' 'Defaulting to specified repository overrides.', site_name) site_def_repos = repo_overrides # Extract user/key that we will use for all repositories. repo_key = config.get_repo_key() repo_user = config.get_repo_username() for repo_alias in site_def_repos.keys(): if repo_alias == "site": LOG.warning( "The primary site repository path must be specified " "via the -r flag. Ignoring the provided " "site-definition entry: %s", site_def_repos[repo_alias]) continue # Extract URL and revision, prioritizing overrides over the defaults in # the site-definition.yaml. if repo_alias in repo_overrides: repo_url_or_path = repo_overrides[repo_alias]['url'] repo_revision = repo_overrides[repo_alias]['revision'] else: repo_url_or_path = site_def_repos[repo_alias]['url'] repo_revision = site_def_repos[repo_alias]['revision'] repo_url_or_path = _format_url_with_repo_username(repo_url_or_path) LOG.info( "Processing repository %s with url=%s, repo_key=%s, " "repo_username=%s, revision=%s", repo_alias, repo_url_or_path, repo_key, repo_user, repo_revision) temp_extra_repo = _process_repository(repo_url_or_path, repo_revision) extra_repos.append(temp_extra_repo) # Overwrite the site repo and extra repos in the config because further # processing will fail if they contain revision info in their paths. LOG.debug("Updating site_repo=%s extra_repo_list=%s in config", site_repo, extra_repos) config.set_site_repo(site_repo) config.set_extra_repo_list(extra_repos)