Class: Gitolite::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/gitolite/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gitolite_path, override_configuration = nil) ⇒ Manager

Returns a new instance of Manager.



27
28
29
30
31
32
# File 'lib/gitolite/manager.rb', line 27

def initialize(gitolite_path, override_configuration = nil)
  @repos, @user_groups, @commit_messages = [], [], []
  @gitolite_path = gitolite_path
  @configuration = override_configuration || Configuration.new
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
end

Instance Attribute Details

#commit_messagesObject

Returns the value of attribute commit_messages.



24
25
26
# File 'lib/gitolite/manager.rb', line 24

def commit_messages
  @commit_messages
end

#configurationObject

Returns the value of attribute configuration.



24
25
26
# File 'lib/gitolite/manager.rb', line 24

def configuration
  @configuration
end

#gitolite_pathObject (readonly)

Returns the value of attribute gitolite_path.



25
26
27
# File 'lib/gitolite/manager.rb', line 25

def gitolite_path
  @gitolite_path
end

#loggerObject

Returns the value of attribute logger.



24
25
26
# File 'lib/gitolite/manager.rb', line 24

def logger
  @logger
end

#reposObject

Returns the value of attribute repos.



24
25
26
# File 'lib/gitolite/manager.rb', line 24

def repos
  @repos
end

#user_groupsObject

Returns the value of attribute user_groups.



24
25
26
# File 'lib/gitolite/manager.rb', line 24

def user_groups
  @user_groups
end

Instance Method Details

#add_pub_key!(username, rsa_pub_key_name, rsa_pub_key) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gitolite/manager.rb', line 87

def add_pub_key!(username, rsa_pub_key_name, rsa_pub_key)
  file_name = "#{username}@#{rsa_pub_key_name}"
  key_path  = @configuration.user_key_path(file_name)

  if users_public_keys().include?(key_path)
    raise ::Gitolite::Duplicate, "Duplicate public key (#{rsa_pub_key_name}) for user (#{username})"
  end

  add_commit_file(key_path, rsa_pub_key, "Added RSA public key (#{file_name}) for user (#{username})")
  file_name
end

#create_user(username, rsa_pub_key, rsa_pub_key_name) ⇒ Object

this should be depracated



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gitolite/manager.rb', line 58

def create_user(username, rsa_pub_key, rsa_pub_key_name)
  key_name = "#{username}@#{rsa_pub_key_name}"
  key_path = @configuration.user_key_path(key_name)

  if users_public_keys().include?(key_path)
    raise ::Gitolite::Duplicate, "Public key (#{rsa_pub_key_name}) already exists for user (#{username}) on gitolite server"
  end

  add_commit_file(key_path,rsa_pub_key, "Added public key (#{rsa_pub_key_name}) for user (#{username}) ")

  key_path
end

#create_user_depracated(username, rsa_pub_key) ⇒ Object



71
72
73
# File 'lib/gitolite/manager.rb', line 71

def create_user_depracated(username, rsa_pub_key)
  create_user(username, rsa_pub_key, 'default')
end

#delete_repo(repo_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/gitolite/manager.rb', line 40

def delete_repo(repo_name)
  file_path = @configuration.repo_path(repo_name)
  remove_file(file_path, "Deleting repo (#{repo_name}) from gitolite.")

  bare_repo_path = @configuration.bare_repo_path(repo_name)
  if File.directory?(bare_repo_path)
    FileUtils.rm_rf bare_repo_path
  end
  repo_name
end

#delete_user(username) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/gitolite/manager.rb', line 75

def delete_user(username)
  key_path = @configuration.user_key_path(username)

  has_there_been_deletion = remove_public_keys_for_user!(username)

  unless has_there_been_deletion
    raise ::Gitolite::NotFound, "User (#{username}) not found on gitolite server"
  end

  username
end

#delete_user_group(group_name) ⇒ Object



133
134
135
136
137
# File 'lib/gitolite/manager.rb', line 133

def delete_user_group(group_name)
  path = @configuration.user_group_path(group_name)
  remove_file(path, "Remove user group (#{group_name}) from gitolite.")
  group_name
end

