Revision 47bb45c0

b/astakosclient/astakosclient/__init__.py
69 69
API_COMMISSIONS = join_urls(ACCOUNTS_PREFIX, "commissions")
70 70
API_COMMISSIONS_ACTION = join_urls(API_COMMISSIONS, "action")
71 71
API_FEEDBACK = join_urls(ACCOUNTS_PREFIX, "feedback")
72
API_PROJECTS = join_urls(ACCOUNTS_PREFIX, "projects")
73
API_APPLICATIONS = join_urls(API_PROJECTS, "apps")
74
API_MEMBERSHIPS = join_urls(API_PROJECTS, "memberships")
72 75

  
73 76
# --------------------------------------------------------------------
74 77
# Astakos Keystone API urls
......
575 578
                                 self.logger)
576 579
        return self._call_astakos(token, path, req_headers, req_body, "POST")
577 580

  
581
    # ----------------------------
582
    # do a GET to ``API_PROJECTS``
583
    def get_projects(self, token, name=None, state=None, owner=None):
584
        """Retrieve all accessible projects
585

  
586
        Arguments:
587
        token -- user's token (string)
588
        name  -- filter by name (optional)
589
        state -- filter by state (optional)
590
        owner -- filter by owner (optional)
591

  
592
        In case of success, return a list of project descriptions.
593
        """
594
        path = API_PROJECTS
595
        filters = {}
596
        if name is not None:
597
            filters["name"] = name
598
        if state is not None:
599
            filters["state"] = state
600
        if owner is not None:
601
            filters["owner"] = owner
602
        req_headers = {'content-type': 'application/json'}
603
        req_body = (parse_request({"filter": filters}, self.logger)
604
                    if filters else None)
605
        return self._call_astakos(token, path, req_headers, req_body)
606

  
607
    # -----------------------------------------
608
    # do a GET to ``API_PROJECTS``/<project_id>
609
    def get_project(self, token, project_id):
610
        """Retrieve project description, if accessible
611

  
612
        Arguments:
613
        token      -- user's token (string)
614
        project_id -- project identifier
615

  
616
        In case of success, return project description.
617
        """
618
        path = join_urls(API_PROJECTS, str(project_id))
619
        return self._call_astakos(token, path)
620

  
621
    # -----------------------------
622
    # do a POST to ``API_PROJECTS``
623
    def create_project(self, token, specs):
624
        """Submit application to create a new project
625

  
626
        Arguments:
627
        token -- user's token (string)
628
        specs -- dict describing a project
629

  
630
        In case of success, return project and application identifiers.
631
        """
632
        path = API_PROJECTS
633
        req_headers = {'content-type': 'application/json'}
634
        req_body = parse_request(specs, self.logger)
635
        return self._call_astakos(token, path, req_headers, req_body, "POST")
636

  
637
    # ------------------------------------------
638
    # do a POST to ``API_PROJECTS``/<project_id>
639
    def modify_project(self, token, project_id, specs):
640
        """Submit application to modify an existing project
641

  
642
        Arguments:
643
        token      -- user's token (string)
644
        project_id -- project identifier
645
        specs      -- dict describing a project
646

  
647
        In case of success, return project and application identifiers.
648
        """
649
        path = join_urls(API_PROJECTS, str(project_id))
650
        req_headers = {'content-type': 'application/json'}
651
        req_body = parse_request(specs, self.logger)
652
        return self._call_astakos(token, path, req_headers, req_body, "POST")
653

  
654
    # -------------------------------------------------
655
    # do a POST to ``API_PROJECTS``/<project_id>/action
656
    def project_action(self, token, project_id, action, reason=""):
657
        """Perform action on a project
658

  
659
        Arguments:
660
        token      -- user's token (string)
661
        project_id -- project identifier
662
        action     -- action to perform, one of "suspend", "unsuspend",
663
                      "terminate", "reinstate"
664
        reason     -- reason of performing the action
665

  
666
        In case of success, return nothing.
667
        """
668
        path = join_urls(API_PROJECTS, str(project_id))
669
        path = join_urls(path, "action")
670
        req_headers = {'content-type': 'application/json'}
671
        req_body = parse_request({action: reason}, self.logger)
672
        return self._call_astakos(token, path, req_headers, req_body, "POST")
673

  
674
    # --------------------------------
675
    # do a GET to ``API_APPLICATIONS``
676
    def get_applications(self, token, project=None):
677
        """Retrieve all accessible applications
678

  
679
        Arguments:
680
        token   -- user's token (string)
681
        project -- filter by project (optional)
682

  
683
        In case of success, return a list of application descriptions.
684
        """
685
        path = API_APPLICATIONS
686
        req_headers = {'content-type': 'application/json'}
687
        body = {"project": project} if project is not None else None
688
        req_body = parse_request(body, self.logger) if body else None
689
        return self._call_astakos(token, path, req_headers, req_body)
690

  
691
    # -----------------------------------------
692
    # do a GET to ``API_APPLICATIONS``/<app_id>
693
    def get_application(self, token, app_id):
694
        """Retrieve application description, if accessible
695

  
696
        Arguments:
697
        token  -- user's token (string)
698
        app_id -- application identifier
699

  
700
        In case of success, return application description.
701
        """
702
        path = join_urls(API_APPLICATIONS, str(app_id))
703
        return self._call_astakos(token, path)
704

  
705
    # -------------------------------------------------
706
    # do a POST to ``API_APPLICATIONS``/<app_id>/action
707
    def application_action(self, token, app_id, action, reason=""):
