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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4548ca444d7fc60b4f00896823b11b6385e43243
4
- data.tar.gz: 986bcbcc585dfda6dd70656bed1e005bf519ac77
3
+ metadata.gz: acd25bb5ca03b072bd4daae629aa86ef3c388f1a
4
+ data.tar.gz: ad0841368e3fd4f5052030a7bf2079b09f2a6f43
5
5
  SHA512:
6
- metadata.gz: 6d383ec8ef3ff7c0347e438650402e25db7141deb24e41de8b2684330ead5abd38d295a6784071d48a7a562ab9db7cff1e5544fbc446080da879783e907a4aee
7
- data.tar.gz: 701233c012f4b11ff74494b8de0ffca43682eafed2f799bb38344939a42f1914219d5358423181410db2d60913be625fc28f12d57af985f45f9029f85be92cd6
6
+ metadata.gz: 7439c37cda896fd81507ab88144fccf885abb2f63fe0372d8150c31b8c42291b2a1f764688d9f1051078c786bfb940166d974e4b5ff4051adb4de50dafa0f6c1
7
+ data.tar.gz: 85d4af79803f6b18b32e21ed624fb7a4957cc60c6621834194b7d46fe36529d1c52d04c8ac8be9561bc32e1aa9a1302af5f57c22138959dba60d35a171827579
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-lfs-s3 (0.0.1)
4
+ git-lfs-s3 (0.1.0)
5
5
  aws-sdk (~> 2)
6
6
  multi_json
7
7
  sinatra
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 the configuration variables must be set.
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 server inside of another application, such as Rails, 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.
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
@@ -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,
@@ -1,8 +1,8 @@
1
- require 'logger'
2
1
  require 'sinatra/base'
3
2
  require 'aws-sdk'
4
3
  require 'multi_json'
5
4
 
6
5
  require "git-lfs-s3/aws"
6
+ require "git-lfs-s3/authentication"
7
7
  require "git-lfs-s3/services/upload"
8
8
  require "git-lfs-s3/application"
@@ -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
- Dir.mkdir('logs') unless Dir.exists?('logs')
10
- $logger = Logger.new("logs/#{settings.environment}.log", "weekly")
11
- $logger.level = Logger::INFO
26
+ helpers do
27
+ def logger
28
+ settings.logger
29
+ end
12
30
  end
13
31
 
14
- configure :development do
15
- $logger.level = Logger::DEBUG
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
- helpers do
19
- def logger
20
- $logger
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
- # before do
25
- # raise headers['Accept'].inspect
26
- # if headers['Accept'] != 'application/vnd.git-lfs+json'
27
- # halt 406, {'Content-Type' => 'text/plain'}, 'Server only accepts application/vnd.git-lfs+json'
28
- # end
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
@@ -1,3 +1,3 @@
1
1
  module GitLfsS3
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-lfs-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan LeFevre