How to use the pyral.context.RallyContext function in pyral

To help you get started, we’ve selected a few pyral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
# the workspaces and projects this user has access to (and their defaults)
        self._subs_name        = ""
        self._subs_workspaces  = []  # a list of Workspace "shell" objects
        self._workspaces       = []
        self._workspace_ref    = {}
        self._workspace_inflated = {}
        self._defaultWorkspace = None
        self._currentWorkspace = None
        self._inflated         = False

        self._projects         = {}  # key by workspace name with list of projects per workspace
        self._project_ref      = {}  # key by workspace name with dict of project_name: project_ref
        self._project_path     = {}  # keyed by project ref, value is "base // intermed // leaf", only for "pathed" projects
        self._defaultProject   = None
        self._currentProject   = None
        self.context           = RallyContext(server, user, password, self.agent.serviceURL())
        self.defaultContext    = self.context # to be updated on check call 
        self.operatingContext  = self.context # to be updated on check call
github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
if not self._workspaces:
            self._workspaces    = [self._defaultWorkspace]
        if not self._projects:
            self._projects      = {self._defaultWorkspace : [self._defaultProject]}
        if not self._workspace_ref:
            wksp_name, wkspace_ref = self.getWorkspace()
            short_ref = "/".join(wkspace_ref.split('/')[-2:])  # we only need the 'workspace/' part to be a valid ref
            self._workspace_ref = {self._defaultWorkspace : short_ref}
        if not self._project_ref:
            short_ref = "/".join(proj_ref.split('/')[-2:])  # we only need the 'project/' part to be a valid ref
            self._project_ref   = {self._defaultWorkspace : {self._defaultProject : short_ref}}

        self.defaultContext   = RallyContext(self.server, self.user, self.password,
                                             self.agent.serviceURL(), subscription=self._subs_name,
                                             workspace=self._defaultWorkspace, project=self._defaultProject)
        self.operatingContext = RallyContext(self.server, self.user, self.password,
                                             self.agent.serviceURL(), subscription=self._subs_name,
                                             workspace=self._currentWorkspace, project=self._currentProject)
        self.context = self.operatingContext 
##
github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
##        print("   Default Workspace : %s" % self._defaultWorkspace)
##        print("   Default Project   : %s" % self._defaultProject)
##
        if not self._workspaces:
            self._workspaces    = [self._defaultWorkspace]
        if not self._projects:
            self._projects      = {self._defaultWorkspace : [self._defaultProject]}
        if not self._workspace_ref:
            wksp_name, wkspace_ref = self.getWorkspace()
            short_ref = "/".join(wkspace_ref.split('/')[-2:])  # we only need the 'workspace/' part to be a valid ref
            self._workspace_ref = {self._defaultWorkspace : short_ref}
        if not self._project_ref:
            short_ref = "/".join(proj_ref.split('/')[-2:])  # we only need the 'project/' part to be a valid ref
            self._project_ref   = {self._defaultWorkspace : {self._defaultProject : short_ref}}

        self.defaultContext   = RallyContext(self.server, self.user, self.password,
                                             self.agent.serviceURL(), subscription=self._subs_name,
                                             workspace=self._defaultWorkspace, project=self._defaultProject)
        self.operatingContext = RallyContext(self.server, self.user, self.password,
                                             self.agent.serviceURL(), subscription=self._subs_name,
                                             workspace=self._currentWorkspace, project=self._currentProject)
        self.context = self.operatingContext 
##
github RallyTools / RallyRestToolkitForPython / pyral / restapi.py View on Github external
elif (type(fetch) == bytes or type(fetch) == str) and fetch.lower() != 'false':
            self.hydration = "full"
        elif type(fetch) == tuple and len(fetch) == 1 and fetch[0].count(',') > 0:
            fetch = fetch[0]
        elif type(fetch) in [list, tuple]:
            field_dict = dict([(attr_name, True) for attr_name in fetch]) 
            attr_info = self.validateAttributeNames(entity, field_dict) 
            fetch = ",".join(k for k in list(attr_info.keys()))
            self.hydration = "full"

        entity = self._officialRallyEntityName(entity)
        resource = RallyUrlBuilder(entity)
        resource.qualify(fetch, query, order, pagesize, startIndex)

        if '_disableAugments' in kwargs:
            context = RallyContext(self.server, self.user, self.password or self.apikey, self.service_url)
        else:
            context, augments = self.contextHelper.identifyContext(**kwargs)
            workspace_ref = self.contextHelper.currentWorkspaceRef()
            project_ref   = self.contextHelper.currentProjectRef()
            if workspace_ref:   # TODO: would we ever _not_ have a workspace_ref?
                if 'workspace' not in kwargs or ('workspace' in kwargs and kwargs['workspace'] is not None):
                    resource.augmentWorkspace(augments, workspace_ref)
                    if project_ref:
                        if 'project' not in kwargs or ('project' in kwargs and kwargs['project'] is not None):
                            resource.augmentProject(augments, project_ref)
                            resource.augmentScoping(augments)
        resource = resource.build()  # can also use resource = resource.build(pretty=True)
        full_resource_url = "%s/%s" % (self.service_url, resource)

        return context, resource, full_resource_url, limit