Skip to content

Commit

Permalink
[password hardening]remove unuse functions created by the auto cli ge…
Browse files Browse the repository at this point in the history
…nerator
  • Loading branch information
davidpil2002 committed Aug 9, 2022
1 parent 4b81398 commit 24814ba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 179 deletions.
151 changes: 0 additions & 151 deletions config/plugins/sonic-passwh_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@ def validate_config_or_raise(cfg):
raise Exception('Failed to validate configuration: {}'.format(err))


def add_entry_validated(db, table, key, data):
""" Add new entry in table and validate configuration.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector obect.
table (str): Table name to add new entry to.
key (Union[str, Tuple]): Key name in the table.
data (Dict): Entry data.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

cfg = db.get_config()
cfg.setdefault(table, {})
if key in cfg[table]:
raise Exception(f"{key} already exists")

cfg[table][key] = data

validate_config_or_raise(cfg)
db.set_entry(table, key, data)


def update_entry_validated(db, table, key, data, create_if_not_exists=False):
""" Update entry in table and validate configuration.
If attribute value in data is None, the attribute is deleted.
Expand Down Expand Up @@ -104,134 +81,6 @@ def update_entry_validated(db, table, key, data, create_if_not_exists=False):

validate_config_or_raise(cfg)
db.set_entry(table, key, cfg[table][key])


def del_entry_validated(db, table, key):
""" Delete entry in table and validate configuration.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector obect.
table (str): Table name to add new entry to.
key (Union[str, Tuple]): Key name in the table.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

cfg = db.get_config()
cfg.setdefault(table, {})
if key not in cfg[table]:
raise Exception(f"{key} does not exist")

cfg[table].pop(key)

validate_config_or_raise(cfg)
db.set_entry(table, key, None)


def add_list_entry_validated(db, table, key, attr, data):
""" Add new entry into list in table and validate configuration.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector obect.
table (str): Table name to add data to.
key (Union[str, Tuple]): Key name in the table.
attr (str): Attribute name which represents a list the data needs to be added to.
data (List): Data list to add to config DB.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

cfg = db.get_config()
cfg.setdefault(table, {})
if key not in cfg[table]:
raise Exception(f"{key} does not exist")
cfg[table][key].setdefault(attr, [])
for entry in data:
if entry in cfg[table][key][attr]:
raise Exception(f"{entry} already exists")
cfg[table][key][attr].append(entry)

validate_config_or_raise(cfg)
db.set_entry(table, key, cfg[table][key])


def del_list_entry_validated(db, table, key, attr, data):
""" Delete entry from list in table and validate configuration.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector obect.
table (str): Table name to remove data from.
key (Union[str, Tuple]): Key name in the table.
attr (str): Attribute name which represents a list the data needs to be removed from.
data (Dict): Data list to remove from config DB.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

cfg = db.get_config()
cfg.setdefault(table, {})
if key not in cfg[table]:
raise Exception(f"{key} does not exist")
cfg[table][key].setdefault(attr, [])
for entry in data:
if entry not in cfg[table][key][attr]:
raise Exception(f"{entry} does not exist")
cfg[table][key][attr].remove(entry)
if not cfg[table][key][attr]:
cfg[table][key].pop(attr)

validate_config_or_raise(cfg)
db.set_entry(table, key, cfg[table][key])


def clear_list_entry_validated(db, table, key, attr):
""" Clear list in object and validate configuration.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector obect.
table (str): Table name to remove the list attribute from.
key (Union[str, Tuple]): Key name in the table.
attr (str): Attribute name which represents a list that needs to be removed.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

update_entry_validated(db, table, key, {attr: None})





































@click.group(name="passw-hardening",
Expand Down
28 changes: 0 additions & 28 deletions show/plugins/sonic-passwh_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,6 @@ def format_attr_value(entry, attr):
return entry.get(attr["name"], "N/A")


def format_group_value(entry, attrs):
""" Helper that formats grouped attribute to be presented in the table output.
Args:
entry (Dict[str, str]): CONFIG DB entry configuration.
attrs (List[Dict]): Attributes metadata that belongs to the same group.
Returns:
str: fomatted group attributes.
"""

data = []
for attr in attrs:
if entry.get(attr["name"]):
data.append((attr["name"] + ":", format_attr_value(entry, attr)))
return tabulate.tabulate(data, tablefmt="plain")












@click.group(name="passw-hardening",
cls=clicommon.AliasedGroup)
def PASSW_HARDENING():
Expand Down

0 comments on commit 24814ba

Please sign in to comment.