git-lfs-s3 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -5
- data/bin/git-lfs-s3 +6 -0
- data/lib/git-lfs-s3.rb +1 -1
- data/lib/git-lfs-s3/application.rb +35 -15
- data/lib/git-lfs-s3/services/upload/upload_required.rb +0 -11
- data/lib/git-lfs-s3/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acd25bb5ca03b072bd4daae629aa86ef3c388f1a
|
4
|
+
data.tar.gz: ad0841368e3fd4f5052030a7bf2079b09f2a6f43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7439c37cda896fd81507ab88144fccf885abb2f63fe0372d8150c31b8c42291b2a1f764688d9f1051078c786bfb940166d974e4b5ff4051adb4de50dafa0f6c1
|
7
|
+
data.tar.gz: 85d4af79803f6b18b32e21ed624fb7a4957cc60c6621834194b7d46fe36529d1c52d04c8ac8be9561bc32e1aa9a1302af5f57c22138959dba60d35a171827579
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ A [Git LFS](https://git-lfs.github.com/) server that stores your large Git files
|
|
4
4
|
|
5
5
|
It works by generating a presigned URL that the Git LFS client can use to upload directly to S3. It also provides download URLs that allow Git clients to download directly from S3. No data is proxied through the Git LFS server.
|
6
6
|
|
7
|
-
**Note:** the current version does not implement any authentication yet, so use with caution. Authentication will be added soon.
|
8
|
-
|
9
7
|
## Installation
|
10
8
|
|
11
9
|
Git LFS S3 is available on RubyGems.
|
@@ -24,7 +22,7 @@ gem 'git-lfs-s3'
|
|
24
22
|
|
25
23
|
### Standalone
|
26
24
|
|
27
|
-
All configuration is done via environment variables. All of
|
25
|
+
All configuration is done via environment variables. All of these configuration variables must be set.
|
28
26
|
|
29
27
|
* `AWS_REGION` - the region where your S3 bucket is.
|
30
28
|
* `AWS_ACCESS_KEY_ID` - your AWS access key.
|
@@ -32,9 +30,29 @@ All configuration is done via environment variables. All of the configuration va
|
|
32
30
|
* `S3_BUCKET` - the bucket you wish to use for LFS storage. While not required, I recommend using a dedicated bucket for this.
|
33
31
|
* `LFS_SERVER_URL` - the URL where this server can be reached; needed to fetch download URLs.
|
34
32
|
|
33
|
+
You can (and should) also set authentication information. When you push for the first time from git, you will be prompted to enter a username and password when authentication is enabled. You can configure these with environment variables as well.
|
34
|
+
|
35
|
+
* `USERNAME` - the login username.
|
36
|
+
* `PASSWORD` - the login password.
|
37
|
+
|
35
38
|
### Bundled
|
36
39
|
|
37
|
-
If you are bundling the
|
40
|
+
If you are bundling the service inside of another application, such as Rails, or a different server of your choosing, you can set the configuration directly on `GitLfsS3::Application`. See [bin/git-lfs-s3](https://github.com/meltingice/git-lfs-s3/blob/master/bin/git-lfs-s3) for an example.
|
41
|
+
|
42
|
+
You can also hook the authentication into your own service this way. For example:
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
GitLfsS3::Application.on_authenticate do |username, password|
|
46
|
+
user = User.find(username: username)
|
47
|
+
user.verify_password(password)
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
The logger can be configured as well. This is especially handy if you want to hook it into your Rails logger:
|
52
|
+
|
53
|
+
``` ruby
|
54
|
+
GitLfsS3::Application.set :logger, Rails.logger
|
55
|
+
```
|
38
56
|
|
39
57
|
### Git Setup
|
40
58
|
|
@@ -63,5 +81,4 @@ mount GitLfsS3::Application => '/lfs'
|
|
63
81
|
|
64
82
|
## TODO
|
65
83
|
|
66
|
-
* Authentication
|
67
84
|
* Cloudfront support
|
data/bin/git-lfs-s3
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "rubygems"
|
4
|
+
require "logger"
|
4
5
|
require "git-lfs-s3"
|
5
6
|
|
6
7
|
GitLfsS3::Application.set :aws_region, ENV['AWS_REGION']
|
@@ -8,6 +9,11 @@ GitLfsS3::Application.set :aws_access_key_id, ENV['AWS_ACCESS_KEY_ID']
|
|
8
9
|
GitLfsS3::Application.set :aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY']
|
9
10
|
GitLfsS3::Application.set :s3_bucket, ENV['S3_BUCKET']
|
10
11
|
GitLfsS3::Application.set :server_url, ENV['LFS_SERVER_URL']
|
12
|
+
GitLfsS3::Application.set :logger, Logger.new(STDOUT)
|
13
|
+
|
14
|
+
GitLfsS3::Application.on_authenticate do |username, password|
|
15
|
+
username == ENV['USERNAME'] && password == ENV['PASSWORD']
|
16
|
+
end
|
11
17
|
|
12
18
|
Rack::Handler::WEBrick.run(
|
13
19
|
GitLfsS3::Application.new,
|
data/lib/git-lfs-s3.rb
CHANGED
@@ -2,31 +2,52 @@ module GitLfsS3
|
|
2
2
|
class Application < Sinatra::Application
|
3
3
|
include AwsHelpers
|
4
4
|
|
5
|
+
class << self
|
6
|
+
attr_reader :auth_callback
|
7
|
+
|
8
|
+
def on_authenticate(&block)
|
9
|
+
@auth_callback = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def authentication_enabled?
|
13
|
+
!auth_callback.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform_authentication(username, password)
|
17
|
+
auth_callback.call(username, password)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
5
21
|
configure do
|
6
22
|
disable :sessions
|
7
23
|
enable :logging
|
24
|
+
end
|
8
25
|
|
9
|
-
|
10
|
-
|
11
|
-
|
26
|
+
helpers do
|
27
|
+
def logger
|
28
|
+
settings.logger
|
29
|
+
end
|
12
30
|
end
|
13
31
|
|
14
|
-
|
15
|
-
|
32
|
+
def authorized?
|
33
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
34
|
+
@auth.provided? && @auth.basic? && @auth.credentials && self.class.auth_callback.call(
|
35
|
+
@auth.credentials[0], @auth.credentials[1]
|
36
|
+
)
|
16
37
|
end
|
17
38
|
|
18
|
-
|
19
|
-
|
20
|
-
|
39
|
+
def protected!
|
40
|
+
unless authorized?
|
41
|
+
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
|
42
|
+
throw(:halt, [401, "Invalid username or password"])
|
21
43
|
end
|
22
44
|
end
|
23
45
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# end
|
46
|
+
before { protected! }
|
47
|
+
|
48
|
+
get '/' do
|
49
|
+
"Git LFS S3 is online."
|
50
|
+
end
|
30
51
|
|
31
52
|
get "/objects/:oid", provides: 'application/vnd.git-lfs+json' do
|
32
53
|
object = object_data(params[:oid])
|
@@ -58,7 +79,6 @@ module GitLfsS3
|
|
58
79
|
logger.debug headers.inspect
|
59
80
|
service = UploadService.service_for(request.body)
|
60
81
|
logger.debug service.response
|
61
|
-
logger.debug service.to_curl
|
62
82
|
|
63
83
|
status service.status
|
64
84
|
body MultiJson.dump(service.response)
|
@@ -23,17 +23,6 @@ module GitLfsS3
|
|
23
23
|
202
|
24
24
|
end
|
25
25
|
|
26
|
-
def to_curl
|
27
|
-
curl = ["curl -XPUT"]
|
28
|
-
curl << "-T \"{{file}}\""
|
29
|
-
upload_headers.each do |k, v|
|
30
|
-
curl << "-H \"#{k}: #{v}\""
|
31
|
-
end
|
32
|
-
curl << upload_destination
|
33
|
-
|
34
|
-
curl.join(' ')
|
35
|
-
end
|
36
|
-
|
37
26
|
private
|
38
27
|
|
39
28
|
def upload_destination
|
data/lib/git-lfs-s3/version.rb
CHANGED