Exemple #1
0
class SecretsManager(object):

    HEADER = "[VESPENE-CLOAK]"

    def __init__(self):
        self.plugin_loader = PluginLoader()
        self.plugins = self.plugin_loader.get_secrets_plugins()

    def is_cloaked(self, msg):
        if not msg:
            return False
        return msg.startswith(self.HEADER)

    def decloak(self, msg):
        if not self.is_cloaked(msg):
            return msg
        else:
            for plugin in self.plugins:
                if plugin.recognizes(msg):
                    return plugin.decloak(msg)
            raise Exception("no plugin found to decloak value")

    def cloak(self, msg):
        if not msg or self.is_cloaked(msg) or len(self.plugins) == 0:
            return msg
        return self.plugins[0].cloak(msg)
Exemple #2
0
class SecretsManager(object):

    def __init__(self):
        self.plugin_loader = PluginLoader()
        self.plugins = self.plugin_loader.get_secrets_plugins()

    def cloak(self, msg):
        if len(self.plugins) == 0:
            return msg
        if not self.is_cloaked(msg):
            return self.plugins[0].cloak(msg)
        else:
            # already cloaked, will not re-cloak
            return msg

    def is_cloaked(self, msg):
        return msg.startswith(HEADER)

    def decloak(self, msg):
        remainder = msg.replace(HEADER, "", 1)
        for plugin in self.plugins:
            if plugin.recognizes(remainder):
                return plugin.decloak(remainder)
        return remainder