Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
4b522b3d
Commit
4b522b3d
authored
Jul 19, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a ghetto api token generator
parent
37a15c11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
models.rb
lib/noah/models.rb
+1
-0
tokens.rb
lib/noah/models/tokens.rb
+41
-0
No files found.
lib/noah/models.rb
View file @
4b522b3d
...
@@ -129,3 +129,4 @@ require File.join(File.dirname(__FILE__), 'models','applications')
...
@@ -129,3 +129,4 @@ require File.join(File.dirname(__FILE__), 'models','applications')
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'configurations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'configurations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'watchers'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'watchers'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'ephemerals'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'ephemerals'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'models'
,
'tokens'
)
lib/noah/models/tokens.rb
0 → 100644
View file @
4b522b3d
module
Noah
class
Token
<
Model
include
Taggable
include
Linkable
attribute
:name
attribute
:token
attribute
:lifetime
index
:name
index
:token
index
:lifetime
before
:save
,
:generate_api_token
def
validate
super
assert_present
:name
assert_unique
:name
assert_unique
:token
end
def
to_hash
h
=
{
:token
=>
token
,
:lifetime
=>
lifetime
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
}
super
.
merge
(
h
)
end
protected
def
generate_api_token
# Wicked hot logic to generate an API token
random_string
=
(
0
...
50
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
self
.
token
.
nil?
?
self
.
token
=
OpenSSL
::
Digest
::
SHA256
.
hexdigest
(
random_string
<<
self
.
name
<<
Time
.
now
.
to_s
)
:
self
.
token
end
def
save_hook
# called after any create,update,delete
# logic needed to expire any orphaned ephemerals
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment