Module: GitWit
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/git_wit.rb,
lib/git_wit/cli.rb,
lib/git_wit/auth.rb,
lib/git_wit/engine.rb,
lib/git_wit/errors.rb,
lib/git_wit/actions.rb,
lib/git_wit/actions.rb,
lib/git_wit/version.rb,
lib/git_wit/commands/util.rb,
lib/git_wit/commands/debug.rb,
lib/git_wit/authorized_keys.rb,
lib/git_wit/commands/git_shell.rb,
lib/git_wit/authorized_keys/key.rb,
lib/git_wit/authorized_keys/file.rb,
app/controllers/git_wit/git_controller.rb,
app/controllers/git_wit/application_controller.rb,
lib/generators/git_wit/install/install_generator.rb,
lib/generators/git_wit/ssh_user/ssh_user_generator.rb
Defined Under Namespace
Modules: Actions, AuthorizedKeys, Commands Classes: ApplicationController, Cli, ConfigurationError, Engine, ForbiddenError, GitController, GitError, InstallGenerator, NotFoundError, SshUserGenerator, UnauthorizedError
Constant Summary collapse
- VERSION =
Public: Rubygems compatible version number String.
"0.0.6"
Class Method Summary collapse
-
.add_authorized_key(username, key) ⇒ Object
Public: Add a public key for a given username to the authorized_keys file.
- .authenticate(user, password) ⇒ Object
- .authorize(operation, user, repository) ⇒ Object
- .authorize_read(user, repository) ⇒ Object
- .authorize_write(user, repository) ⇒ Object
-
.authorized_keys_file ⇒ Object
Public: Get an authorized_keys file instance.
-
.authorized_keys_path ⇒ Object
Public: Determine the path to the authorized_keys file based on the configuration.
- .default_config! ⇒ Object
-
.regenerate_authorized_keys(keys_map) ⇒ Object
Public: Clear out all existing public keys in the authorized_keys file and add each public key for each user in the key map to the new file.
-
.remove_authorized_key(key) ⇒ Object
Public: Remove a public key from the authorized_keys file.
- .reset_config! ⇒ Object
- .restore_config ⇒ Object
- .stash_config ⇒ Object
- .user_for_authentication(username) ⇒ Object
Class Method Details
.add_authorized_key(username, key) ⇒ Object
Public: Add a public key for a given username to the authorized_keys file.
username - The String username for the public key owner. key - The String public key contents.
Returns nothing.
48 49 50 |
# File 'lib/git_wit/authorized_keys.rb', line 48 def self.(username, key) .add AuthorizedKeys::Key.shell_key_for_username(username, key) end |
.authenticate(user, password) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/git_wit/auth.rb', line 9 def self.authenticate(user, password) if config.authenticate.respond_to?(:call) return config.authenticate.call(user, password) end config.authenticate end |
.authorize(operation, user, repository) ⇒ Object
24 25 26 27 |
# File 'lib/git_wit/auth.rb', line 24 def self.(operation, user, repository) cfg = config.send "authorize_#{operation}".to_sym cfg.respond_to?(:call) ? cfg.call(user, repository) : cfg end |
.authorize_read(user, repository) ⇒ Object
20 21 22 |
# File 'lib/git_wit/auth.rb', line 20 def self.(user, repository) :read, user, repository end |
.authorize_write(user, repository) ⇒ Object
16 17 18 |
# File 'lib/git_wit/auth.rb', line 16 def self.(user, repository) :write, user, repository end |
.authorized_keys_file ⇒ Object
Public: Get an authorized_keys file instance.
Returns an AuthorizedKeys::File instance. Raises ConfigurationError if the path cannot be determined.
18 19 20 21 22 |
# File 'lib/git_wit/authorized_keys.rb', line 18 def self. path = return AuthorizedKeys::File.new path if path.present? raise ConfigurationError, "Could not determine path to authorized_keys file" end |
.authorized_keys_path ⇒ Object
Public: Determine the path to the authorized_keys file based on the configuration. If not explicitly configured, the ssh_user’s home directory is used to construct the path by adding “.ssh/authorized_keys”.
Returns the path as a String or nothing if it cannot be determined.
7 8 9 10 11 12 |
# File 'lib/git_wit/authorized_keys.rb', line 7 def self. return config. if config..present? if ssh_user.present? File.(File.join("~#{ssh_user}", ".ssh", "authorized_keys")) end end |
.default_config! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/git_wit.rb', line 31 def self.default_config! reset_config! configure do |config| config.realm = "GitWit" config.repositories_path = Rails.root.join("repositories").to_s config.ssh_user = nil config.git_path = "git" config.insecure_write = false config.insecure_auth = false config.authenticate = false config. = false config. = false config.username_attribute = :login config.email_attribute = :email config.name_attribute = :name end end |
.regenerate_authorized_keys(keys_map) ⇒ Object
Public: Clear out all existing public keys in the authorized_keys file and add each public key for each user in the key map to the new file.
keys_map - The Hash of String public key contents, keyed by String username.
Returns nothing.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/git_wit/authorized_keys.rb', line 30 def self.(keys_map) keys_file = keys_file.clear do |file| keys_map.each do |username, keys| keys.each do |key| keys_file.add AuthorizedKeys::Key.shell_key_for_username(username, key) end end end nil end |
.remove_authorized_key(key) ⇒ Object
Public: Remove a public key from the authorized_keys file.
key - The String public key contents.
Returns nothing.
57 58 59 |
# File 'lib/git_wit/authorized_keys.rb', line 57 def self.(key) .remove key end |
.reset_config! ⇒ Object
18 19 20 |
# File 'lib/git_wit.rb', line 18 def self.reset_config! @_config = nil end |
.restore_config ⇒ Object
26 27 28 29 |
# File 'lib/git_wit.rb', line 26 def self.restore_config @_config = @_stashed @_stashed = nil end |
.stash_config ⇒ Object
22 23 24 |
# File 'lib/git_wit.rb', line 22 def self.stash_config @_stashed = @_config.dup end |
.user_for_authentication(username) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/git_wit/auth.rb', line 2 def self.user_for_authentication(username) if config.user_for_authentication.respond_to?(:call) return config.user_for_authentication.call(username) end username end |