krb 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/exe/krb +2 -0
- data/lib/krb/application_service.rb +24 -19
- data/lib/krb/download/base.rb +8 -1
- data/lib/krb/import/base.rb +8 -1
- data/lib/krb/setup/apply_admin_credentials.rb +36 -0
- data/lib/krb/setup/apply_production_namespace.rb +20 -0
- data/lib/krb/setup/update.rb +20 -0
- data/lib/krb/version.rb +1 -1
- data/lib/krb/webhooks/base.rb +60 -0
- data/lib/krb/webhooks/reset.rb +30 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16db5a121841d07289f437da043c705b62c22f19db2a7503afae4c766725a1c0
|
4
|
+
data.tar.gz: 9beacfeba66d2accc9815101adaa319b89cea0c98607994b8d5ea63de586e0f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 724899b75a0c9907673b7abbbc0b08a3cdc9ed6e5da1a4ec759299a75f2f057a337cf6631d2c5e635fb2ed011ce3d15a28cf3245e18577ce59708c78e9721ba5
|
7
|
+
data.tar.gz: 89a6a067fedc3400f786310f4f2e4d5db2ae58d2c163da3db3ce8410d14a3f6d5546c8ff443714fb8a7677fba924d3e5dac5d71ed904ffbcf3304351a95cc008
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/exe/krb
CHANGED
@@ -21,13 +21,21 @@ module Krb
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def verify_setup
|
24
|
-
return if
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
return if base_setup?
|
25
|
+
::Krb::Setup::Base.process
|
26
|
+
remove_instance_variable(:@setup)
|
27
|
+
end
|
28
|
+
|
29
|
+
def verify_production
|
30
|
+
return if production_setup?
|
31
|
+
::Krb::Setup::ApplyProductionNamespace.process
|
32
|
+
remove_instance_variable(:@setup)
|
33
|
+
end
|
34
|
+
|
35
|
+
def verify_admin
|
36
|
+
return if admin_setup?
|
37
|
+
::Krb::Setup::ApplyAdminCredentials.process
|
38
|
+
remove_instance_variable(:@setup)
|
31
39
|
end
|
32
40
|
|
33
41
|
protected
|
@@ -35,7 +43,7 @@ module Krb
|
|
35
43
|
def setup
|
36
44
|
@setup ||= begin
|
37
45
|
if File.exist?(setup_file_path)
|
38
|
-
|
46
|
+
JSON.parse(File.open(setup_file_path).read)
|
39
47
|
else
|
40
48
|
{}
|
41
49
|
end
|
@@ -44,21 +52,18 @@ module Krb
|
|
44
52
|
|
45
53
|
private
|
46
54
|
|
47
|
-
def
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def config_file_path
|
52
|
-
[Dir.pwd, '.krb'].join('/')
|
55
|
+
def base_setup?
|
56
|
+
setup && !setup.dig('access_key').nil?
|
53
57
|
end
|
54
58
|
|
55
|
-
def
|
56
|
-
|
59
|
+
def production_setup?
|
60
|
+
setup && !setup.dig('production_namespace').nil?
|
57
61
|
end
|
58
62
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
63
|
+
def admin_setup?
|
64
|
+
setup &&
|
65
|
+
!setup.dig('admin_api_key').nil? &&
|
66
|
+
!setup.dig('admin_password').nil?
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
data/lib/krb/download/base.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tty/command'
|
4
|
+
|
3
5
|
module Krb
|
4
6
|
module Download
|
5
7
|
# Download methods
|
@@ -7,10 +9,15 @@ module Krb
|
|
7
9
|
def initialize
|
8
10
|
super
|
9
11
|
verify_setup
|
12
|
+
verify_production
|
13
|
+
@cmd = ::TTY::Command.new
|
10
14
|
end
|
11
15
|
|
12
16
|
def process
|
13
|
-
'
|
17
|
+
@cmd.run('rm -rf ./content')
|
18
|
+
@cmd.run("wget -q https://#{setup.dig('production_namespace')}.ngx.host/download -O ./content.zip")
|
19
|
+
@cmd.run("unzip -q ./content.zip -d ./content")
|
20
|
+
@cmd.run("rm -rf ./content/lost+found content.zip")
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
data/lib/krb/import/base.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tty/command'
|
4
|
+
|
3
5
|
module Krb
|
4
6
|
module Import
|
5
7
|
# Import methods
|
@@ -7,10 +9,15 @@ module Krb
|
|
7
9
|
def initialize
|
8
10
|
super
|
9
11
|
verify_setup
|
12
|
+
verify_production
|
13
|
+
@cmd = ::TTY::Command.new
|
10
14
|
end
|
11
15
|
|
12
16
|
def process
|
13
|
-
'
|
17
|
+
@cmd.run('rm -rf ./content')
|
18
|
+
@cmd.run("wget https://#{setup.dig('production_namespace')}.ngx.host/download -O ./content.zip")
|
19
|
+
@cmd.run("unzip ./content.zip -d ./content")
|
20
|
+
@cmd.run("rm -rf ./content/lost+found content.zip")
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'tty/prompt'
|
5
|
+
|
6
|
+
module Krb
|
7
|
+
module Setup
|
8
|
+
# Sets up configuration
|
9
|
+
class ApplyAdminCredentials < ApplicationService
|
10
|
+
def process
|
11
|
+
ask_api_key
|
12
|
+
ask_password
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def ask_password
|
18
|
+
input = prompt.mask(ask_password_phrase) { |q| q.required true }
|
19
|
+
::Krb::Setup::Update.process('admin_password' => input)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ask_password_phrase
|
23
|
+
'Please enter your shopify admin password key : '
|
24
|
+
end
|
25
|
+
|
26
|
+
def ask_api_key
|
27
|
+
input = prompt.mask(ask_api_key_phrase) { |q| q.required true }
|
28
|
+
::Krb::Setup::Update.process('admin_api_key' => input)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask_api_key_phrase
|
32
|
+
'Please enter your shopify admin api key : '
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'tty/prompt'
|
5
|
+
|
6
|
+
module Krb
|
7
|
+
module Setup
|
8
|
+
# Sets up configuration
|
9
|
+
class ApplyProductionNamespace < ApplicationService
|
10
|
+
def process
|
11
|
+
input = prompt.ask(ask_phrase) { |q| q.required true }
|
12
|
+
::Krb::Setup::Update.process('production_namespace' => input)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ask_phrase
|
16
|
+
'Please enter your production namespace (*namespace*.ngx.host) : '
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty/prompt'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Krb
|
7
|
+
module Setup
|
8
|
+
# Sets up configuration
|
9
|
+
class Update < ApplicationService
|
10
|
+
def initialize(payload)
|
11
|
+
@payload = payload
|
12
|
+
end
|
13
|
+
|
14
|
+
def process
|
15
|
+
updated_setup = setup.merge(@payload)
|
16
|
+
File.open(setup_file_path, 'w+') { |f| f.write(updated_setup.to_json) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/krb/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Krb
|
6
|
+
module Webhooks
|
7
|
+
# Webhooks methods
|
8
|
+
class Base < ApplicationService
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
verify_setup
|
12
|
+
verify_production
|
13
|
+
verify_admin
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
::Krb::Webhooks::Reset.process
|
18
|
+
%w[create update delete].each do |meth|
|
19
|
+
HTTP.headers(headers).post(shopify_webhooks_url, body: body(meth).to_json)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def body(meth)
|
26
|
+
{
|
27
|
+
webhook: {
|
28
|
+
topic: "products/#{meth}",
|
29
|
+
address: "https://#{setup.dig('production_namespace')}.ngx.host/webhook",
|
30
|
+
format: :json,
|
31
|
+
fields: %w[handle id]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def shopify_webhooks_url
|
37
|
+
"https://#{setup.dig('shop_name')}.myshopify.com/admin/webhooks.json"
|
38
|
+
end
|
39
|
+
|
40
|
+
def shopify_webhooks_delete_url(id)
|
41
|
+
"https://#{setup.dig('shop_name')}.myshopify.com/admin/webhooks/#{id}.json"
|
42
|
+
end
|
43
|
+
|
44
|
+
def headers
|
45
|
+
{
|
46
|
+
'Content-Type' => 'application/json',
|
47
|
+
'Authorization' => "Basic #{basic_auth_token}"
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def basic_auth_token
|
52
|
+
Base64.strict_encode64(password)
|
53
|
+
end
|
54
|
+
|
55
|
+
def password
|
56
|
+
[setup.dig('admin_api_key'), setup.dig('admin_password')].join(':')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Krb
|
6
|
+
module Webhooks
|
7
|
+
# Webhooks methods
|
8
|
+
class Reset < Base
|
9
|
+
def process
|
10
|
+
webhooks_list.each do |webhook|
|
11
|
+
delete(webhook.dig('id'))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def delete(id)
|
18
|
+
HTTP.headers(headers).delete(shopify_webhooks_delete_url(id))
|
19
|
+
end
|
20
|
+
|
21
|
+
def webhooks_list
|
22
|
+
resp = HTTP.headers(headers).get(shopify_webhooks_url)
|
23
|
+
JSON
|
24
|
+
.parse(resp.to_s)
|
25
|
+
.dig('webhooks')
|
26
|
+
.select { |node| node.dig('topic').match(/products\//) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bbnnt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,11 +78,16 @@ files:
|
|
78
78
|
- lib/krb/application_service.rb
|
79
79
|
- lib/krb/download/base.rb
|
80
80
|
- lib/krb/import/base.rb
|
81
|
+
- lib/krb/setup/apply_admin_credentials.rb
|
82
|
+
- lib/krb/setup/apply_production_namespace.rb
|
81
83
|
- lib/krb/setup/ask_shopify_access_key.rb
|
82
84
|
- lib/krb/setup/ask_shopify_shop_name.rb
|
83
85
|
- lib/krb/setup/base.rb
|
84
86
|
- lib/krb/setup/git_ignore.rb
|
87
|
+
- lib/krb/setup/update.rb
|
85
88
|
- lib/krb/version.rb
|
89
|
+
- lib/krb/webhooks/base.rb
|
90
|
+
- lib/krb/webhooks/reset.rb
|
86
91
|
homepage: https://ngx.host
|
87
92
|
licenses:
|
88
93
|
- MIT
|