Skip to content

Commit

Permalink
Issue 51051 - CLI fix consistency issues with confirmations
Browse files Browse the repository at this point in the history
Description:  The remove-all feature of dsctl uses different confirmation
              prompt than "dsctl remove".  To fix this the "countdown" style
              confirmation was moved to "remove_all", as "dsctl INST remove"
              already had an additional argument.

              Also cleaned up unused imports other various bugs found by my
              IDE.

relates: https://pagure.io/389-ds-base/issue/51050

Reviewed by: firstyear(Thanks!)
  • Loading branch information
mreynolds389 committed May 1, 2020
1 parent ae2a2a4 commit ba3a704
Show file tree
Hide file tree
Showing 37 changed files with 62 additions and 152 deletions.
10 changes: 5 additions & 5 deletions src/lib389/lib389/__init__.py
Expand Up @@ -1804,7 +1804,7 @@ def handle(self, dn, entry):
raise e
self.log.exception("Error: could not add entry %s", dn)

adder = LDIFAdder(input_file, self, cont)
LDIFAdder(input_file, self, cont)

def getDBStats(self, suffix, bename=''):
if bename:
Expand Down Expand Up @@ -2983,8 +2983,8 @@ def ldifs(self, use_json=False):

if use_json:
json_result = {'type': 'list', 'items': []}
for ldif in dirlist:
fullpath = ldifdir + "/" + ldif
for ldif_file in dirlist:
fullpath = ldifdir + "/" + ldif_file
ldif_date = os.path.getmtime(fullpath)
ldif_date = datetime.fromtimestamp(ldif_date).strftime('%Y-%m-%d %H:%M:%S')
ldif_size = subprocess.check_output(['du', '-sh', fullpath]).split()[0].decode('utf-8')
Expand All @@ -2993,10 +2993,10 @@ def ldifs(self, use_json=False):
# This is not a valid LDIF file
ldif_suffix = "Invalid LDIF"
if use_json:
json_item = [ldif, ldif_date, ldif_size, ldif_suffix]
json_item = [ldif_file, ldif_date, ldif_size, ldif_suffix]
json_result['items'].append(json_item)
else:
self.log.info('{} ({}), Created ({}), Size ({})'.format(ldif, ldif_suffix, ldif_date, ldif_size))
self.log.info('{} ({}), Created ({}), Size ({})'.format(ldif_file, ldif_suffix, ldif_date, ldif_size))

if use_json:
print(json.dumps(json_result))
Expand Down
7 changes: 3 additions & 4 deletions src/lib389/lib389/_entry.py
Expand Up @@ -568,12 +568,11 @@ def _parse_term(self, key, term):
return wdict

def _parse_bind_rules(self, subterm):

