hobgoblin 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/hobgoblin +9 -0
- data/hobgoblin.gemspec +27 -0
- data/lib/hobgoblin.rb +5 -0
- data/lib/hobgoblin/cli.rb +33 -0
- data/lib/hobgoblin/cli/download.rb +18 -0
- data/lib/hobgoblin/cli/upload.rb +18 -0
- data/lib/hobgoblin/client.rb +82 -0
- data/lib/hobgoblin/version.rb +5 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 976adf1d9f465a3f4b88a788662241cfa994255b
|
4
|
+
data.tar.gz: adb38b4858aa390ba7436d605339ac300e38726f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f591de40ddf7a0ebd8bb6ae451574a77940c1073c5eb8f0b769ea0283edeead15469e96b2234f14806feffb07e17b6a3f63bf2540737b4034463c5683978737
|
7
|
+
data.tar.gz: 6e27b642536ed31a1bda6e4449b2dd3160bb73e07a3b2f2d88f94fe09d5204a6b782e9af59d732884a64d7b0681e169b8fc44d3018a6023e4206507d7c0b251f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Hobgoblin
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hobgoblin`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hobgoblin'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hobgoblin
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Andre Medeiros/hobgoblin.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hobgoblin"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/hobgoblin
ADDED
data/hobgoblin.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hobgoblin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'hobgoblin'
|
8
|
+
spec.version = Hobgoblin::VERSION
|
9
|
+
spec.authors = ['Andre Medeiros']
|
10
|
+
spec.email = ['andre.medeiros@shopify.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Hobgoblin is a client that talks to the Bridge Troll service}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/Shopify/hobgoblin'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'signpost-signer', '~> 0.1.4'
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.4'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
|
+
end
|
data/lib/hobgoblin.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hobgoblin'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Hobgoblin
|
7
|
+
class CLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
class_option 'server', type: :string, desc: 'URL for the Bridge Troll server',
|
11
|
+
required: true
|
12
|
+
|
13
|
+
desc 'upload <SOURCE> <REMOTE_PATH>', 'Uploads a local file to the Bridge Troll bucket'
|
14
|
+
long_desc <<-DESC
|
15
|
+
Upload sends a local file to the remote Bridge Troll bucket with the path
|
16
|
+
specified by <REMOTE_PATH>.
|
17
|
+
DESC
|
18
|
+
def upload(source, remote_path)
|
19
|
+
require 'hobgoblin/cli/upload'
|
20
|
+
Upload.new(source, remote_path, options).run
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'download <REMOTE_SOURCE> <PATH>', 'Downloads a remote file from the Bridge Troll bucket'
|
24
|
+
long_desc <<-DESC
|
25
|
+
Download pulls a remote file to the remote Bridge Troll bucket with the path
|
26
|
+
specified by <REMOTE_SOURCE>.
|
27
|
+
DESC
|
28
|
+
def download(remote_source, path)
|
29
|
+
require 'hobgoblin/cli/download'
|
30
|
+
Download.new(remote_source, path, options).run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hobgoblin/client'
|
4
|
+
|
5
|
+
module Hobgoblin
|
6
|
+
class CLI::Download
|
7
|
+
def initialize(remote_source, path, options)
|
8
|
+
@remote_source = remote_source
|
9
|
+
@path = path
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
client = Hobgoblin::Client.new(@options)
|
15
|
+
client.download(@remote_source, @path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hobgoblin/client'
|
4
|
+
|
5
|
+
module Hobgoblin
|
6
|
+
class CLI::Upload
|
7
|
+
def initialize(source, remote_path, options)
|
8
|
+
@source = source
|
9
|
+
@remote_path = remote_path
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
client = Hobgoblin::Client.new(@options)
|
15
|
+
client.upload(@source, @remote_path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'signpost/signer'
|
5
|
+
|
6
|
+
module Hobgoblin
|
7
|
+
class Client
|
8
|
+
ClientError = Class.new(StandardError)
|
9
|
+
UploadForbiddenError = Class.new(ClientError)
|
10
|
+
FileNotFoundError = Class.new(ClientError)
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def download(remote_source, path)
|
17
|
+
remote_path = "/#{remote_source}" unless remote_source[0] == '/'
|
18
|
+
uri = URI.parse("#{@options['server']}#{remote_source}")
|
19
|
+
|
20
|
+
req = Net::HTTP::Get.new(uri)
|
21
|
+
Signpost::Signer.sign_request(req)
|
22
|
+
|
23
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 10) do |http|
|
24
|
+
http.request(req)
|
25
|
+
end
|
26
|
+
|
27
|
+
case res
|
28
|
+
when Net::HTTPRedirection
|
29
|
+
location_uri = URI.parse(res['Location'])
|
30
|
+
location_req = Net::HTTP::Get.new(location_uri)
|
31
|
+
|
32
|
+
rsp = Net::HTTP.start(location_uri.host, location_uri.port, use_ssl: true, read_timeout: 10) do |http|
|
33
|
+
http.request(location_req)
|
34
|
+
end
|
35
|
+
|
36
|
+
File.binwrite(path, rsp.body.force_encoding('UTF-8'))
|
37
|
+
File.chmod(0755, path)
|
38
|
+
puts <<-STR
|
39
|
+
= Downloaded:
|
40
|
+
Source: #{remote_source}
|
41
|
+
Destination: #{path}
|
42
|
+
STR
|
43
|
+
else
|
44
|
+
raise "#{res.code} #{res.message}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def upload(source, remote_path)
|
49
|
+
extended_source_path = File.expand_path(source)
|
50
|
+
raise FileNotFoundError unless File.exist?(extended_source_path)
|
51
|
+
|
52
|
+
remote_path = "/#{remote_path}" unless remote_path[0] == '/'
|
53
|
+
uri = URI.parse("#{@options['server']}#{remote_path}")
|
54
|
+
|
55
|
+
headers = {
|
56
|
+
'Host' => uri.host,
|
57
|
+
'User-Agent' => "Hobgoblin/#{Hobgoblin::VERSION}"
|
58
|
+
}
|
59
|
+
|
60
|
+
req = Net::HTTP::Post.new(uri)
|
61
|
+
req.body = File.binread(extended_source_path)
|
62
|
+
req.content_type = 'multipart/form-data'
|
63
|
+
req.initialize_http_header(headers)
|
64
|
+
Signpost::Signer.sign_request(req)
|
65
|
+
|
66
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
67
|
+
http.request(req)
|
68
|
+
end
|
69
|
+
|
70
|
+
if res.code == '401'
|
71
|
+
puts 'You are not authorized to upload assets'
|
72
|
+
exit 1
|
73
|
+
else
|
74
|
+
puts <<-STR
|
75
|
+
= Uploaded:
|
76
|
+
Source: #{extended_source_path}
|
77
|
+
Destination: #{uri.to_s}
|
78
|
+
STR
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobgoblin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andre Medeiros
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: signpost-signer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.19.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.19.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description: Hobgoblin is a client that talks to the Bridge Troll service
|
84
|
+
email:
|
85
|
+
- andre.medeiros@shopify.com
|
86
|
+
executables:
|
87
|
+
- hobgoblin
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- exe/hobgoblin
|
99
|
+
- hobgoblin.gemspec
|
100
|
+
- lib/hobgoblin.rb
|
101
|
+
- lib/hobgoblin/cli.rb
|
102
|
+
- lib/hobgoblin/cli/download.rb
|
103
|
+
- lib/hobgoblin/cli/upload.rb
|
104
|
+
- lib/hobgoblin/client.rb
|
105
|
+
- lib/hobgoblin/version.rb
|
106
|
+
homepage: https://github.com/Shopify/hobgoblin
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.6.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Hobgoblin is a client that talks to the Bridge Troll service
|
129
|
+
test_files: []
|