Ejemplo n.º 1
0
    def backup(  # type: ignore
            self, client: DCOSClient, **kwargs) -> BackupList:
        backupList = BackupList()
        sec = DCOSSecretsService(client)
        path = ""
        keys = sec.list(path)
        if keys:
            for key in keys:
                secData = sec.get(path, key)

                backupList.append(
                    Backup(self.plugin_name,
                           Backup.renderBackupName(path + key),
                           data=secData))

        return backupList
def create_example_list(dir: str) -> StorableList:
    list = StorableList(str(dir))

    p = "testPlugin"
    b = "foobar"
    d = {"foo": "bar"}
    list.append(Backup(pluginName=p, backupName=b, data=d))

    list.store()
    return list, p, b, d
Ejemplo n.º 3
0
    def backup(self, client: DCOSClient, backupList: BackupList, **kwargs: Any) -> BackupList:
        bl = BackupList()
        for b in backupList.backups(pluginName="marathon"):
            assert isinstance(b, Backup)
            if (b.data and 'labels' in b.data and "DCOS_PACKAGE_NAME" in b.data['labels']
                    and b.data['labels']['DCOS_PACKAGE_NAME'] == "jenkins"):
                # we found a jenkins package lets extract the config
                if 'DCOS_PACKAGE_OPTIONS' in b.data['labels']:
                    options_str = b64decode(b.data['labels']['DCOS_PACKAGE_OPTIONS'])

                    options = json.loads(options_str)
                    data = {
                        "packageName": b.data['labels']['DCOS_PACKAGE_NAME'],
                        "version": b.data['labels']['DCOS_PACKAGE_VERSION'],
                        "options": options
                    }

                    bl.append(
                        Backup(pluginName=self.plugin_name,
                               backupName=Backup.renderBackupName(b.data['labels']['DCOS_SERVICE_NAME']),
                               data=data))
        return bl
def test_secret_migrate():
    with open('tests/examples/simpleSecret.json') as json_file:
        data = json.load(json_file)

        assert data['key'] is not None

        bl = BackupList()
        bl.append(Backup(pluginName='secret', backupName='foo.bar', data=data))

        s = SecretPlugin()

        ml = s.migrate(backupList=bl, manifestList=ManifestList())

        assert len(ml) == 1
        assert ml[0][0].data['foo.bar'] == 'Rk9PQkFS'
Ejemplo n.º 5
0
    def backup(self, client: DCOSClient, backupList: BackupList,
               **kwargs: Any) -> BackupList:
        bl = BackupList()
        metadataResp = client.get(client.full_dcos_url('/metadata'))
        stateSumResp = client.get(
            client.full_dcos_url('/mesos/master/state-summary'))

        metadata = metadataResp.json()
        state = stateSumResp.json()

        data = {
            "CLUSTER_ID": metadata['CLUSTER_ID'],
            "CLUSTER": state['cluster'],
            "MESOS_MASTER_STATE-SUMMARY": state,
            "BACKUP_DATE": str(datetime.date.today())
        }

        bl.append(
            Backup(pluginName=self.plugin_name,
                   backupName="default",
                   data=data))

        return bl
Ejemplo n.º 6
0
 def createBackup(self, app: Dict[str, Any]) -> Backup:
     return Backup(pluginName=self.plugin_name,
                   backupName=Backup.renderBackupName(app['id']),
                   data=app)
Ejemplo n.º 7
0
 def createBackup(self, job: T.Dict[str, T.Any]) -> Backup:
     return Backup(
         pluginName=self.plugin_name,
         backupName=Backup.renderBackupName(job["id"]),
         data=job,
     )