Module: PadSec
- Defined in:
- lib/pad_sec.rb,
lib/pad_sec/keys.rb,
lib/pad_sec/server.rb,
lib/pad_sec/version.rb,
lib/pad_sec/encryption.rb,
lib/pad_sec/config_file.rb
Defined Under Namespace
Modules: ConfigFile, Encryption
Constant Summary collapse
- VERSION =
Gem version
"0.2.0"
Class Method Summary collapse
-
.authenticate(username: nil, pwd: nil, token: nil) ⇒ Boolean
Authenticates a user.
-
.authenticated? ⇒ Boolean
Checks if user is authenticated.
-
.get_token ⇒ String, Void
Gets the current token.
- .key ⇒ Object
- .main(arg) ⇒ Object
-
.server_url ⇒ String
Gets the Padstone server url.
Class Method Details
.authenticate(username: nil, pwd: nil, token: nil) ⇒ Boolean
Note:
If a username and pwd are given, token is optional and vice-versa.
Authenticates a user
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pad_sec.rb', line 25 def self.authenticate(username: nil, pwd: nil, token: nil) if !token.nil? # A token is given authenticate_with_token(token: token) elsif !username.nil? && !pwd.nil? # A username and a password are given authenticate_with_username(username: username, pwd: pwd) elsif username.nil? && pwd.nil? && token.nil? # Nothing is given authenticate_from_file else # Incomplete params are given, such as only a password false end end |
.authenticated? ⇒ Boolean
Checks if user is authenticated.
45 46 47 |
# File 'lib/pad_sec.rb', line 45 def self.authenticated? authenticate end |
.get_token ⇒ String, Void
Gets the current token.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pad_sec.rb', line 53 def self.get_token token = nil config_file = PadSec::ConfigFile::path if PadUtils.file_exist?(config_file) config = PadUtils.json_file_to_hash(config_file) if !config[:token].nil? token = config[:token] end end token end |
.key ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/pad_sec/keys.rb', line 3 def self.key if ENV['PADSTONE'] == 'development' "dev_key" else "b528d946-e5b9-49d2-b165-24e77187e90a" end end |
.main(arg) ⇒ Object
9 10 11 |
# File 'lib/pad_sec.rb', line 9 def self.main(arg) puts "PadSec: #{arg}" end |
.server_url ⇒ String
Gets the Padstone server url.
Based on ‘ENV`, gets the Padstone server url.
8 9 10 11 12 13 14 |
# File 'lib/pad_sec/server.rb', line 8 def self.server_url if ENV['PADSTONE'] == 'development' "http://localhost:3000/services/v1" else "http://padstone.io/services/v1" end end |