Sha256: 96d2d57b6af2535e81890ce617404199736f8371a7c1588363f9ba65efbc9307

Contents?: true

Size: 1.84 KB

Versions: 17

Compression:

Stored size: 1.84 KB

Contents

require 'json'
require 'puppetfactory'

class Puppetfactory::Plugins::Gitlab < Puppetfactory::Plugins

  def initialize(options)
    super(options)

    @suffix = options[:usersuffix]

    begin
      # Use default gitlab root password to get session token
      login  = {:login => 'root', :password => '5iveL!fe'}
      resp   = JSON.parse(RestClient.post('http://localhost:8888/api/v3/session', login))
      @token = resp['private_token']
    rescue => e
      raise "GitLab authentication error! (#{e.message})"
    end
  end

  def create(username, password)
    begin
      if password.length < 8
        raise "Password must be at least 8 characters"
      end

      RestClient.post('http://localhost:8888/api/v3/users',
                      {
                        :email         => "#{username}.#{@suffix}",
                        :password      => password,
                        :username      => username,
                        :name          => username,
                        :confirm       => false,
                        :private_token => @token        # TODO: this invocation does not look like the invocation below?
                      })
      end

      $logger.info "Created GitLab user #{username}."
    rescue => e
      $logger.error "Error creating GitLab user #{username}: #{e.message}"
      return false
    end

    true
  end

  def delete(username)
    begin
      users  = JSON.parse(RestClient.get('http://localhost:8888/api/v3/users', {"PRIVATE-TOKEN" => @token}))
      userid = users.select { |record| record['username'] == username }['id']
      RestClient.delete("http://localhost:8888/api/v3/users/#{userid}" , {"PRIVATE-TOKEN" => @token})

      $logger.info "Removed GitLab user #{username}."
    rescue => e
      $logger.error "Error removing GitLab user #{username}: #{e.message}"
      return false
    end

    true
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
puppetfactory-0.6.5 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.6.4 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.6.3 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.6.2 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.6.1 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.6.0 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.9 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.8 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.7 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.6 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.5 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.4 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.3 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.2 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.1 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.5.0 lib/puppetfactory/plugins/gitlab.rb
puppetfactory-0.4.0 lib/puppetfactory/plugins/gitlab.rb