예제 #1
0
 def setup(self, url, token, parent_project = None):
     timer = Timer()
     timer.start("Setup")
     
     self.parent_project = parent_project
     
     rest = RestRequests(url)
     self.auth = Auth(rest)
     
     if not self.auth.authorize(token):
         # Try one more time, since often the error is a session expired error and
         # seems to work fine on the second try.
         print("Encountered error, retrying authorization")
         if not self.auth.authorize(token):
             timer.stop()
             return False
     
     self.rest = AuthorizingRestProxy(rest, self.auth.get_token())
     self.projects = Projects(self.rest)
     self.batches = Batches(self.rest)
     self.groups = Groups(self.rest)
     self.permissions = Permissions(self.rest)
     
     # Also sets up a project to work in.
     self.project = self.projects.new_project(parent_project, None,
         "Test project created at " + str(datetime.datetime.now()))
     print("Set up project with uuid " + self.project.get_uuid())
     
     timer.stop()
     return True
예제 #2
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.config.get_url()))
        auth = Auth(rest)
        if not auth.authenticate(self.config.get_token()):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.config.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        timer.stop()
        return True
예제 #3
0
    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.url))
        auth = Auth(rest)
        if not auth.authenticate(self.token):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.token)
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
예제 #4
0
    def setup(self):
        """Sets up the API client and modules for issuing requests to the ADAM API."""
        timer = Timer()
        timer.start("Setup")

        retrying_rest = RetryingRestProxy(RestRequests())
        self.rest = AuthenticatingRestProxy(retrying_rest)
        auth = Auth(self.rest)
        if not auth.authenticate():
            print("Could not authenticate.")
            return False

        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True
예제 #5
0
class Service(object):
    """Module wrapping the REST API and associated client libraries. The goal of this
    module is to make it very easy and readable to do basic operations against a prod or
    dev setup.

    """
    @classmethod
    def from_config(cls, config=None):
        if config is None:
            cm = ConfigManager()
            config = cm.get_config(environment=cm.get_default_env())
        return cls(url=config['url'], project=config['workspace'])

    def __init__(self, url, project):
        """Initialize the Service module.

        Args:
            url (str): The URL of the ADAM server to send requests to.
            project (str): The ADAM project id, under which to create other working projects.
        """
        self.url = url
        self.project = project
        self.working_projects = []

    def new_working_project(self, project_name=None):
        """Creates a new project under the root project (workspace) in the ADAM configuration.

        Args:
            project_name (str): The name for the new project (optional).

        Returns:
            Project: the newly created project, or None, if there is no configured root project.
        """
        timer = Timer()
        timer.start(
            f"Create a new working project under project {self.project}")
        if self.project:
            project = self.projects.new_project(
                self.project, project_name,
                "Test project created at " + str(datetime.datetime.now()))
            self.working_projects.append(project)
            print("Set up project with uuid " + project.get_uuid())
            timer.stop()
            return project
        else:
            print(
                "A root project must be configured in order to use other working projects "
                + "(which live under the root project).")
            timer.stop()
            return None

    def setup(self):
        """Sets up the API client and modules for issuing requests to the ADAM API."""
        timer = Timer()
        timer.start("Setup")

        retrying_rest = RetryingRestProxy(RestRequests())
        self.rest = AuthenticatingRestProxy(retrying_rest)
        auth = Auth(self.rest)
        if not auth.authenticate():
            print("Could not authenticate.")
            return False

        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        self.processing_service = AdamProcessingService(self.rest)

        timer.stop()
        return True

    def teardown(self):
        """Delete all working projects that were created in this Jupyter session."""
        timer = Timer()
        timer.start("Teardown")
        for project in self.working_projects:
            print("Cleaning up working project %s..." % (project.get_uuid()))
            self.projects.delete_project(project.get_uuid())
        timer.stop()

    def get_projects_module(self):
        return self.projects

    def get_batches_module(self):
        return self.batches

    def get_groups_module(self):
        return self.groups

    def get_permissions_module(self):
        return self.permissions
