Blame SOURCES/0008-Issue-3657-Add-options-to-dsctl-for-dsrc-file.patch

3280a9
From 4faec52810e12070ef72da347bb590c57d8761e4 Mon Sep 17 00:00:00 2001
3280a9
From: Mark Reynolds <mreynolds@redhat.com>
3280a9
Date: Fri, 20 Nov 2020 17:47:18 -0500
3280a9
Subject: [PATCH 1/2] Issue 3657 - Add options to dsctl for dsrc file
3280a9
3280a9
Description:  Add options to create, modify, delete, and display
3280a9
              the .dsrc CLI tool shortcut file.
3280a9
3280a9
Relates: https://github.com/389ds/389-ds-base/issues/3657
3280a9
3280a9
Reviewed by: firstyear(Thanks!)
3280a9
---
3280a9
 dirsrvtests/tests/suites/clu/dsrc_test.py | 136 ++++++++++
3280a9
 src/lib389/cli/dsctl                      |   2 +
3280a9
 src/lib389/lib389/cli_ctl/dsrc.py         | 312 ++++++++++++++++++++++
3280a9
 3 files changed, 450 insertions(+)
3280a9
 create mode 100644 dirsrvtests/tests/suites/clu/dsrc_test.py
3280a9
 create mode 100644 src/lib389/lib389/cli_ctl/dsrc.py
