Sha256: ba26e4353e7a5c761f4c7f15ebd827e5e000a5c7d2e2e13b3b8277bfd775580a

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require 'conjur/command'

class Conjur::Command::LDAPSync < Conjur::Command
  desc 'LDAP sync management commands'
  command :'ldap-sync' do |cgrp|

    cgrp.desc 'Trigger a sync of users/groups from LDAP to Conjur'
    cgrp.command :now do |cmd|
      cmd.desc 'LDAP Sync profile to use (defined in UI)'
      cmd.default_value 'default'
      cmd.arg_name 'profile'
      cmd.flag ['p', 'profile']
  
      cmd.desc 'Print the actions that would be performed'
      cmd.default_value false
      cmd.switch ['dry-run']
  
      cmd.desc 'Output format of sync operation (text, yaml)'
      cmd.default_value 'text'
      cmd.arg_name 'format'
      cmd.flag ['f', 'format'], :must_match => ['text', 'yaml']
  
      cmd.action do |_ ,options, args|
        assert_empty args
        
        format = options[:format] == 'text' ? 'application/json' : 'text/yaml'

        # options[:'dry-run'] is nil when dry_run should be disabled (either --no-dry-run
        # or no option given at all). It is true when --dry-run is given.
        dry_run = options[:'dry-run']
        dry_run = false if dry_run.nil?

        $stderr.puts "Performing #{dry_run ? 'dry run ' : ''}LDAP sync"
  
        response = api.ldap_sync_now(options[:profile], format, dry_run)
  
        if options[:format] == 'text'
          puts "Messages:"
          response['events'].each do |event|
            puts [ event['timestamp'], event['severity'], event['message'] ].join("\t")
          end
          puts
          puts "Actions:"
          response['result']['actions'].each do |action|
            puts action
          end
        else
          puts response
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
conjur-cli-5.2.5 lib/conjur/command/ldapsync.rb
conjur-cli-5.2.4 lib/conjur/command/ldapsync.rb
conjur-cli-5.2.3 lib/conjur/command/ldapsync.rb
conjur-cli-5.2.1 lib/conjur/command/ldapsync.rb