text stringlengths 81 112k |
|---|
Usage:
>>> TList([1, 2, 3, -2, -1]).uniq_by(lambda x: x**2)
[1, 2, 3]
def uniq_by(self, func: Callable[[T], Any]) -> 'TList[T]':
"""
Usage:
>>> TList([1, 2, 3, -2, -1]).uniq_by(lambda x: x**2)
[1, 2, 3]
"""
rs = TList()
for e in ... |
:param to_key:
:type to_key: T -> unicode
:rtype: TDict[TList[T]]
Usage:
>>> TList([1, 2, 3, 4, 5]).group_by(lambda x: x % 2).to_json()
'{"0": [2,4],"1": [1,3,5]}'
def group_by(self, to_key):
"""
:param to_key:
:type to_key: T -> unicode
... |
:param to_key: value -> key
Usage:
>>> TList(['a1', 'b2', 'c3']).key_by(lambda x: x[0]).to_json()
'{"a": "a1","b": "b2","c": "c3"}'
>>> TList([1, 2, 3, 4, 5]).key_by(lambda x: x % 2).to_json()
'{"0": 4,"1": 5}'
def key_by(self, to_key: Callable[[T], str]) -> 'TD... |
:param func:
:type func: T -> any
:param reverse: Sort by descend order if True, else by ascend
:type reverse: bool
:rtype: TList[T]
Usage:
>>> TList([12, 25, 31, 40, 57]).order_by(lambda x: x % 10)
[40, 31, 12, 25, 57]
>>> TList([12, 25, 31,... |
:param values:
:type values: TList[T]
:param first:
:type first: bool
:rtype: TList[T]
Usage:
>>> TList([1, 2]).concat(TList([3, 4]))
[1, 2, 3, 4]
>>> TList([1, 2]).concat(TList([3, 4]), first=True)
[3, 4, 1, 2]
def concat(self, ... |
Usage:
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 3)
Option --> 4
>>> TList([1, 2, 3, 4, 5]).find(lambda x: x > 6)
Option --> None
def find(self, func: Callable[[T], bool]) -> TOption[T]:
"""
Usage:
>>> TList([1, 2, 3, 4, 5]).find(lambda ... |
:param key:
Usage:
>>> TDict(k1=1, k2=2, k3=3).get("k2")
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).get("unknown")
Option --> None
def get(self, key: K) -> TOption[T]:
"""
:param key:
Usage:
>>> TDict(k1=1, k2=2, k3=3).get("k... |
:param func:
:type func: (K, T) -> U
:rtype: TList[U]
Usage:
>>> sorted(TDict(k1=1, k2=2, k3=3).map(lambda k, v: v*2))
[2, 4, 6]
def map(self, func):
"""
:param func:
:type func: (K, T) -> U
:rtype: TList[U]
Usage:
... |
:param func:
:type func: T -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values(lambda x: x*2) == {
... "k1": 2,
... "k2": 4,
... "k3": 6
... }
True
def map_values(self, func):
"""
... |
:param func:
:type func: (K, T) -> U
:rtype: TDict[U]
Usage:
>>> TDict(k1=1, k2=2, k3=3).map_values2(lambda k, v: f'{k} -> {v*2}') == {
... "k1": "k1 -> 2",
... "k2": "k2 -> 4",
... "k3": "k3 -> 6"
... }
True
... |
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).filter(lambda k, v: v < 2)
[1]
def filter(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
... |
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
>>> TDict(k1=1, k2=2, k3=3).reject(lambda k, v: v < 3)
[3]
def reject(self, func):
"""
:param func:
:type func: (K, T) -> bool
:rtype: TList[T]
Usage:
... |
Usage:
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 2)
Option --> 2
>>> TDict(k1=1, k2=2, k3=3).find(lambda k, v: v == 4)
Option --> None
def find(self, func: Callable[[K, T], bool]) -> TOption[T]:
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3... |
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 0)
True
>>> TDict(k1=1, k2=2, k3=3).all(lambda k, v: v > 1)
False
def all(self, func):
"""
:param func:
:type fu... |
:param func:
:type func: (K, T) -> bool
:rtype: bool
Usage:
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 2)
True
>>> TDict(k1=1, k2=2, k3=3).any(lambda k, v: v > 3)
False
def any(self, func):
"""
:param func:
:type fu... |
Usage:
>>> TDict(k1=1, k2=2, k3=3).pick_by(lambda k, v: v > 2)
{'k3': 3}
def pick_by(self, func: Callable[[K, T], bool]) -> 'TDict[T]':
"""
Usage:
>>> TDict(k1=1, k2=2, k3=3).pick_by(lambda k, v: v > 2)
{'k3': 3}
"""
return TDict({k: v f... |
Takes a header tagname (e.g. 'h1') and adjusts the
stack that remembers the headers seen.
def storeSectionState(self, level):
"""
Takes a header tagname (e.g. 'h1') and adjusts the
stack that remembers the headers seen.
"""
# self.document.append("<!-- storeSectionSta... |
Closes all sections of level >= sectnum. Defaults to closing all open sections
def endSections(self, level=u'0'):
"""Closes all sections of level >= sectnum. Defaults to closing all open sections"""
iSectionsClosed = self.storeSectionState(level)
self.document.append("</section>\n" * iSections... |
From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inherited if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Dict
... |
From instance to dict
:param ignore_none: Properties which is None are excluded if True
:param force_value: Transform to value using to_value (default: str()) of ValueTransformer which inherited if True
:param ignore_empty: Properties which is empty are excluded if True
:return: List[Di... |
From instance to json string
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
Usage:
>>> from owlmixin.samples import Huma... |
From instance to json file
:param fpath: Json file path
:param encoding: Json file encoding
:param indent: Number of indentation
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return:... |
From instance to pretty json string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Json string
Usage:
>>> from owlmixin.samples import Human
>>> human = Human.from_d... |
From instance to yaml string
:param ignore_none: Properties which is None are excluded if True
:param ignore_empty: Properties which is empty are excluded if True
:return: Yaml string
Usage:
>>> from owlmixin.samples import Human
>>> human = Human.from_dict({
... |
From instance to yaml file
:param ignore_none: Properties which is None are excluded if True
:param fpath: Yaml file path
:param encoding: Yaml file encoding
:return: Yaml file path
def to_yamlf(self, fpath: str, encoding: str='utf8', ignore_none: bool=True, ignore_empty: bool=False) -... |
From sequence of text to csv string
:param fieldnames: Order of columns by property name
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF line break at the end of line if True, else add LF
:param tsv: Use tabs as separator if True, else use comma
:... |
From instance to yaml file
:param fpath: Csv file path
:param fieldnames: Order of columns by property name
:param encoding: Csv file encoding
:param with_header: Add headers at the first line if True
:param crlf: Add CRLF line break at the end of line if True, else add LF
... |
From sequence of text to csv string
:param fieldnames: Order of columns by property name
:return: Table string
Usage:
>>> from owlmixin.samples import Human
>>> humans = Human.from_dicts([
... {"id": 1, "name": "Tom", "favorites": [{"name": "Apple"}]},
... |
This method transforms a few things before tidy runs. When we get rid
of tidy, this can go away.
def _pre_tidy(html):
""" This method transforms a few things before tidy runs. When we get rid
of tidy, this can go away. """
tree = etree.fromstring(html, etree.HTMLParser())
for el in tree.xpa... |
This method transforms post tidy. Will go away when tidy goes away.
def _post_tidy(html):
""" This method transforms post tidy. Will go away when tidy goes away. """
tree = etree.fromstring(html)
ems = tree.xpath(
"//xh:em[@class='underline']|//xh:em[contains(@class, ' underline ')]",
names... |
Tidy up a html4/5 soup to a parsable valid XHTML5.
Requires tidy-html5 from https://github.com/w3c/tidy-html5
Installation: http://goo.gl/FG27n
def _tidy2xhtml5(html):
"""Tidy up a html4/5 soup to a parsable valid XHTML5.
Requires tidy-html5 from https://github.com/w3c/tidy-html5
Installation: http... |
Helper that creates a XSLT stylesheet
def _make_xsl(filename):
"""Helper that creates a XSLT stylesheet """
path = pkg_resources.resource_filename('rhaptos.cnxmlutils.xsl', filename)
xml = etree.parse(path)
return etree.XSLT(xml) |
Transforms the xml using the specifiec xsl file.
def _transform(xsl_filename, xml, **kwargs):
"""Transforms the xml using the specifiec xsl file."""
xslt = _make_xsl(xsl_filename)
xml = xslt(xml, **kwargs)
return xml |
Unescapes Math from Mathjax to MathML.
def _unescape_math(xml):
"""Unescapes Math from Mathjax to MathML."""
xpath_math_script = etree.XPath(
'//x:script[@type="math/mml"]',
namespaces={'x': 'http://www.w3.org/1999/xhtml'})
math_script_list = xpath_math_script(xml)
for mathscrip... |
Transform the CNXML source to HTML
def cnxml_to_html(cnxml_source):
"""Transform the CNXML source to HTML"""
source = _string2io(cnxml_source)
xml = etree.parse(source)
# Run the CNXML to HTML transform
xml = _transform('cnxml-to-html5.xsl', xml,
version='"{}"'.format(version))... |
Converts HTML5 from Aloha editor output to a lxml etree.
def aloha_to_etree(html_source):
""" Converts HTML5 from Aloha editor output to a lxml etree. """
xml = _tidy2xhtml5(html_source)
for i, transform in enumerate(ALOHA2HTML_TRANSFORM_PIPELINE):
xml = transform(xml)
return xml |
Converts HTML5 from Aloha to a more structured HTML5
def aloha_to_html(html_source):
"""Converts HTML5 from Aloha to a more structured HTML5"""
xml = aloha_to_etree(html_source)
return etree.tostring(xml, pretty_print=True) |
Transform the HTML to CNXML. We need the original CNXML content in
order to preserve the metadata in the CNXML document.
def html_to_cnxml(html_source, cnxml_source):
"""Transform the HTML to CNXML. We need the original CNXML content in
order to preserve the metadata in the CNXML document.
"""
sour... |
Transform the HTML to valid CNXML (used for OERPUB).
No original CNXML is needed. If HTML is from Aloha please use
aloha_to_html before using this method
def html_to_valid_cnxml(html_source):
"""Transform the HTML to valid CNXML (used for OERPUB).
No original CNXML is needed. If HTML is from Aloha pl... |
Usage:
>>> TOption(3).get_or(999)
3
>>> TOption(0).get_or(999)
0
>>> TOption(None).get_or(999)
999
def get_or(self, default: T) -> T:
"""
Usage:
>>> TOption(3).get_or(999)
3
>>> TOption(0).get_... |
Usage:
>>> TOption(3).map(lambda x: x+1).get()
4
>>> TOption(None).map(lambda x: x+1).get_or(999)
999
def map(self, func: Callable[[T], U]) -> 'TOption[T]':
"""
Usage:
>>> TOption(3).map(lambda x: x+1).get()
4
>>> TOp... |
Usage:
>>> TOption(3).flat_map(lambda x: TOption(x+1)).get()
4
>>> TOption(3).flat_map(lambda x: TOption(None)).get_or(999)
999
>>> TOption(None).flat_map(lambda x: TOption(x+1)).get_or(999)
999
def flat_map(self, func: Callable[[T], 'TOption[T]'... |
Replace both the hex and decimal versions of symbols in an XML string
def replace(text):
"""Replace both the hex and decimal versions of symbols in an XML string"""
for hex, value in UNICODE_DICTIONARY.items():
num = int(hex[3:-1], 16)
#uni = unichr(num)
decimal = '&#' + str(num) + ';'
for key in [... |
:param dict d:
:param Dict[unicode, unicode] keymap:
:param bool force_snake_case:
:rtype: Dict[unicode, unicode]
def replace_keys(d, keymap, force_snake_case):
"""
:param dict d:
:param Dict[unicode, unicode] keymap:
:param bool force_snake_case:
:rtype: Dict[unicode, unicode]
"""
... |
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
def load_jsonf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return json.load(f) |
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
def load_yamlf(fpath, encoding):
"""
:param unicode fpath:
:param unicode encoding:
:rtype: dict | list
"""
with codecs.open(fpath, encoding=encoding) as f:
return yaml.safe_load(f) |
:param unicode fpath:
:param Optional[list[unicode]] fieldnames:
:param unicode encoding:
:rtype: List[dict]
def load_csvf(fpath, fieldnames, encoding):
"""
:param unicode fpath:
:param Optional[list[unicode]] fieldnames:
:param unicode encoding:
:rtype: List[dict]
"""
with open... |
:param data:
:param fieldnames:
:param with_header:
:param crlf:
:param tsv:
:return: unicode
def dump_csv(data: List[dict], fieldnames: Sequence[str], with_header: bool = False, crlf: bool = False,
tsv: bool = False) -> str:
"""
:param data:
:param fieldnames:
:param w... |
:param data:
:param fieldnames:
:param fpath: write path
:param encoding: encoding
:param with_header:
:param crlf:
:param tsv:
:return: written path
def save_csvf(data: list, fieldnames: Sequence[str], fpath: str, encoding: str, with_header: bool = False,
crlf: bool = False, ... |
:param list | dict data:
:param Optional[int] indent:
:rtype: unicode
def dump_json(data, indent=None):
"""
:param list | dict data:
:param Optional[int] indent:
:rtype: unicode
"""
return json.dumps(data,
indent=indent,
ensure_ascii=False,
... |
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:param indent:
:rtype: written path
def save_jsonf(data: Union[list, dict], fpath: str, encoding: str, indent=None) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encodi... |
:param list | dict data:
:rtype: unicode
def dump_yaml(data):
"""
:param list | dict data:
:rtype: unicode
"""
return yaml.dump(data,
indent=2,
encoding=None,
allow_unicode=True,
default_flow_style=False,
... |
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:rtype: written path
def save_yamlf(data: Union[list, dict], fpath: str, encoding: str) -> str:
"""
:param data: list | dict data
:param fpath: write path
:param encoding: encoding
:rtype: written path
... |
:param data:
:param fieldnames:
:return: Table string
def dump_table(data: List[dict], fieldnames: Sequence[str]) -> str:
"""
:param data:
:param fieldnames:
:return: Table string
"""
def min3(num: int) -> int:
return 3 if num < 4 else num
width_by_col: Dict[str, int] = {
... |
:param word:
:return: Widths of word
Usage:
>>> string_width('abc')
3
>>> string_width('Abしー')
7
>>> string_width('')
0
def string_width(word: str) -> int:
"""
:param word:
:return: Widths of word
Usage:
>>> string_width('abc')
... |
Used only for debugging to write out intermediate files
def writeXMLFile(filename, content):
""" Used only for debugging to write out intermediate files"""
xmlfile = open(filename, 'w')
# pretty print
content = etree.tostring(content, pretty_print=True)
xmlfile.write(content)
xmlfile.close() |
Given an ODT file this returns a tuple containing
the cnxml, a dictionary of filename -> data, and a list of errors
def transform(odtfile, debug=False, parsable=False, outputdir=None):
""" Given an ODT file this returns a tuple containing
the cnxml, a dictionary of filename -> data, and a list of e... |
Create instance from symbol
:param value: unique symbol
:return: This instance
Usage:
>>> from owlmixin.samples import Animal
>>> Animal.from_value('cat').crow()
mewing
def from_value(cls, value: str) -> T:
"""Create instance from symbol
:pa... |
Will thaw into a temporary location
def auto_thaw(vault_client, opt):
"""Will thaw into a temporary location"""
icefile = opt.thaw_from
if not os.path.exists(icefile):
raise aomi.exceptions.IceFile("%s missing" % icefile)
thaw(vault_client, icefile, opt)
return opt |
Will provision vault based on the definition within a Secretfile
def seed(vault_client, opt):
"""Will provision vault based on the definition within a Secretfile"""
if opt.thaw_from:
opt.secrets = tempfile.mkdtemp('aomi-thaw')
auto_thaw(vault_client, opt)
Context.load(get_secretfile(opt), ... |
Render any provided template. This includes the Secretfile,
Vault policies, and inline AWS roles
def render(directory, opt):
"""Render any provided template. This includes the Secretfile,
Vault policies, and inline AWS roles"""
if not os.path.exists(directory) and not os.path.isdir(directory):
... |
Export contents of a Secretfile from the Vault server
into a specified directory.
def export(vault_client, opt):
"""Export contents of a Secretfile from the Vault server
into a specified directory."""
ctx = Context.load(get_secretfile(opt), opt) \
.fetch(vault_client)
for resource ... |
Maybe it will render in color maybe it will not!
def maybe_colored(msg, color, opt):
"""Maybe it will render in color maybe it will not!"""
if opt.monochrome:
return msg
return colored(msg, color) |
Normalize JSON/YAML derived values as they pertain
to Vault resources and comparison operations
def normalize_val(val):
"""Normalize JSON/YAML derived values as they pertain
to Vault resources and comparison operations """
if is_unicode(val) and val.isdigit():
return int(val)
elif isinstanc... |
Output the changes, if any, for a dict
def details_dict(obj, existing, ignore_missing, opt):
"""Output the changes, if any, for a dict"""
existing = dict_unicodeize(existing)
obj = dict_unicodeize(obj)
for ex_k, ex_v in iteritems(existing):
new_value = normalize_val(obj.get(ex_k))
og_va... |
At the first level of verbosity this will print out detailed
change information on for the specified Vault resource
def maybe_details(resource, opt):
"""At the first level of verbosity this will print out detailed
change information on for the specified Vault resource"""
if opt.verbose == 0:
r... |
Handle the diff action for a single thing. It may be a Vault backend
implementation or it may be a Vault data resource
def diff_a_thing(thing, opt):
"""Handle the diff action for a single thing. It may be a Vault backend
implementation or it may be a Vault data resource"""
changed = thing.diff()
if... |
Derive a comparison between what is represented in the Secretfile
and what is actually live on a Vault instance
def diff(vault_client, opt):
"""Derive a comparison between what is represented in the Secretfile
and what is actually live on a Vault instance"""
if opt.thaw_from:
opt.secrets = temp... |
Handle display of help and whatever diagnostics
def help_me(parser, opt):
"""Handle display of help and whatever diagnostics"""
print("aomi v%s" % version)
print('Get started with aomi'
' https://autodesk.github.io/aomi/quickstart')
if opt.verbose == 2:
tf_str = 'Token File,' if token... |
Add the command line options for the extract_file operation
def extract_file_args(subparsers):
"""Add the command line options for the extract_file operation"""
extract_parser = subparsers.add_parser('extract_file',
help='Extract a single secret from'
... |
Add various variable mapping command line options to the parser
def mapping_args(parser):
"""Add various variable mapping command line options to the parser"""
parser.add_argument('--add-prefix',
dest='add_prefix',
help='Specify a prefix to use when '
... |
Add command line options for the aws_environment operation
def aws_env_args(subparsers):
"""Add command line options for the aws_environment operation"""
env_parser = subparsers.add_parser('aws_environment')
env_parser.add_argument('vault_path',
help='Full path(s) to the AWS sec... |
Add command line options for the environment operation
def environment_args(subparsers):
"""Add command line options for the environment operation"""
env_parser = subparsers.add_parser('environment')
env_parser.add_argument('vault_paths',
help='Full path(s) to secret',
... |
Add command line options for the template operation
def template_args(subparsers):
"""Add command line options for the template operation"""
template_parser = subparsers.add_parser('template')
template_parser.add_argument('template',
help='Template source',
... |
Add Secretfile management command line arguments to parser
def secretfile_args(parser):
"""Add Secretfile management command line arguments to parser"""
parser.add_argument('--secrets',
dest='secrets',
help='Path where secrets are stored',
... |
Add the generic command line options
def base_args(parser):
"""Add the generic command line options"""
generic_args(parser)
parser.add_argument('--monochrome',
dest='monochrome',
help='Whether or not to use colors',
action='store_true'... |
Add command line options for the export operation
def export_args(subparsers):
"""Add command line options for the export operation"""
export_parser = subparsers.add_parser('export')
export_parser.add_argument('directory',
help='Path where secrets will be exported into')
... |
Add command line options for the render operation
def render_args(subparsers):
"""Add command line options for the render operation"""
render_parser = subparsers.add_parser('render')
render_parser.add_argument('directory',
help='Path where Secrefile and accoutrement'
... |
Add command line options for the diff operation
def diff_args(subparsers):
"""Add command line options for the diff operation"""
diff_parser = subparsers.add_parser('diff')
secretfile_args(diff_parser)
vars_args(diff_parser)
base_args(diff_parser)
thaw_from_args(diff_parser) |
Add command line options for the seed operation
def seed_args(subparsers):
"""Add command line options for the seed operation"""
seed_parser = subparsers.add_parser('seed')
secretfile_args(seed_parser)
vars_args(seed_parser)
seed_parser.add_argument('--mount-only',
dest... |
Adds command line options for things related to inline thawing
of icefiles
def thaw_from_args(parser):
"""Adds command line options for things related to inline thawing
of icefiles"""
parser.add_argument('--thaw-from',
dest='thaw_from',
help='Thaw an ICE ... |
Add command line options for the thaw operation
def thaw_args(subparsers):
"""Add command line options for the thaw operation"""
thaw_parser = subparsers.add_parser('thaw')
thaw_parser.add_argument('--gpg-password-path',
dest='gpg_pass_path',
help='... |
Add command line options for the freeze operation
def freeze_args(subparsers):
"""Add command line options for the freeze operation"""
freeze_parser = subparsers.add_parser('freeze')
freeze_parser.add_argument('--icefile-prefix',
dest='icefile_prefix',
... |
Add command line options for the set_password operation
def password_args(subparsers):
"""Add command line options for the set_password operation"""
password_parser = subparsers.add_parser('set_password')
password_parser.add_argument('vault_path',
help='Path which contains ... |
Add various command line options for external vars
def vars_args(parser):
"""Add various command line options for external vars"""
parser.add_argument('--extra-vars',
dest='extra_vars',
help='Extra template variables',
default=[],
... |
Return a proper contextual OptionParser
def parser_factory(fake_args=None):
"""Return a proper contextual OptionParser"""
parser = ArgumentParser(description='aomi')
subparsers = parser.add_subparsers(dest='operation',
help='Specify the data '
... |
Executes template related operations
def template_runner(client, parser, args):
"""Executes template related operations"""
if args.builtin_list:
aomi.template.builtin_list()
elif args.builtin_info:
aomi.template.builtin_info(args.builtin_info)
elif args.template and args.destination and... |
Handle some human triggers actions
def ux_actions(parser, args):
"""Handle some human triggers actions"""
# cryptorito uses native logging (as aomi should tbh)
normal_fmt = '%(message)s'
if hasattr(args, 'verbose') and args.verbose and args.verbose >= 2:
logging.basicConfig(level=logging.DEBUG)... |
Execute the thaw operation, pulling in an actual Vault
client if neccesary
def do_thaw(client, args):
"""Execute the thaw operation, pulling in an actual Vault
client if neccesary"""
vault_client = None
if args.gpg_pass_path:
vault_client = client.connect(args)
aomi.filez.thaw(vault_cl... |
Run appropriate action, or throw help
def action_runner(parser, args):
"""Run appropriate action, or throw help"""
ux_actions(parser, args)
client = aomi.vault.Client(args)
if args.operation == 'extract_file':
aomi.render.raw_file(client.connect(args),
args.vault_... |
Entrypoint, sweet Entrypoint
def main():
"""Entrypoint, sweet Entrypoint"""
parser, args = parser_factory()
try:
action_runner(parser, args)
# this is our uncaught handler so yes we want to actually
# catch every error. the format may vary based on the error handler tho
except Exceptio... |
Parses the TTL information
def grok_ttl(secret):
"""Parses the TTL information"""
ttl_obj = {}
lease_msg = ''
if 'lease' in secret:
ttl_obj['lease'] = secret['lease']
lease_msg = "lease:%s" % (ttl_obj['lease'])
if 'lease_max' in secret:
ttl_obj['lease_max'] = secret['lease_... |
Return the version, checking both packaged and development locations
def my_version():
"""Return the version, checking both packaged and development locations"""
if os.path.exists(resource_filename(__name__, 'version')):
return resource_string(__name__, 'version')
return open(os.path.join(os.path.... |
Return what is hopefully a OS independent path.
def abspath(raw):
"""Return what is hopefully a OS independent path."""
path_bits = []
if raw.find('/') != -1:
path_bits = raw.split('/')
elif raw.find('\\') != -1:
path_bits = raw.split('\\')
else:
path_bits = [raw]
retur... |
Returns an absolute path to either the relative or absolute file.
def hard_path(path, prefix_dir):
"""Returns an absolute path to either the relative or absolute file."""
relative = abspath("%s/%s" % (prefix_dir, path))
a_path = abspath(path)
if os.path.exists(relative):
LOG.debug("using relati... |
Checks if tags match
def is_tagged(required_tags, has_tags):
"""Checks if tags match"""
if not required_tags and not has_tags:
return True
elif not required_tags:
return False
found_tags = []
for tag in required_tags:
if tag in has_tags:
found_tags.append(tag)
... |
Parse out a hash from a list of key=value strings
def cli_hash(list_of_kv):
"""Parse out a hash from a list of key=value strings"""
ev_obj = {}
for extra_var in list_of_kv:
ev_list = extra_var.split('=')
key = ev_list[0]
val = '='.join(ev_list[1:]) # b64 and other side effects
... |
Deep merge of two dicts
def merge_dicts(dict_a, dict_b):
"""Deep merge of two dicts"""
obj = {}
for key, value in iteritems(dict_a):
if key in dict_b:
if isinstance(dict_b[key], dict):
obj[key] = merge_dicts(value, dict_b.pop(key))
else:
obj[key] = va... |
When returning a password from a TTY we assume a user
is entering it on a keyboard so we ask for confirmation.
def get_tty_password(confirm):
"""When returning a password from a TTY we assume a user
is entering it on a keyboard so we ask for confirmation."""
LOG.debug("Reading password from TTY")
n... |
Will return a two part tuple comprising of the vault path
and the key with in the stored object
def path_pieces(vault_path):
"""Will return a two part tuple comprising of the vault path
and the key with in the stored object"""
path_bits = vault_path.split('/')
path = '/'.join(path_bits[0:len(path_b... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.