예제 #6
0
class Service():
    """Module wrapping the REST API and associated client libraries. The goal of this
    module is to make it very easy and readable to do basic operations against a prod or
    dev setup.

    """
    def __init__(self, config):
        self.config = config
        self.working_projects = []

    def new_working_project(self):
        timer = Timer()
        timer.start("Generate working project")
        if self.config.get_workspace() != '':
            project = self.projects.new_project(
                self.config.get_workspace(), None,
                "Test project created at " + str(datetime.datetime.now()))
            self.working_projects.append(project)
            print("Set up project with uuid " + project.get_uuid())
            timer.stop()
            return project
        else:
            print(
                "Workspace must be configured in order to use working projects (which live in the workspace)."
            )
            timer.stop()
            return None

    def setup(self):
        timer = Timer()
        timer.start("Setup")

        rest = RetryingRestProxy(RestRequests(self.config.get_url()))
        auth = Auth(rest)
        if not auth.authenticate(self.config.get_token()):
            print("Could not authenticate.")
            return False

        self.rest = AuthenticatingRestProxy(rest, self.config.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)

        timer.stop()
        return True

    def teardown(self):
        timer = Timer()
        timer.start("Teardown")
        for project in self.working_projects:
            print("Cleaning up working project %s..." % (project.get_uuid()))
            self.projects.delete_project(project.get_uuid())
        timer.stop()

    def get_projects_module(self):
        return self.projects

    def get_batches_module(self):
        return self.batches

    def get_groups_module(self):
        return self.groups

    def get_permissions_module(self):
        return self.permissions
예제 #7
0
class Service():
    """Module wrapping the REST API and associated client libraries. The goal of this
    module is to make it very easy and readable to do basic operations against a prod or
    dev setup.

    """
    def __init__(self):
        self.batch_runs = []
    
    def setup_with_test_account(self, prod=True):
        # These tokens belong to [email protected] (b612adam) which has
        # been given the permissions necessary to carry out various operations.
        if prod:
            token = "42MbDS0RbvVZF83aqXvapPvY6h62"
            url = "https://pro-equinox-162418.appspot.com/_ah/api/adam/v1"
            parent_project = "61c25677-c328-45c4-af22-a0a4d5e54826"
        else:
            token = "1YueO0qiWOTBJSZjdIynYTmJZDG3"
            url = "https://adam-dev-193118.appspot.com/_ah/api/adam/v1"
            parent_project = "88e2152d-e37e-437d-af88-65bca9374f34"
        return self.setup(url, token, parent_project)
    
    def setup(self, url, token, parent_project = None):
        timer = Timer()
        timer.start("Setup")
        
        self.parent_project = parent_project
        
        rest = RestRequests(url)
        self.auth = Auth(rest)
        
        if not self.auth.authorize(token):
            # Try one more time, since often the error is a session expired error and
            # seems to work fine on the second try.
            print("Encountered error, retrying authorization")
            if not self.auth.authorize(token):
                timer.stop()
                return False
        
        self.rest = AuthorizingRestProxy(rest, self.auth.get_token())
        self.projects = Projects(self.rest)
        self.batches = Batches(self.rest)
        self.groups = Groups(self.rest)
        self.permissions = Permissions(self.rest)
        
        # Also sets up a project to work in.
        self.project = self.projects.new_project(parent_project, None,
            "Test project created at " + str(datetime.datetime.now()))
        print("Set up project with uuid " + self.project.get_uuid())
        
        timer.stop()
        return True
        
    def teardown(self):
        timer = Timer()
        timer.start("Teardown")
        self.projects.delete_project(self.project.get_uuid())
        timer.stop()
    
    def get_working_project(self):
        return self.project
            
    def get_projects_module(self):
        return self.projects
    
    def get_batches_module(self):
        return self.batches
    
    def get_groups_module(self):
        return self.groups
    
    def get_permissions_module(self):
        return self.permissions
    
    def get_rest(self):
        # Note, this is only necessary because batches are currently more than pure data
        # objects and therefore need a rest accessor (and aren't built here).
        # Please don't use this extensively.
        return self.rest