Class: Puppetfactory::Plugins::Gitea
- Inherits:
-
Puppetfactory::Plugins
- Object
- Puppetfactory::Plugins
- Puppetfactory::Plugins::Gitea
- Defined in:
- lib/puppetfactory/plugins/gitea.rb
Instance Attribute Summary
Attributes inherited from Puppetfactory::Plugins
Instance Method Summary collapse
- #create(username, password) ⇒ Object
- #delete(username) ⇒ Object
-
#initialize(options) ⇒ Gitea
constructor
A new instance of Gitea.
Constructor Details
#initialize(options) ⇒ Gitea
Returns a new instance of Gitea.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppetfactory/plugins/gitea.rb', line 8 def initialize() super() @cache_dir = '/var/cache/puppetfactory/gitea' @lockfile = '/var/cache/puppetfactory/gitea.lock' @templatedir = [:templatedir] @suffix = [:usersuffix] @controlrepo = [:controlrepo] @reponame = File.basename(@controlrepo, '.git') @repopath = "#{@cache_dir}/#{@reponame}" @gitea_upstream = [:gitea_upstream] || "https://github.com/puppetlabs-education/#{@controlrepo}" @gitea_cmd = [:gitea_cmd] || '/home/git/go/bin/gitea' @admin_username = [:gitea_admin_username] || 'root' @admin_password = [:gitea_admin_password] || 'puppetlabs' @gitea_port = [:gitea_port] || '3000' @gitea_user = [:gitea_user] || 'git' @gitea_homedir = Dir.home(@gitea_user) # the rest of this method is for the big boys only return unless Process.euid == 0 # gitea will scream if the admin's .ssh directory doesn't exist FileUtils.mkdir_p(File.("~#{@admin_username}/.ssh")) migrate_repo! unless File.directory?(@repopath) end |
Instance Method Details
#create(username, password) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppetfactory/plugins/gitea.rb', line 35 def create(username, password) begin # since we're changing directories, none of this can be done concurrently; lock it all. # # TODO: consider forking worker processes so that CWD doesn't leak between threads. File.open(@lockfile, 'w') do |file| file.flock(File::LOCK_EX) make_user(username, password) $logger.debug "Created Gitea user #{username}." make_branch(username) $logger.debug "Created Gitea branch #{username}." add_collaborator(@admin_username, @reponame, username, 'write') $logger.info "Created Gitea collaborator #{username}." end rescue => e $logger.error "Error configuring Gitea for #{username}: #{e.}" $logger.error e.backtrace.join("\n") return false end true end |
#delete(username) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppetfactory/plugins/gitea.rb', line 59 def delete(username) begin remove_user(username) $logger.info "Removed Gitea user #{username}." rescue => e $logger.error "Error removing Gitea user #{username}: #{e.}" return false end true end |