3280a9
3280a9
diff --git a/dirsrvtests/tests/suites/clu/dsrc_test.py b/dirsrvtests/tests/suites/clu/dsrc_test.py
3280a9
new file mode 100644
3280a9
index 000000000..1b27700ec
3280a9
--- /dev/null
3280a9
+++ b/dirsrvtests/tests/suites/clu/dsrc_test.py
3280a9
@@ -0,0 +1,136 @@
3280a9
+import logging
3280a9
+import pytest
3280a9
+import os
3280a9
+from os.path import expanduser
3280a9
+from lib389.cli_base import FakeArgs
3280a9
+from lib389.cli_ctl.dsrc import create_dsrc, modify_dsrc, delete_dsrc, display_dsrc
3280a9
+from lib389._constants import DEFAULT_SUFFIX, DN_DM
3280a9
+from lib389.topologies import topology_st as topo
3280a9
+
3280a9
+log = logging.getLogger(__name__)
3280a9
+
3280a9
+
3280a9
+@pytest.fixture(scope="function")
3280a9
+def setup(topo, request):
3280a9
+    """Preserve any existing .dsrc file"""
3280a9
+
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+    backup_file = dsrc_file + ".original"
3280a9
+    if os.path.exists(dsrc_file):
3280a9
+        os.rename(dsrc_file, backup_file)
3280a9
+
3280a9
+    def fin():
3280a9
+        if os.path.exists(backup_file):
3280a9
+            os.rename(backup_file, dsrc_file)
3280a9
+
3280a9
+    request.addfinalizer(fin)
3280a9
+
3280a9
+
3280a9
+def test_dsrc(topo, setup):
3280a9
+    """Test "dsctl dsrc" command
3280a9
+
3280a9
+    :id: 0610de6c-e167-4761-bdab-3e677b2d44bb
3280a9
+    :setup: Standalone Instance
3280a9
+    :steps:
3280a9
+        1. Test creation works
3280a9
+        2. Test creating duplicate section
3280a9
+        3. Test adding an additional inst config works
3280a9
+        4. Test removing an instance works
3280a9
+        5. Test modify works
3280a9
+        6. Test delete works
3280a9
+        7. Test display fails when no file is present
3280a9
+
3280a9
+    :expectedresults:
3280a9
+        1. Success
3280a9
+        2. Success
3280a9
+        3. Success
3280a9
+        4. Success
3280a9
+        5. Success
3280a9
+        6. Success
3280a9
+        7. Success
3280a9
+    """
3280a9
+
3280a9
+    inst = topo.standalone
3280a9
+    serverid = inst.serverid
3280a9
+    second_inst_name = "Second"
3280a9
+    second_inst_basedn = "o=second"
3280a9
+    different_suffix = "o=different"
3280a9
+
3280a9
+    # Setup our args
3280a9
+    args = FakeArgs()
3280a9
+    args.basedn = DEFAULT_SUFFIX
3280a9
+    args.binddn = DN_DM
3280a9
+    args.json = None
3280a9
+    args.uri = None
3280a9
+    args.saslmech = None
3280a9
+    args.tls_cacertdir = None
3280a9
+    args.tls_cert = None
3280a9
+    args.tls_key = None
3280a9
+    args.tls_reqcert = None
3280a9
+    args.starttls = None
3280a9
+    args.cancel_starttls = None
3280a9
+    args.pwdfile = None
3280a9
+    args.do_it = True
3280a9
+
3280a9
+    # Create a dsrc configuration entry
3280a9
+    create_dsrc(inst, log, args)
3280a9
+    display_dsrc(inst, topo.logcap.log, args)
3280a9
+    assert topo.logcap.contains("basedn = " + args.basedn)
3280a9
+    assert topo.logcap.contains("binddn = " + args.binddn)
3280a9
+    assert topo.logcap.contains("[" + serverid + "]")
3280a9
+    topo.logcap.flush()
3280a9
+
3280a9
+    # Attempt to add duplicate instance section
3280a9
+    with pytest.raises(ValueError):
3280a9
+        create_dsrc(inst, log, args)
3280a9
+
3280a9
+    # Test adding a second instance works correctly
3280a9
+    inst.serverid = second_inst_name
3280a9
+    args.basedn = second_inst_basedn
3280a9
+    create_dsrc(inst, log, args)
3280a9
+    display_dsrc(inst, topo.logcap.log, args)
3280a9
+    assert topo.logcap.contains("basedn = " + args.basedn)
3280a9
+    assert topo.logcap.contains("[" + second_inst_name + "]")
3280a9
+    topo.logcap.flush()
3280a9
+
3280a9
+    # Delete second instance
3280a9
+    delete_dsrc(inst, log, args)
3280a9
+    inst.serverid = serverid  # Restore original instance name
3280a9
+    display_dsrc(inst, topo.logcap.log, args)
3280a9
+    assert not topo.logcap.contains("[" + second_inst_name + "]")
3280a9
+    assert not topo.logcap.contains("basedn = " + args.basedn)
3280a9
+    # Make sure first instance config is still present
3280a9
+    assert topo.logcap.contains("[" + serverid + "]")
3280a9
+    assert topo.logcap.contains("binddn = " + args.binddn)
3280a9
+    topo.logcap.flush()
3280a9
+
3280a9
+    # Modify the config
3280a9
+    args.basedn = different_suffix
3280a9
+    modify_dsrc(inst, log, args)
3280a9
+    display_dsrc(inst, topo.logcap.log, args)
3280a9
+    assert topo.logcap.contains(different_suffix)
3280a9
+    topo.logcap.flush()
3280a9
+
3280a9
+    # Remove an arg from the config
3280a9
+    args.basedn = ""
3280a9
+    modify_dsrc(inst, log, args)
3280a9
+    display_dsrc(inst, topo.logcap.log, args)
3280a9
+    assert not topo.logcap.contains(different_suffix)
3280a9
+    topo.logcap.flush()
3280a9
+
3280a9
+    # Remove the last entry, which should delete the file
3280a9
+    delete_dsrc(inst, log, args)
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+    assert not os.path.exists(dsrc_file)
3280a9
+
3280a9
+    # Make sure display fails
3280a9
+    with pytest.raises(ValueError):
3280a9
+        display_dsrc(inst, log, args)
3280a9
+
3280a9
+
3280a9
+if __name__ == '__main__':
3280a9
+    # Run isolated
3280a9
+    # -s for DEBUG mode
3280a9
+    CURRENT_FILE = os.path.realpath(__file__)
3280a9
+    pytest.main(["-s", CURRENT_FILE])
3280a9
+
3280a9
diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl
3280a9
index fe9bc10e9..69f069297 100755
3280a9
--- a/src/lib389/cli/dsctl
3280a9
+++ b/src/lib389/cli/dsctl
3280a9
@@ -23,6 +23,7 @@ from lib389.cli_ctl import tls as cli_tls
3280a9
 from lib389.cli_ctl import health as cli_health
