cloudster / api / shelf / configuration /

__author__ = 'guillermo'

import os
import sys
import re
import simplejson as json

from api.shelf.registry.clients import StorageClientsRegistry
from api.shelf.configuration import config

class AccountsManager():

    def __init__(self, client_class):
        self.__client_class = client_class
        self.__account_type_class = self.__client_class.registry_metadata().account_type_class()
        self.__config_manager = config.ConfigurationManager()

    def get_configuration_descriptor(self):
        return self.__account_type_class.get_configuration_fields()

    def create(self, account_config_values):
        return self.__account_type_class(json.dumps(account_config_values))

    def authorize(self, account_data):
        client = self.__client_class(account_data)

        return client,account_data

    def load(self, unique_account_id):

        filename = self.__build_account_filename(unique_account_id)
        full_account_file_path = os.path.join(config.ConfigurationManager.APP_INSTANCES_PATH, filename)

        if os.path.exists(full_account_file_path):
            account_file = open(full_account_file_path,'r')
            account_file_content =


            return self.__account_type_class(account_file_content)
            #TODO Use a more specific exception
            raise RuntimeError('Account file %s not found' % filename)

    def connect(self, account_data):
        client = self.__client_class(account_data)

        return client

    def __build_account_filename(self, unique_account_id):
        return self.__client_class.registry_metadata().unique_id() + "_" + unique_account_id + ".json"

    def save(self, account_data):


        filename= self.__build_account_filename(account_data.unique_id()), filename))

    def delete(self, id=None):

    def list(self):

        name_expression = r"^"+ self.__client_class.registry_metadata().unique_id() + "_(\w*).json$"
        name_expression_compiled = re.compile(name_expression)

        account_file_names = self.__config_manager.list_defined_instances(name_expression_compiled)

        account_ids = []

        for account_name in account_file_names:
            result = re.match(name_expression_compiled,account_name)

        return account_ids
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.