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

add protocol option (ssh or https) in config/settings.yml #6

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
5 changes: 3 additions & 2 deletions example_app/github_repo_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def credentials_for_repo_uri(uri)
def shell_create_and_push_commit(repo_credentials, application_name)
private_key = repo_credentials["private_key"]
repo_name = repo_credentials["name"]
repo_ssh_url = repo_credentials["ssh_url"]
repo_url = repo_credentials["ssh"] ? repo_credentials["ssh_url"] : repo_credentials["uri"]
keys_dir = "/tmp/github_keys"
key_file_name = "#{keys_dir}/#{repo_name}.key"
git_ssh_script = "/tmp/#{repo_name}_ssh_script.sh"
Expand Down Expand Up @@ -87,7 +87,8 @@ def shell_create_and_push_commit(repo_credentials, application_name)
end

commands = [
"cd /tmp; GIT_SSH=#{git_ssh_script} git clone #{repo_ssh_url} 2>&1",
"cd /tmp; GIT_SSH=#{git_ssh_script} git clone #{repo_url} 2>&1",
"cd /tmp/#{repo_name} && git config user.email '#{application_name}' 2>&1",
"cd /tmp/#{repo_name} && git config user.name '#{application_name}' 2>&1",
"cd /tmp/#{repo_name} && git commit --allow-empty -m 'auto generated empty commit' 2>&1",
"cd /tmp/#{repo_name} && git log --pretty=format:\"%h%x09%ad%x09%s\" 2>&1",
Expand Down
1 change: 1 addition & 0 deletions service_broker/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ github:
# curl -u <your-github-username> -d '{"scopes": ["repo", "delete_repo"], "note": "CF Service Broker"}' https://api.github.com/authorizations
username: #<your-github-username>
access_token: #<token-value>
ssh: true
8 changes: 5 additions & 3 deletions service_broker/github_service_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class GithubUnreachableError < StandardError
class GithubError < StandardError
end

def initialize(login, access_token)
def initialize(login, access_token, ssh=true)
@login = login
@access_token = access_token
@ssh = ssh
end

def create_github_repo(name)
Expand Down Expand Up @@ -63,7 +64,8 @@ def create_github_deploy_key(options)
name: repo_name,
uri: repo_https_url(full_repo_name),
ssh_url: repo_ssh_url(full_repo_name),
private_key: key_pair.private_key
private_key: key_pair.private_key,
ssh: @ssh
}
end

Expand Down Expand Up @@ -122,7 +124,7 @@ def repo_ssh_url(full_repo_name)
end

def repo_https_url(full_repo_name)
"https://github.com/#{full_repo_name}"
"https://#{@login}:#{@access_token}@github.com/#{full_repo_name}"
end

def octokit_client
Expand Down
2 changes: 1 addition & 1 deletion service_broker/service_broker_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ def self.app_settings

def github_service
github_credentials = self.class.app_settings.fetch("github")
GithubServiceHelper.new(github_credentials.fetch("username"), github_credentials.fetch("access_token"))
GithubServiceHelper.new(github_credentials.fetch("username"), github_credentials.fetch("access_token"), github_credentials.fetch("ssh"))
end
end