Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable default SSH access to private GitHub repositories #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cmake/cmaize/globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ cpp_set_global(
"H;h;HPP;hpp;HXX;hxx;HH;hh"
)

#[[[
# URL prefix for GitHub SSH access. Defaults to ``[email protected]``.
# This option allows for SSH aliases, e.g. ``git@github-alt-account``
# where ``githut-alt-account` is a user-defined alias for GitHub
# SSH access defined in a user's $HOME/.ssh/config.
#]]
cpp_set_global(
CMAIZE_GITHUB_SSH_PREFIX
"[email protected]"
)

#[[[
# GitHub token used to access private repositories. It is defaulted to the
# value of the old ``CPP_GITHUB_TOKEN`` for backwards compatability and
Expand All @@ -20,6 +31,16 @@ cpp_set_global(
"${CPP_GITHUB_TOKEN}"
)

#[[[
# Use SSH access for private GitHub repositories toa void OAuth token
# requirements. See ``CMAIZE_GITHUB_SSH_PREFIX`` for details pertaining
# to chaging default GitHub SSH access prefixes.
#]]
cpp_set_global(
CMAIZE_GITHUB_USE_SSH
OFF
)

#[[[
# Current CMaize project.
#]]
Expand Down
6 changes: 5 additions & 1 deletion cmake/cmaize/package_managers/cmake/dependency/github.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ cpp_class(GitHubDependency Dependency)
GitHubDependency(GET "${_bd_this}" _bd_name name)
GitHubDependency(GET "${_bd_this}" _bd_cmake_args cmake_args)

if( _bd_private AND CMAIZE_GITHUB_USE_SSH )
string( REPLACE "github.com/" "${CMAIZE_GITHUB_SSH_PREFIX}:" _bd_url "${_bd_url}")
endif( )

# TODO: In the future, this might need to be generalized more to
# accommodate those who use multiple accounts with SSH keys
# associated with them. In these situations, the string
Expand All @@ -47,7 +51,7 @@ cpp_class(GitHubDependency Dependency)
# REGEX MATCH below should do this, but the `cmaize_sanitize_url`
# function also must be redesigned for these URLs to be allowed.
# string(REGEX MATCH "^git@[A-Za-z0-9_-]:" _bd_is_ssh "${_bd_url}")
string(FIND "${_bd_url}" "[email protected]:" _bd_is_ssh)
string(FIND "${_bd_url}" "${CMAIZE_GITHUB_SSH_PREFIX}:" _bd_is_ssh)

# Determine what type of URL to generate to access the repository
if(_bd_is_ssh GREATER -1)
Expand Down