Skip to content

Commit

Permalink
Merge pull request #14 from ahanselka/enable-custom-gitlab
Browse files Browse the repository at this point in the history
allow usage of a custom GitLab URL
  • Loading branch information
JustinAiken committed Mar 9, 2018
2 parents 8b60712 + 1754edc commit 5daaca9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2.1

- Add custom GitLab URL setting

# 0.2.0

- #8 - Fully automated! Use new gitlab API for the last step
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gitlab-letsencrypt:
delay_time: 15 # How long to wait between each check once it starts looking for the file

# Optional settings you probably don't need:
gitlab_url: 'https://someurl' # Set if you need to use a self-hosted GitLab instance
endpoint: 'https://somewhere' # if you're doing the ACME thing outside of letsencrypt
branch: 'master' # Defaults to master, but you can use a different branch
layout: 'null' # Layout to use for challenge file - defaults to null, but you can change if needed
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll/gitlab/letsencrypt/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Configuration
DEFAULT_INITIAL_DELAY = 120
DEFAULT_DELAY_TIME = 15
DEFAULT_SCHEME = 'http'
DEFAULT_GITLAB_URL = 'https://gitlab.com'

REQUIRED_KEYS = %w{gitlab_repo email domain}

Expand All @@ -25,6 +26,10 @@ def endpoint
jekyll_config['endpoint'] || DEFAULT_ENDPOINT
end

def gitlab_url
jekyll_config['gitlab_url'] || DEFAULT_GITLAB_URL
end

def gitlab_repo
jekyll_config['gitlab_repo']
end
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll/gitlab/letsencrypt/gitlab_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class GitlabClient

attr_accessor :content

delegate :filename, :personal_access_token, :gitlab_repo, :branch, :domain, to: Configuration
delegate :filename, :personal_access_token, :gitlab_url, :gitlab_repo, :branch, :domain, to: Configuration

def commit!(content)
@content = content
Expand Down Expand Up @@ -49,7 +49,7 @@ def commit_file!
content: content
}.to_json
end
Jekyll.logger.info "Done Commiting! Check https://gitlab.com/#{gitlab_repo}/commits/#{branch}"
Jekyll.logger.info "Done Commiting! Check #{gitlab_url}/#{gitlab_repo}/commits/#{branch}"
end

private
Expand All @@ -73,7 +73,7 @@ def repo_id
end

def connection
@connection ||= Faraday.new(url: 'https://gitlab.com/api/v3/') do |faraday|
@connection ||= Faraday.new(url: "#{gitlab_url}/api/v3/") do |faraday|
faraday.adapter Faraday.default_adapter
faraday.headers['Content-Type'] = 'application/json'
faraday.headers['PRIVATE-TOKEN'] = personal_access_token
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/gitlab/letsencrypt/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.process!
self.new(client).process!
end

delegate :base_path, :gitlab_repo, :pretty_url?, :layout, :domain, :initial_delay, :delay_time, :scheme, to: Configuration
delegate :base_path, :gitlab_url, :gitlab_repo, :pretty_url?, :layout, :domain, :initial_delay, :delay_time, :scheme, to: Configuration

def initialize(client)
@client = client
Expand Down Expand Up @@ -86,7 +86,7 @@ def update_gitlab_pages

def display_certificate
Jekyll.logger.info "Certifcate retrieved!"
Jekyll.logger.info "Go to https://gitlab.com/#{gitlab_repo}/pages"
Jekyll.logger.info "Go to #{gitlab_url}/#{gitlab_repo}/pages"
Jekyll.logger.info " - If you already have an existing entry for #{domain}, remove it"
Jekyll.logger.info " - Then click + New Domain and enter the following:"
Jekyll.logger.info ""
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/gitlab/letsencrypt/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Jekyll
module Gitlab
module Letsencrypt
VERSION = "0.2.0"
VERSION = "0.2.1"
end
end
end
12 changes: 12 additions & 0 deletions spec/lib/jekyll/gitlab/letsencrypt/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@
it { should eq 'https://foo/'}
end
end

describe '#gitlab_url' do
subject { described_class.gitlab_url }
context "with no gitlab_url" do
it { should eq 'https://gitlab.com'}
end

context "with an gitlab_url" do
let(:plugin_config) { {'gitlab_url' => "https://gitlab"} }
it { should eq 'https://gitlab'}
end
end
end
1 change: 1 addition & 0 deletions spec/lib/jekyll/gitlab/letsencrypt/gitlab_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

let(:filename) { 'test_file.html' }
let(:personal_access_token) { 'SECRET_TOKEN' }
let(:gitlab_url) { 'https://gitlab.com'}
let(:gitlab_repo) { 'gitlab_user/gitlab_repo' }
let(:branch) { 'test_branch' }
let(:domain) { 'example.com' }
Expand Down

0 comments on commit 5daaca9

Please sign in to comment.