# First, determine if there are extraneous braces wrapping the term.
subterm = subterm.strip()
if subterm[0] == '(' and subterm[-1] == ')':
subterm = subterm[1:-1]
terms = subterm.split('and')
# terms = subterm.split('and')
"""
We could parse everything into nice structures, and then work with
them. Or we can just leave the bind rule alone, as a string. Let
Expand All @@ -588,7 +587,7 @@ def _parse_bind_rules(self, subterm):
def _parse_version_3_0(self, rawacipart, data):
# We have to do this because it's not the same as other term formats.
terms = []
bindrules = []
# bindrules = []
interms = rawacipart.split(';')
interms = [x.strip() for x in interms]
for iwork in interms:
Expand All @@ -615,7 +614,7 @@ def _parse_version_3_0(self, rawacipart, data):

def _parse_aci(self, rawaci):
aci = rawaci
depth = 0
# depth = 0
data = {
'rawaci': rawaci,
'allow_raw_bindrules': [],
Expand Down
1 change: 1 addition & 0 deletions src/lib389/lib389/_replication.py
Expand Up @@ -10,6 +10,7 @@
import datetime
import logging
import re
from lib389.utils import cmp

log = logging.getLogger(__name__)

Expand Down
3 changes: 0 additions & 3 deletions src/lib389/lib389/aci.py
Expand Up @@ -13,9 +13,6 @@

import ldap

from lib389._constants import *


# Helpers to detect common patterns in aci
def _aci_any_targetattr_ne(aci):
"""Returns True if any of the targetattr types is a != type"""
Expand Down
3 changes: 1 addition & 2 deletions src/lib389/lib389/agreement.py
Expand Up @@ -213,7 +213,6 @@ def get_agmt_status(self, binddn=None, bindpw=None, return_json=False):
:type bindpw: str
:returns: A status message about the replication agreement
"""
status = "Unknown"
con_maxcsn = "Unknown"
try:
agmt_maxcsn = self.get_agmt_maxcsn()
Expand Down Expand Up @@ -803,7 +802,7 @@ def setProperties(self, suffix=None, agmnt_dn=None, agmnt_entry=None,

# TODO
if suffix:
raise NotImplemented
raise NotImplementedError

# The caller provides a set of properties to set into a replica entry
if agmnt_entry:
Expand Down
1 change: 0 additions & 1 deletion src/lib389/lib389/cli_conf/config.py
Expand Up @@ -8,7 +8,6 @@

from lib389.config import Config
from lib389.cli_base import (
populate_attr_arguments,
_generic_get_entry,
_generic_get_attr,
_generic_add_attr,
Expand Down
2 changes: 1 addition & 1 deletion src/lib389/lib389/cli_conf/plugins/accountpolicy.py
Expand Up @@ -7,7 +7,7 @@
# --- END COPYRIGHT BLOCK ---

import ldap
from lib389.plugins import AccountPolicyPlugin, AccountPolicyConfigs, AccountPolicyConfig
from lib389.plugins import AccountPolicyPlugin, AccountPolicyConfig
from lib389.cli_conf import add_generic_plugin_parsers, generic_object_edit, generic_object_add

arg_to_attr = {
Expand Down
3 changes: 1 addition & 2 deletions src/lib389/lib389/cli_conf/plugins/attruniq.py
Expand Up @@ -9,8 +9,7 @@
import json
import ldap
from lib389.plugins import AttributeUniquenessPlugin, AttributeUniquenessPlugins
from lib389.cli_conf import (add_generic_plugin_parsers, generic_object_edit, generic_object_add,
generic_enable, generic_disable, generic_status)
from lib389.cli_conf import (generic_object_edit, generic_object_add)

arg_to_attr = {
'enabled': 'nsslapd-pluginenabled',
Expand Down
2 changes: 1 addition & 1 deletion src/lib389/lib389/cli_conf/plugins/memberof.py
Expand Up @@ -8,7 +8,7 @@
# --- END COPYRIGHT BLOCK ---

import ldap
from lib389.plugins import MemberOfPlugin, Plugins, MemberOfSharedConfig, MemberOfSharedConfigs
from lib389.plugins import MemberOfPlugin, MemberOfSharedConfig
from lib389.cli_conf import add_generic_plugin_parsers, generic_object_edit, generic_object_add

arg_to_attr = {
Expand Down
33 changes: 15 additions & 18 deletions src/lib389/lib389/cli_ctl/instance.py
@@ -1,5 +1,5 @@
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2019 Red Hat, Inc.
# Copyright (C) 2020 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
Expand All @@ -9,10 +9,7 @@
import os
import json
import time
import sys
from getpass import getpass
from lib389 import DirSrv
from lib389.tools import DirSrvTools
from lib389.instance.setup import SetupDs
from lib389.utils import get_instance_list
from lib389.instance.remove import remove_ds_instance
Expand Down Expand Up @@ -129,24 +126,31 @@ def instance_remove_all(log, args):

inst_names = get_instance_list()
if len(inst_names) > 0:
answer = input("Are you sure you want to remove all the Directory Server instances? Enter \"Yes\" to continue: ")
if answer != 'Yes':
print("Aborted removal of all instances")
return
log.info("""
About to remove all Directory Server instances!
If this is not what you want, press ctrl-c now ...
""")
for i in range(1, 6):
log.info('%s ...' % (6 - int(i)))
time.sleep(1)

# Do it!
list_inst = DirSrv(verbose=args.verbose)
insts = list_inst.list(all=True, serverid=inst_names[0])
no_problems = True
for inst in insts:
remove_inst = DirSrv(verbose=args.verbose)
remove_inst.allocate(inst)
try:
log.info("Removing instance: slapd-" + str(remove_inst.serverid))
remove_ds_instance(remove_inst)
except Exception as e:
log.fatal('Failed to remove all instances: ' + str(e))
sys.exit(1)
log.info('All instances have been successfully removed')
log.error(f'Failed to remove slapd-{remove_inst.serverid} - Error: {str(e)}')
no_problems = False
if no_problems:
log.info('All instances have been successfully removed')
else:
log.info('Some instances were not removed')
else:
print("No instances to remove")

Expand All @@ -157,13 +161,6 @@ def instance_remove(inst, log, args):
log.info("""Not removing: if you are sure, add --do-it""")
return True
else:
log.info("""
About to remove instance (%s)!
If this is not what you want, press ctrl-c now ...
""" % inst.serverid)
for i in range(1, 6):
log.info('%s ...' % (6 - int(i)))
time.sleep(1)
log.info('Removing instance ...')
try:
remove_ds_instance(inst)
Expand Down
6 changes: 0 additions & 6 deletions src/lib389/lib389/cli_idm/account.py
Expand Up @@ -9,13 +9,9 @@

import ldap
import math
import time
from datetime import datetime
import argparse

from lib389.idm.account import Account, Accounts, AccountState
from lib389.cli_base import (
_generic_get,
_generic_get_dn,
_generic_list,
_generic_delete,
Expand All @@ -24,8 +20,6 @@
_get_dn_arg,
_warn,
)
from lib389.utils import gentime_to_posix_time


MANY = Accounts
SINGULAR = Account
Expand Down
7 changes: 2 additions & 5 deletions src/lib389/lib389/cli_idm/client_config.py
Expand Up @@ -6,12 +6,9 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

import argparse

from lib389.idm.user import nsUserAccount, nsUserAccounts
from lib389.idm.group import Group, Groups
from lib389.idm.user import nsUserAccounts
from lib389.idm.group import Groups
from lib389.plugins import MemberOfPlugin

from lib389.utils import basedn_to_ldap_dns_uri

SSSD_CONF_TEMPLATE = """
Expand Down
2 changes: 0 additions & 2 deletions src/lib389/lib389/cli_idm/group.py
Expand Up @@ -6,7 +6,6 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

import argparse
from lib389.idm.group import Group, Groups, MUST_ATTRIBUTES
from lib389.cli_base import populate_attr_arguments, _generic_modify
from lib389.cli_idm import (
Expand All @@ -16,7 +15,6 @@
_generic_create,
_generic_delete,
_get_arg,
_get_args,
_get_attributes,
_warn,
)
Expand Down
2 changes: 0 additions & 2 deletions src/lib389/lib389/cli_idm/organizationalunit.py
Expand Up @@ -6,7 +6,6 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

import argparse
from lib389.idm.organizationalunit import OrganizationalUnit, OrganizationalUnits, MUST_ATTRIBUTES
from lib389.cli_base import populate_attr_arguments, _generic_modify
from lib389.cli_idm import (
Expand All @@ -16,7 +15,6 @@
_generic_create,
_generic_delete,
_get_arg,
_get_args,
_get_attributes,
_warn,
)
Expand Down
2 changes: 0 additions & 2 deletions src/lib389/lib389/cli_idm/posixgroup.py
Expand Up @@ -6,7 +6,6 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

import argparse
from lib389.idm.posixgroup import PosixGroup, PosixGroups, MUST_ATTRIBUTES
from lib389.cli_base import populate_attr_arguments, _generic_modify
from lib389.cli_idm import (
Expand All @@ -16,7 +15,6 @@
_generic_create,
_generic_delete,
_get_arg,
_get_args,
_get_attributes,
_warn,
)
Expand Down
6 changes: 1 addition & 5 deletions src/lib389/lib389/cli_idm/role.py
Expand Up @@ -8,16 +8,12 @@
# --- END COPYRIGHT BLOCK ---

import ldap
import argparse

from lib389.idm.role import Role, Roles, RoleState
from lib389.idm.role import Role, Roles
from lib389.cli_base import (
_generic_get,
_generic_get_dn,
_generic_list,
_generic_delete,
_generic_modify_dn,
_get_arg,
_get_dn_arg,
_warn,
)
Expand Down
2 changes: 0 additions & 2 deletions src/lib389/lib389/cli_idm/user.py
Expand Up @@ -6,7 +6,6 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

import argparse
from lib389.idm.user import nsUserAccount, nsUserAccounts
from lib389.cli_base import populate_attr_arguments, _generic_modify
from lib389.cli_idm import (
Expand All @@ -16,7 +15,6 @@
_generic_create,
_generic_delete,
_get_arg,
_get_args,
_get_attributes,
_warn,
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib389/lib389/configurations/config.py
Expand Up @@ -32,7 +32,7 @@ def __init__(self, instance):
def apply(self, install, upgrade, interactive):
# How do we want to handle interactivity?
if not ((install and self.install) or (upgrade and self.upgrade)):
instance.debug()
self._instance.debug()
return False
if interactive:
raise Exception('Interaction not yet supported')
Expand Down
5 changes: 2 additions & 3 deletions src/lib389/lib389/configurations/config_001004000.py
Expand Up @@ -6,13 +6,12 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---

from .config import baseconfig, configoperation
from .config import baseconfig
from .sample import sampleentries
from lib389.idm.organizationalunit import OrganizationalUnits
from lib389.idm.group import Groups
from lib389.idm.posixgroup import PosixGroups
from lib389.idm.user import nsUserAccounts
from lib389.idm.services import ServiceAccounts
from lib389.idm.nscontainer import nsHiddenContainers


Expand All @@ -29,7 +28,7 @@ def _apply(self):
# Create the 389 service container
# This could also move to be part of core later ....
hidden_containers = nsHiddenContainers(self._instance, self._basedn)
ns389container = hidden_containers.create(properties={
hidden_containers.create(properties={
'cn': '389_ds_system'
})

Expand Down
4 changes: 1 addition & 3 deletions src/lib389/lib389/dirsrv_log.py
Expand Up @@ -11,11 +11,9 @@

import re
import gzip
from datetime import datetime
from dateutil.parser import parse as dt_parse
from glob import glob
from lib389._constants import DN_CONFIG
from lib389.utils import ensure_bytes, ensure_str
from lib389.utils import ensure_bytes


# Because many of these settings can change live, we need to check for certain
Expand Down
6 changes: 2 additions & 4 deletions src/lib389/lib389/encrypted_attributes.py
@@ -1,14 +1,12 @@
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2018 Red Hat, Inc.
# Copyright (C) 2020 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---


from lib389._constants import *
from lib389.properties import *
from lib389._mapped_object import DSLdapObjects, DSLdapObject


Expand Down Expand Up @@ -46,4 +44,4 @@ def __init__(self, instance, basedn):
self._objectclasses = ['nsAttributeEncryption']
self._filterattrs = ['cn']
self._childobject = EncryptedAttr
self._basedn = basedn
self._basedn = basedn

0 comments on commit ba3a704

Please sign in to comment.