708
        """Perform action on an application
709

  
710
        Arguments:
711
        token  -- user's token (string)
712
        app_id -- application identifier
713
        action -- action to perform, one of "approve", "deny",
714
                  "dismiss", "cancel"
715
        reason -- reason of performing the action
716

  
717
        In case of success, return nothing.
718
        """
719
        path = join_urls(API_APPLICATIONS, str(app_id))
720
        path = join_urls(path, "action")
721
        req_headers = {'content-type': 'application/json'}
722
        req_body = parse_request({action: reason}, self.logger)
723
        return self._call_astakos(token, path, req_headers, req_body, "POST")
724

  
725
    # -------------------------------
726
    # do a GET to ``API_MEMBERSHIPS``
727
    def get_memberships(self, token, project=None):
728
        """Retrieve all accessible memberships
729

  
730
        Arguments:
731
        token   -- user's token (string)
732
        project -- filter by project (optional)
733

  
734
        In case of success, return a list of membership descriptions.
735
        """
736
        path = API_MEMBERSHIPS
737
        req_headers = {'content-type': 'application/json'}
738
        body = {"project": project} if project is not None else None
739
        req_body = parse_request(body, self.logger) if body else None
740
        return self._call_astakos(token, path, req_headers, req_body)
741

  
742
    # -----------------------------------------
743
    # do a GET to ``API_MEMBERSHIPS``/<memb_id>
744
    def get_membership(self, token, memb_id):
745
        """Retrieve membership description, if accessible
746

  
747
        Arguments:
748
        token   -- user's token (string)
749
        memb_id -- membership identifier
750

  
751
        In case of success, return membership description.
752
        """
753
        path = join_urls(API_MEMBERSHIPS, str(memb_id))
754
        return self._call_astakos(token, path)
755

  
756
    # -------------------------------------------------
757
    # do a POST to ``API_MEMBERSHIPS``/<memb_id>/action
758
    def membership_action(self, token, memb_id, action, reason=""):
759
        """Perform action on a membership
760

  
761
        Arguments:
762
        token   -- user's token (string)
763
        memb_id -- membership identifier
764
        action  -- action to perform, one of "leave", "cancel", "accept",
765
                   "reject", "remove"
766
        reason  -- reason of performing the action
767

  
768
        In case of success, return nothing.
769
        """
770
        path = join_urls(API_MEMBERSHIPS, str(memb_id))
771
        path = join_urls(path, "action")
772
        req_headers = {'content-type': 'application/json'}
773
        req_body = parse_request({action: reason}, self.logger)
774
        return self._call_astakos(token, path, req_headers, req_body, "POST")
775

  
776
    # --------------------------------
777
    # do a POST to ``API_MEMBERSHIPS``
778
    def join_project(self, token, project_id):
779
        """Join a project
780

  
781
        Arguments:
782
        token      -- user's token (string)
783
        project_id -- project identifier
784

  
785
        In case of success, return membership identifier.
786
        """
787
        path = API_MEMBERSHIPS
788
        req_headers = {'content-type': 'application/json'}
789
        body = {"join": {"project": project_id}}
790
        req_body = parse_request(body, self.logger)
791
        return self._call_astakos(token, path, req_headers, req_body, "POST")
792

  
793
    # --------------------------------
794
    # do a POST to ``API_MEMBERSHIPS``
795
    def enroll_member(self, token, project_id, email):
796
        """Enroll a user in a project
797

  
798
        Arguments:
799
        token      -- user's token (string)
800
        project_id -- project identifier
801
        email      -- user identified by email
802

  
803
        In case of success, return membership identifier.
804
        """
805
        path = API_MEMBERSHIPS
806
        req_headers = {'content-type': 'application/json'}
807
        body = {"enroll": {"project": project_id, "user": email}}
808
        req_body = parse_request(body, self.logger)
809
        return self._call_astakos(token, path, req_headers, req_body, "POST")
578 810

  
579 811
# --------------------------------------------------------------------
580 812
# Private functions
b/astakosclient/docs/index.rst
192 192
        resolved.
193 193
        Otherwise raise an AstakosClientException exception.
194 194

  
195
    **get_projects(**\ token, name=None, state=None, owner=None\ **)**
196
        Retrieve all accessible projects
197

  
198
    **get_project(**\ token, project_id\ **)**
199
        Retrieve project description, if accessible
200

  
201
    **create_project(**\ token, specs\ **)**
202
        Submit application to create a new project
203

  
204
    **modify_project(**\ token, project_id, specs\ **)**
205
        Submit application to modify an existing project
206

  
207
    **project_action(**\ token, project_id, action, reason=""\ **)**
208
        Perform action on a project
209

  
210
    **get_applications(**\ token, project=None\ **)**
211
        Retrieve all accessible applications
212

  
213
    **get_application(**\ token, app_id\ **)**
214
        Retrieve application description, if accessible
215

  
216
    **application_action(**\ token, app_id, action, reason=""\ **)**
217
        Perform action on an application
218

  
219
    **get_memberships(**\ token, project=None\ **)**
220
        Retrieve all accessible memberships
221

  
222
    **get_membership(**\ token, memb_id\ **)**
223
        Retrieve membership description, if accessible
224

  
225
    **membership_action(**\ token, memb_id, action, reason=""\ **)**
226
        Perform action on a membership
227

  
228
    **join_project(**\ token, project_id\ **)**
229
        Join a project
230

  
231
    **enroll_member(**\ token, project_id, email\ **)**
232
        Enroll a user in a project
195 233

  
196 234
Public Functions
197 235
----------------

Also available in: Unified diff