3280a9
 from lib389.cli_ctl import nsstate as cli_nsstate
3280a9
 from lib389.cli_ctl import dbgen as cli_dbgen
3280a9
+from lib389.cli_ctl import dsrc as cli_dsrc
3280a9
 from lib389.cli_ctl.instance import instance_remove_all
3280a9
 from lib389.cli_base import (
3280a9
     disconnect_instance,
3280a9
@@ -61,6 +62,7 @@ cli_tls.create_parser(subparsers)
3280a9
 cli_health.create_parser(subparsers)
3280a9
 cli_nsstate.create_parser(subparsers)
3280a9
 cli_dbgen.create_parser(subparsers)
3280a9
+cli_dsrc.create_parser(subparsers)
3280a9
 
3280a9
 argcomplete.autocomplete(parser)
3280a9
 
3280a9
diff --git a/src/lib389/lib389/cli_ctl/dsrc.py b/src/lib389/lib389/cli_ctl/dsrc.py
3280a9
new file mode 100644
3280a9
index 000000000..e49c7f819
3280a9
--- /dev/null
3280a9
+++ b/src/lib389/lib389/cli_ctl/dsrc.py
3280a9
@@ -0,0 +1,312 @@
3280a9
+# --- BEGIN COPYRIGHT BLOCK ---
3280a9
+# Copyright (C) 2020 Red Hat, Inc.
3280a9
+# All rights reserved.
3280a9
+#
3280a9
+# License: GPL (version 3 or any later version).
3280a9
+# See LICENSE for details.
3280a9
+# --- END COPYRIGHT BLOCK ---
3280a9
+
3280a9
+import json
3280a9
+from os.path import expanduser
3280a9
+from os import path, remove
3280a9
+from ldapurl import isLDAPUrl
3280a9
+from ldap.dn import is_dn
3280a9
+import configparser
3280a9
+
3280a9
+
3280a9
+def create_dsrc(inst, log, args):
3280a9
+    """Create the .dsrc file
3280a9
+
3280a9
+    [instance]
3280a9
+    uri = ldaps://hostname:port
3280a9
+    basedn = dc=example,dc=com
3280a9
+    binddn = uid=user,....
3280a9
+    saslmech = [EXTERNAL|PLAIN]
3280a9
+    tls_cacertdir = /path/to/cacertdir
3280a9
+    tls_cert = /path/to/user.crt
3280a9
+    tls_key = /path/to/user.key
3280a9
+    tls_reqcert = [never, hard, allow]
3280a9
+    starttls = [true, false]
3280a9
+    pwdfile = /path/to/file
3280a9
+    """
3280a9
+
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+    config = configparser.ConfigParser()
3280a9
+    config.read(dsrc_file)
3280a9
+
3280a9
+    # Verify this section does not already exist
3280a9
+    instances = config.sections()
3280a9
+    if inst.serverid in instances:
3280a9
+        raise ValueError("There is already a configuration section for this instance!")
3280a9
+
3280a9
+    # Process and validate the args
3280a9
+    config[inst.serverid] = {}
3280a9
+
3280a9
+    if args.uri is not None:
3280a9
+        if not isLDAPUrl(args.uri):
3280a9
+            raise ValueError("The uri is not a valid LDAP URL!")
3280a9
+        if args.uri.startswith("ldapi"):
3280a9
+            # We must use EXTERNAL saslmech for LDAPI
3280a9
+            args.saslmech = "EXTERNAL"
3280a9
+        config[inst.serverid]['uri'] = args.uri
3280a9
+    if args.basedn is not None:
3280a9
+        if not is_dn(args.basedn):
3280a9
+            raise ValueError("The basedn is not a valid DN!")
3280a9
+        config[inst.serverid]['basedn'] = args.basedn
3280a9
+    if args.binddn is not None:
3280a9
+        if not is_dn(args.binddn):
3280a9
+            raise ValueError("The binddn is not a valid DN!")
3280a9
+        config[inst.serverid]['binddn'] = args.binddn
3280a9
+    if args.saslmech is not None:
3280a9
+        if args.saslmech not in ['EXTERNAL', 'PLAIN']:
3280a9
+            raise ValueError("The saslmech must be EXTERNAL or PLAIN!")
3280a9
+        config[inst.serverid]['saslmech'] = args.saslmech
3280a9
+    if args.tls_cacertdir is not None:
3280a9
+        if not path.exists(args.tls_cacertdir):
3280a9
+            raise ValueError('--tls-cacertdir directory does not exist!')
3280a9
+        config[inst.serverid]['tls_cacertdir'] = args.tls_cacertdir
3280a9
+    if args.tls_cert is not None:
3280a9
+        if not path.exists(args.tls_cert):
3280a9
+            raise ValueError('--tls-cert does not point to an existing file!')
3280a9
+        config[inst.serverid]['tls_cert'] = args.tls_cert
3280a9
+    if args.tls_key is not None:
3280a9
+        if not path.exists(args.tls_key):
3280a9
+            raise ValueError('--tls-key does not point to an existing file!')
3280a9
+        config[inst.serverid]['tls_key'] = args.tls_key
3280a9
+    if args.tls_reqcert is not None:
3280a9
+        if args.tls_reqcert not in ['never', 'hard', 'allow']:
3280a9
+            raise ValueError('--tls-reqcert value is invalid (must be either "never", "allow", or "hard")!')
3280a9
+        config[inst.serverid]['tls_reqcert'] = args.tls_reqcert
3280a9
+    if args.starttls:
3280a9
+         config[inst.serverid]['starttls'] = 'true'
3280a9
+    if args.pwdfile is not None:
3280a9
+        if not path.exists(args.pwdfile):
3280a9
+            raise ValueError('--pwdfile does not exist!')
3280a9
+        config[inst.serverid]['pwdfile'] = args.pwdfile
3280a9
+
3280a9
+    if len(config[inst.serverid]) == 0:
3280a9
+        # No args set
3280a9
+        raise ValueError("You must set at least one argument for the new dsrc file!")
3280a9
+
3280a9
+    # Print a preview of the config
3280a9
+    log.info(f'Updating "{dsrc_file}" with:\n')
3280a9
+    log.info(f'    [{inst.serverid}]')
3280a9
+    for k, v in config[inst.serverid].items():
3280a9
+        log.info(f'    {k} = {v}')
3280a9
+
3280a9
+    # Perform confirmation?
3280a9
+    if not args.do_it:
3280a9
+        while 1:
3280a9
+            val = input(f'\nUpdate "{dsrc_file}" ? [yes]: ').rstrip().lower()
3280a9
+            if val == '' or val == 'y' or val == 'yes':
3280a9
+                break
3280a9
+            if val == 'n' or val == 'no':
3280a9
+                return
3280a9
+
3280a9
+    # Now write the file
3280a9
+    with open(dsrc_file, 'w') as configfile:
3280a9
+        config.write(configfile)
3280a9
+
3280a9
+    log.info(f'Successfully updated: {dsrc_file}')
3280a9
+
3280a9
+
3280a9
+def modify_dsrc(inst, log, args):
3280a9
+    """Modify the instance config
3280a9
+    """
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+
3280a9
+    if path.exists(dsrc_file):
3280a9
+        config = configparser.ConfigParser()
3280a9
+        config.read(dsrc_file)
3280a9
+
3280a9
+        # Verify we have a section to modify
3280a9
+        instances = config.sections()
3280a9
+        if inst.serverid not in instances:
3280a9
+            raise ValueError("There is no configuration section for this instance to modify!")
3280a9
+
3280a9
+        # Process and validate the args
3280a9
+        if args.uri is not None:
3280a9
+            if not isLDAPUrl(args.uri):
3280a9
+                raise ValueError("The uri is not a valid LDAP URL!")
3280a9
+            if args.uri.startswith("ldapi"):
3280a9
+                # We must use EXTERNAL saslmech for LDAPI
3280a9
+                args.saslmech = "EXTERNAL"
3280a9
+            if args.uri == '':
3280a9
+                del config[inst.serverid]['uri']
3280a9
+            else:
3280a9
+                config[inst.serverid]['uri'] = args.uri
3280a9
+        if args.basedn is not None:
3280a9
+            if not is_dn(args.basedn):
3280a9
+                raise ValueError("The basedn is not a valid DN!")
3280a9
+            if args.basedn == '':
3280a9
+                del config[inst.serverid]['basedn']
3280a9
+            else:
3280a9
+                config[inst.serverid]['basedn'] = args.basedn
3280a9
+        if args.binddn is not None:
3280a9
+            if not is_dn(args.binddn):
3280a9
+                raise ValueError("The binddn is not a valid DN!")
3280a9
+            if args.binddn == '':
3280a9
+                del config[inst.serverid]['binddn']
3280a9
+            else:
3280a9
+                config[inst.serverid]['binddn'] = args.binddn
3280a9
+        if args.saslmech is not None:
3280a9
+            if args.saslmech not in ['EXTERNAL', 'PLAIN']:
3280a9
+                raise ValueError("The saslmech must be EXTERNAL or PLAIN!")
3280a9
+            if args.saslmech == '':
3280a9
+                del config[inst.serverid]['saslmech']
3280a9
+            else:
3280a9
+                config[inst.serverid]['saslmech'] = args.saslmech
3280a9
+        if args.tls_cacertdir is not None:
3280a9
+            if not path.exists(args.tls_cacertdir):
3280a9
+                raise ValueError('--tls-cacertdir directory does not exist!')
3280a9
+            if args.tls_cacertdir == '':
3280a9
+                del config[inst.serverid]['tls_cacertdir']
3280a9
+            else:
3280a9
+                config[inst.serverid]['tls_cacertdir'] = args.tls_cacertdir
3280a9
+        if args.tls_cert is not None:
3280a9
+            if not path.exists(args.tls_cert):
3280a9
+                raise ValueError('--tls-cert does not point to an existing file!')
3280a9
+            if args.tls_cert == '':
3280a9
+                del config[inst.serverid]['tls_cert']
3280a9
+            else:
3280a9
+                config[inst.serverid]['tls_cert'] = args.tls_cert
3280a9
+        if args.tls_key is not None:
3280a9
+            if not path.exists(args.tls_key):
3280a9
+                raise ValueError('--tls-key does not point to an existing file!')
3280a9
+            if args.tls_key == '':
3280a9
+                del config[inst.serverid]['tls_key']
3280a9
+            else:
3280a9
+                config[inst.serverid]['tls_key'] = args.tls_key
3280a9
+        if args.tls_reqcert is not None:
3280a9
+            if args.tls_reqcert not in ['never', 'hard', 'allow']:
3280a9
+                raise ValueError('--tls-reqcert value is invalid (must be either "never", "allow", or "hard")!')
3280a9
+            if args.tls_reqcert == '':
3280a9
+                del config[inst.serverid]['tls_reqcert']
3280a9
+            else:
3280a9
+                config[inst.serverid]['tls_reqcert'] = args.tls_reqcert
3280a9
+        if args.starttls:
3280a9
+             config[inst.serverid]['starttls'] = 'true'
3280a9
+        if args.cancel_starttls:
3280a9
+            config[inst.serverid]['starttls'] = 'false'
3280a9
+        if args.pwdfile is not None:
3280a9
+            if not path.exists(args.pwdfile):
3280a9
+                raise ValueError('--pwdfile does not exist!')
3280a9
+            if args.pwdfile == '':
3280a9
+                del config[inst.serverid]['pwdfile']
3280a9
+            else:
3280a9
+                config[inst.serverid]['pwdfile'] = args.pwdfile
3280a9
+
3280a9
+        # Okay now rewrite the file
3280a9
+        with open(dsrc_file, 'w') as configfile:
3280a9
+            config.write(configfile)
3280a9
+
3280a9
+        log.info(f'Successfully updated: {dsrc_file}')
3280a9
+    else:
3280a9
+        raise ValueError(f'There is no .dsrc file "{dsrc_file}" to update!')
3280a9
+
3280a9
+
3280a9
+def delete_dsrc(inst, log, args):
3280a9
+    """Delete the .dsrc file
3280a9
+    """
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+    if path.exists(dsrc_file):
3280a9
+        if not args.do_it:
3280a9
+            # Get confirmation
3280a9
+            while 1:
3280a9
+                val = input(f'\nAre you sure you want to remove this instances configuration ? [no]: ').rstrip().lower()
3280a9
+                if val == 'y' or val == 'yes':
3280a9
+                    break
3280a9
+                if val == '' or val == 'n' or val == 'no':
3280a9
+                    return
3280a9
+
3280a9
+        config = configparser.ConfigParser()
3280a9
+        config.read(dsrc_file)
3280a9
+        instances = config.sections()
3280a9
+        if inst.serverid not in instances:
3280a9
+            raise ValueError("The is no configuration for this instance")
3280a9
+
3280a9
+        # Update the config object
3280a9
+        del config[inst.serverid]
3280a9
+
3280a9
+        if len(config.sections()) == 0:
3280a9
+            # The file would be empty so just delete it
3280a9
+            try:
3280a9
+                remove(dsrc_file)
3280a9
+                log.info(f'Successfully removed: {dsrc_file}')
3280a9
+                return
3280a9
+            except OSError as e:
3280a9
+                raise ValueError(f'Failed to delete "{dsrc_file}",  error: {str(e)}')
3280a9
+        else:
3280a9
+            # write the updated config
3280a9
+            with open(dsrc_file, 'w') as configfile:
3280a9
+                config.write(configfile)
3280a9
+    else:
3280a9
+        raise ValueError(f'There is no .dsrc file "{dsrc_file}" to update!')
3280a9
+
3280a9
+    log.info(f'Successfully updated: {dsrc_file}')
3280a9
+
3280a9
+def display_dsrc(inst, log, args):
3280a9
+    """Display the contents of the ~/.dsrc file
3280a9
+    """
3280a9
+    dsrc_file = f'{expanduser("~")}/.dsrc'
3280a9
+
3280a9
+    if not path.exists(dsrc_file):
3280a9
+        raise ValueError(f'There is no dsrc file "{dsrc_file}" to display!')
3280a9
+
3280a9
+    config = configparser.ConfigParser()
3280a9
+    config.read(dsrc_file)
3280a9
+    instances = config.sections()
3280a9
+
3280a9
+    for inst_section in instances:
3280a9
+        if args.json:
3280a9
+            log.info(json.dumps({inst_section: dict(config[inst_section])}, indent=4))
3280a9
+        else:
3280a9
+            log.info(f'[{inst_section}]')
3280a9
+            for k, v in config[inst_section].items():
3280a9
+                log.info(f'{k} = {v}')
3280a9
+            log.info("")
3280a9
+
3280a9
+
3280a9
+def create_parser(subparsers):
3280a9
+    dsrc_parser = subparsers.add_parser('dsrc', help="Manage the .dsrc file")
3280a9
+    subcommands = dsrc_parser.add_subparsers(help="action")
3280a9
+
3280a9
+    # Create .dsrc file
3280a9
+    dsrc_create_parser = subcommands.add_parser('create', help='Generate the .dsrc file')
3280a9
+    dsrc_create_parser.set_defaults(func=create_dsrc)
3280a9
+    dsrc_create_parser.add_argument('--uri', help="The URI (LDAP URL) for the Directory Server instance.")
3280a9
+    dsrc_create_parser.add_argument('--basedn', help="The default database suffix.")
3280a9
+    dsrc_create_parser.add_argument('--binddn', help="The default Bind DN used or authentication.")
3280a9
+    dsrc_create_parser.add_argument('--saslmech', help="The SASL mechanism to use: PLAIN or EXTERNAL.")
3280a9
+    dsrc_create_parser.add_argument('--tls-cacertdir', help="The directory containing the Trusted Certificate Authority certificate.")
3280a9
+    dsrc_create_parser.add_argument('--tls-cert', help="The absolute file name to the server certificate.")
3280a9
+    dsrc_create_parser.add_argument('--tls-key', help="The absolute file name to the server certificate key.")
3280a9
+    dsrc_create_parser.add_argument('--tls-reqcert', help="Request certificate strength: 'never', 'allow', 'hard'")
3280a9
+    dsrc_create_parser.add_argument('--starttls', action='store_true', help="Use startTLS for connection to the server.")
3280a9
+    dsrc_create_parser.add_argument('--pwdfile', help="The absolute path to a file containing the Bind DN's password.")
3280a9
+    dsrc_create_parser.add_argument('--do-it', action='store_true', help="Create the file without any confirmation.")
3280a9
+
3280a9
+    dsrc_modify_parser = subcommands.add_parser('modify', help='Modify the .dsrc file')
3280a9
+    dsrc_modify_parser.set_defaults(func=modify_dsrc)
3280a9
+    dsrc_modify_parser.add_argument('--uri', nargs='?', const='', help="The URI (LDAP URL) for the Directory Server instance.")
3280a9
+    dsrc_modify_parser.add_argument('--basedn', nargs='?', const='', help="The default database suffix.")
3280a9
+    dsrc_modify_parser.add_argument('--binddn', nargs='?', const='', help="The default Bind DN used or authentication.")
3280a9
+    dsrc_modify_parser.add_argument('--saslmech', nargs='?', const='', help="The SASL mechanism to use: PLAIN or EXTERNAL.")
3280a9
+    dsrc_modify_parser.add_argument('--tls-cacertdir', nargs='?', const='', help="The directory containing the Trusted Certificate Authority certificate.")
3280a9
+    dsrc_modify_parser.add_argument('--tls-cert', nargs='?', const='', help="The absolute file name to the server certificate.")
3280a9
+    dsrc_modify_parser.add_argument('--tls-key', nargs='?', const='', help="The absolute file name to the server certificate key.")
3280a9
+    dsrc_modify_parser.add_argument('--tls-reqcert', nargs='?', const='', help="Request certificate strength: 'never', 'allow', 'hard'")
3280a9
+    dsrc_modify_parser.add_argument('--starttls', action='store_true', help="Use startTLS for connection to the server.")
3280a9
+    dsrc_modify_parser.add_argument('--cancel-starttls', action='store_true', help="Do not use startTLS for connection to the server.")
3280a9
+    dsrc_modify_parser.add_argument('--pwdfile', nargs='?', const='', help="The absolute path to a file containing the Bind DN's password.")
3280a9
+    dsrc_modify_parser.add_argument('--do-it', action='store_true', help="Update the file without any confirmation.")
3280a9
+
3280a9
+    # Delete the instance from the .dsrc file
3280a9
+    dsrc_delete_parser = subcommands.add_parser('delete', help='Delete instance configuration from the .dsrc file.')
3280a9
+    dsrc_delete_parser.set_defaults(func=delete_dsrc)
3280a9
+    dsrc_delete_parser.add_argument('--do-it', action='store_true',
3280a9
+                                    help="Delete this instance's configuration from the .dsrc file.")
3280a9
+
3280a9
+    # Display .dsrc file
3280a9
+    dsrc_display_parser = subcommands.add_parser('display', help='Display the contents of the .dsrc file.')
3280a9
+    dsrc_display_parser.set_defaults(func=display_dsrc)
3280a9
-- 
3280a9
2.26.2
3280a9