#delete_user_group!(group_name) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/gitolite/manager.rb', line 122

def delete_user_group!(group_name)
  group_path = @configuration.user_group_path(group_name)

  unless user_group_list.include?(group_path)
    raise ::Gitolite::NotFound, "User group (#{group_name}) not found on gitolite server"
  end

  remove_file(key_path, "Removing user group (#{group_name})")
  group_name
end

#list_reposObject



139
140
141
142
# File 'lib/gitolite/manager.rb', line 139

def list_repos()
  repo_names = repo_names_list()
  repo_names.map { |repo_name| { :repo_name => repo_name, :type => Repo.get_repo_type(repo_name) }}
end

#migrate_to_multiple_pub_keysObject

only to help with migration, to be deleted later TODO: Delete Depracated: To be removed



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/gitolite/manager.rb', line 158

def migrate_to_multiple_pub_keys()
  all_pub_keys = users_public_keys()
  base_path    = @configuration.keydir_path

  puts "Starting migration of PUB keys from old format to new! (This can take a while)"
  all_pub_keys.each do |pub_key_path|
    # skip git pub or already migrated key
    unless pub_key_path.match(/.*git.pub$/) || pub_key_path.include?('@')
      file_name = extract_file_name(pub_key_path,base_path,:pub)
      pub_content = gitolite_admin_repo().file_content(pub_key_path)

      # delete_user
      remove_file(pub_key_path, "Migrating user ('#{file_name}') to new annotation, temporary removing user")

      # create user
      create_user_depracated(file_name, pub_content)
    end
  end
  puts "End migration of pub keys"
  require 'pp'
  pp users_public_keys
  puts "--------------- END ---------------"
end

#open_group(group_name) ⇒ Object



51
52
53
54
55
# File 'lib/gitolite/manager.rb', line 51

def open_group(group_name)
  group_conf = UserGroup.new(group_name, @logger, @gitolite_path)
  @user_groups << group_conf
  group_conf
end

#open_repo(repo_name) ⇒ Object



34
35
36
37
38
# File 'lib/gitolite/manager.rb', line 34

def open_repo(repo_name)
  repo_conf = Repo.new(repo_name, @configuration, @logger, @gitolite_path)
  @repos << repo_conf
  repo_conf
end

#pushObject



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/gitolite/manager.rb', line 144

def push()
  changed_repos  = @repos.select { |repo| repo.any_changes? }
  changed_groups = @user_groups.select { |ug| ug.any_changes? }

  unless (@commit_messages.empty? && changed_repos.empty? && changed_groups.empty?)
    changed_repos.each  { |repo| repo.commit_changes }
    changed_groups.each { |ug|   ug.commit_changes   }

    gitolite_admin_repo().push()
  end
end

#remove_pub_key!(username, rsa_pub_key_name) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/gitolite/manager.rb', line 99

def remove_pub_key!(username, rsa_pub_key_name)
  file_name = "#{username}@#{rsa_pub_key_name}"
  key_path  = @configuration.user_key_path(file_name)

  unless users_public_keys().include?(key_path)
    raise ::Gitolite::NotFound, "Public key (#{rsa_pub_key_name}) for user (#{username}) not found"
  end

  remove_file(key_path, "Remove public key (#{rsa_pub_key_name}) for user (#{username})")
  true
end

#rename_pub_key!(old_username, new_username, rsa_pub_key_name, rsa_pub_key_value) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/gitolite/manager.rb', line 111

def rename_pub_key!(old_username, new_username, rsa_pub_key_name, rsa_pub_key_value)
  file_name     = "#{old_username}@#{rsa_pub_key_name}"
  new_file_name = "#{new_username}@#{rsa_pub_key_name}"

  key_path     = @configuration.user_key_path(file_name)
  new_key_path = @configuration.user_key_path(new_file_name)

  remove_file(key_path, "Rename public key (#{rsa_pub_key_name}) from old user (#{old_username}) to new (#{new_username}) - REMOVE")
  add_commit_file(new_key_path, rsa_pub_key_value, "Rename public key (#{rsa_pub_key_name}) from old user (#{old_username}) to new (#{new_username}) - ADD")
end