jekyll-gitlab-letsencrypt 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb4bfb178c062a347cdd00659b5696634d8a62b6
4
- data.tar.gz: 3bd34da9de2d0bce437f056e954736d17bbdeedd
3
+ metadata.gz: 4aa19772ee6eb9fbc74b590baa566f4cfde43db9
4
+ data.tar.gz: 57f5f353d78eee5a174165adac509ef69ddb1a8a
5
5
  SHA512:
6
- metadata.gz: c79377df9752b99c20c192d450efe2a7e9485c809e13e42bd35df6553eb5dade98924ed85dc9d35fa5cea28ba9286b9d1997623dcb1efa126840d6bda98dd869
7
- data.tar.gz: 8e9039a3e65156d2139bc48c84c8b34886c3860221867c7f7ad6019f93960596e151c16928ebe6d9e806276fa505cbadf71e9cb3577bcf04f45988f4a2b5f6ae
6
+ metadata.gz: b0b7ca49d5056a76e89530cee2f40913660649054d15294871ffe2e02e80348082103366493630cac0d3236930d597c90017269b650647b5f7d8016e8539ce37
7
+ data.tar.gz: 124da27fd3bfee7347f7972b84d6112dbe9e86c22ae70eb770b5ae02fcbcd3ef57c7aaeef3f8477363c04e9aa00e493bbf2bc75424e24816d16d83538b6f3b96
@@ -1,3 +1,7 @@
1
+ # 0.2.0
2
+
3
+ - #8 - Fully automated! Use new gitlab API for the last step
4
+
1
5
  # 0.1.0
2
6
 
3
7
  - #6 - Added option to get secret gitlab token from env var
data/README.md CHANGED
@@ -4,15 +4,14 @@
4
4
 
5
5
  ![img](doc/image.png)
6
6
 
7
- This plugin automagically does 90% of the letsencrypt process for your gitlab-hosted jekyll blog.
7
+ This plugin automagically does the entire the letsencrypt process for your gitlab-hosted jekyll blog!
8
8
 
9
9
  - *(automatic)* It registers your email to the letsencrypt server
10
10
  - *(automatic)* It generates a challenge file, and commits it directly via the gitlab API
11
11
  - *(automatic)* It sleeps until the challenge file is live on the internet
12
12
  - *(automatic)* It asks letsencrypt to verify it
13
13
  - *(automatic)* It spits out the certificate chain and private key
14
- - *(manual)* You have to go to the URL provided and manually copy/paste them
15
- - This step must be manual since there is no API through Gitlab for this step
14
+ - *(automatic)* It updates the gitlab pages domain settings to use the certificate
16
15
 
17
16
  ## Usage
18
17
 
@@ -93,29 +92,8 @@ Requesting verification...
93
92
  Challenge status = valid
94
93
  Challenge is valid!
95
94
  Certificate retrieved!
