gollum-auth 0.1.1 → 0.1.2

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: 5db91789f3867f6d9e396ff5f39c8ce4204c4891
4
- data.tar.gz: b583804ff7ea81318a1c962f4d34c5110a4cc84c
3
+ metadata.gz: c48dfb142646b389d1c3f48b86669da0aefbb8a7
4
+ data.tar.gz: a1c0fad00212b93bea5c9f02da882f1328ab1814
5
5
  SHA512:
6
- metadata.gz: 0573f9e23ffc083b45050070cc228c08f29d5d679ee34f80872bfa783f024c254d417ebbb0198a48409c8ec40136fb5a007d534bf6ab284872628440df7a24ec
7
- data.tar.gz: 1a7c66737bd962cf6c6fc85ad7377debae626be910976b402f5047c7c76e4faefc42b0246083e341fbe6da9301136919722051ea3839692e85fa2a9807772262
6
+ metadata.gz: ad314b474affd015c15cd2f37d6abfeae2078f4cdd1226df18e91c731fff6ac9ae7488c68320ff1800f0362c4c10c82fd1515f84cfad2097cd57753ade246dbb
7
+ data.tar.gz: d5523c25c2c68d61f8496ad6970969add84a61e00b810abf6e1192493664ac7e56b1548394a86db6a1f9f15f34342d3d593817b51263862c6286f62e5c8c6621
data/gollum-auth.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_dependency 'rack', '~> 1.6'
25
+ spec.add_dependency 'activemodel', '~> 4.2'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.14'
27
28
  spec.add_development_dependency 'rake', '~> 10.0'
data/lib/gollum/auth.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rack'
2
+ require 'active_model'
2
3
  require 'gollum/auth/version'
4
+ require 'gollum/auth/user'
3
5
 
4
6
  module Gollum
5
7
  module Auth
@@ -10,7 +12,7 @@ module Gollum
10
12
  class App
11
13
  def initialize(app, opts = { })
12
14
  @app = app
13
- @users = opts.fetch(:users, [ ])
15
+ opts.fetch(:users, [ ]).map { |args| User.new(args).save! }
14
16
  end
15
17
 
16
18
  def call(env)
@@ -31,7 +33,13 @@ module Gollum
31
33
  private
32
34
 
33
35
  def valid?(credentials)
34
- @users.any? { |u| [ u['user'], u['password'] ] == credentials }
36
+ user, password = credentials
37
+ current_user = User.find(user)
38
+ current_user && current_user.valid_password?(password)
39
+ end
40
+
41
+ def users
42
+ User.all
35
43
  end
36
44
  end
37
45
  end
@@ -0,0 +1,40 @@
1
+ module Gollum::Auth
2
+ class InvalidUserError < StandardError
3
+ end
4
+
5
+ class User
6
+ include ActiveModel::Model
7
+
8
+ attr_accessor :user, :password
9
+
10
+ validates_presence_of :user, :password
11
+
12
+ class << self
13
+ def find(user)
14
+ all.select { |u| u.user == user }.first
15
+ end
16
+
17
+ def all
18
+ @all ||= []
19
+ end
20
+ end
21
+
22
+ def save!
23
+ save ? self : raise(InvalidUserError, error_message)
24
+ end
25
+
26
+ def save
27
+ (self.class.all << self; self) if valid?
28
+ end
29
+
30
+ def valid_password?(other)
31
+ password == other
32
+ end
33
+
34
+ private
35
+
36
+ def error_message
37
+ errors.full_messages.join(', ')
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  module Auth
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Albers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-12 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +114,7 @@ files:
100
114
  - bin/setup
101
115
  - gollum-auth.gemspec
102
116
  - lib/gollum/auth.rb
117
+ - lib/gollum/auth/user.rb
103
118
  - lib/gollum/auth/version.rb
104
119
  homepage: https://github.com/bjoernalbers/gollum-auth
105
120
  licenses:
@@ -124,5 +139,5 @@ rubyforge_project:
124
139
  rubygems_version: 2.6.10
125
140
  signing_key:
126
141
  specification_version: 4
127
- summary: gollum-auth-0.1.1
142
+ summary: gollum-auth-0.1.2
128
143
  test_files: []