mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add general sanitisers
This commit is contained in:
parent
47d21d9ed2
commit
816b1d1977
1 changed files with 40 additions and 0 deletions
40
salt/utils/general.py
Normal file
40
salt/utils/general.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2016 SUSE LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
import os.path
|
||||
from builtins import str as text
|
||||
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
||||
class InputSanitizer(object):
|
||||
@staticmethod
|
||||
def trim(value):
|
||||
'''
|
||||
Raise an exception if value is empty. Otherwise strip it down.
|
||||
:param value:
|
||||
:return:
|
||||
'''
|
||||
value = (value or '').strip()
|
||||
if not value:
|
||||
raise CommandExecutionError("Empty value during sanitation")
|
||||
|
||||
return text(value)
|
||||
|
||||
|
||||
|
||||
clean = InputSanitizer()
|
Loading…
Add table
Reference in a new issue