96
- Go to https://gitlab.com/gitlab_user/gitlab_repo/pages
97
- - If you already have an existing entry for example.com, remove it
98
- - Then click + New Domain and enter the following:
99
-
100
- Domain: example.com
101
-
102
- Certificate (PEM):
103
- -----BEGIN CERTIFICATE-----
104
- ...
105
- -----END CERTIFICATE-----
106
- -----BEGIN CERTIFICATE-----
107
- ...
108
- -----END CERTIFICATE-----
109
-
110
- Key (PEM):
111
- -----BEGIN RSA PRIVATE KEY-----
112
- ...
113
- -----END RSA PRIVATE KEY-----
114
-
115
-
116
-
117
-
118
- ... hit save, wait a bit, and your new SSL will be live!
95
+ Updating domain example.com pages setting with new certificates..
96
+ Success!
119
97
  ```
120
98
 
121
99
  ### Alternative token usage
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "coveralls"
25
25
 
26
26
  spec.add_dependency "activesupport", ">= 3.0.0"
27
- spec.add_dependency "acme-client", "~> 0.5.0"
27
+ spec.add_dependency "acme-client", "~> 0.6"
28
28
  end
@@ -5,7 +5,7 @@ require 'jekyll/gitlab/letsencrypt/version'
5
5
  require 'jekyll/gitlab/letsencrypt/configuration'
6
6
  require 'jekyll/gitlab/letsencrypt/acme'
7
7
  require 'jekyll/gitlab/letsencrypt/process'
8
- require 'jekyll/gitlab/letsencrypt/committer'
8
+ require 'jekyll/gitlab/letsencrypt/gitlab_client'
9
9
 
10
10
  module Jekyll
11
11
  module Gitlab
@@ -3,21 +3,30 @@ require 'faraday'
3
3
  module Jekyll
4
4
  module Gitlab
5
5
  module Letsencrypt
6
- class Commiter
6
+ class GitlabClient
7
7
 
8
8
  attr_accessor :content
9
9
 
10
- delegate :filename, :personal_access_token, :gitlab_repo, :branch, to: Configuration
10
+ delegate :filename, :personal_access_token, :gitlab_repo, :branch, :domain, to: Configuration
11
11
 
12
- def initialize(content)
12
+ def commit!(content)
13
13
  @content = content
14
- end
15
-
16
- def commit!
17
14
  create_branch! unless branch_exists?
18
15
  commit_file!
19
16
  end
20
17
 
18
+ def update_certificate!(certificate, key)
19
+ Jekyll.logger.info "Updating domain #{domain} pages setting with new certificates.."
20
+ response = connection.put do |req|
21
+ req.url "projects/#{repo_id}/pages/domains/#{domain}"
22
+ req.body = {
23
+ certificate: certificate,
24
+ key: key
25
+ }.to_json
26
+ end
27
+ response.success?
28
+ end
29
+
21
30
  def create_branch!
22
31
  Jekyll.logger.info "Creating branch #{branch}.."
23
32
  connection.post do |req|
@@ -31,7 +40,7 @@ module Jekyll
31
40
 
32
41
  def commit_file!
33
42
  Jekyll.logger.info "Commiting challenge file as #{filename}"
34
- connection.run_request(request_method, nil, nil, nil) do |req|
43
+ connection.run_request(request_method_for_commit, nil, nil, nil) do |req|
35
44
  req.url "projects/#{repo_id}/repository/files"
36
45
  req.body = {
37
46
  file_path: filename,
@@ -50,7 +59,7 @@ module Jekyll
50
59
  JSON.parse(response.body).any? { |json| json['name'] == branch }
51
60
  end
52
61
 
53
- def request_method
62
+ def request_method_for_commit
54
63
  response = connection.get "projects/#{repo_id}/repository/files?ref=#{branch}&file_path=#{filename}"
55
64
  response.status == 404 ? :post : :put
56
65
  end
@@ -25,14 +25,19 @@ module Jekyll
25
25
  wait_until_challenge_is_present
26
26
  request_verification!
27
27
  await_verification_confirmation
28
- display_certificate
28
+ if update_gitlab_pages
29
+ Jekyll.logger.info "Success!"
30
+ else
31
+ Jekyll.logger.info "Updating certificate failed... manual steps:"
32
+ display_certificate
33
+ end
29
34
  end
30
35
 
31
36
  private
32
37
 
33
38
  def commit_to_gitlab!
34
39
  Jekyll.logger.info "Pushing file to Gitlab"
35
- Commiter.new(challenge_content).commit!
40
+ gitlab_client.commit!(challenge_content)
36
41
  end
37
42
 
38
43
  def wait_until_challenge_is_present
@@ -54,6 +59,9 @@ module Jekyll
54
59
  def request_verification!
55
60
  Jekyll.logger.info "Requesting verification..."
56
61
  challenge.request_verification
62
+ rescue ::Acme::Client::Error::BadNonce
63
+ Jekyll.logger.info "bad nonce! trying again.."
64
+ challenge.request_verification
57
65
  end
58
66
 
59
67
  def await_verification_confirmation
@@ -70,6 +78,10 @@ module Jekyll
70
78
  end
71
79
  end
72
80
 
81
+ def update_gitlab_pages
82
+ gitlab_client.update_certificate! certificate.fullchain_to_pem, certificate.request.private_key.to_pem
83
+ end
84
+
73
85
  def display_certificate
74
86
  Jekyll.logger.info "Certifcate retrieved!"
75
87
  Jekyll.logger.info "Go to https://gitlab.com/#{gitlab_repo}/pages"
@@ -114,6 +126,10 @@ module Jekyll
114
126
  end
115
127
  end
116
128
 
129
+ def gitlab_client
130
+ @gitlab_client ||= GitlabClient.new
131
+ end
132
+
117
133
  def challenge
118
134
  @challenge ||= client.challenge
119
135
  end
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Gitlab
3
3
  module Letsencrypt
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gitlab-letsencrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Aiken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-28 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.5.0
117
+ version: '0.6'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.5.0
124
+ version: '0.6'
125
125
  description: Automate letsencrypt renewals for gitlab pages.
126
126
  email:
127
127
  - 60tonangel@gmail.com
@@ -142,8 +142,8 @@ files:
142
142
  - lib/jekyll/commands/gitlab/letsencrypt.rb
143
143
  - lib/jekyll/gitlab/letsencrypt.rb
144
144
  - lib/jekyll/gitlab/letsencrypt/acme.rb
145
- - lib/jekyll/gitlab/letsencrypt/committer.rb
146
145
  - lib/jekyll/gitlab/letsencrypt/configuration.rb
146
+ - lib/jekyll/gitlab/letsencrypt/gitlab_client.rb
147
147
  - lib/jekyll/gitlab/letsencrypt/process.rb
148
148
  - lib/jekyll/gitlab/letsencrypt/version.rb
149
149
  homepage: https://github.com/JustinAiken/jekyll-gitlab-letsencrypt