# Copyright 2020 StrongDM Inc
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 

# This file was generated by protogen. DO NOT EDIT.

import grpc
from . import plumbing
from . import models
from .options_pb2 import *
from .options_pb2_grpc import *
from .spec_pb2 import *
from .spec_pb2_grpc import *
from .account_attachments_pb2 import *
from .account_attachments_pb2_grpc import *
from .account_grants_pb2 import *
from .account_grants_pb2_grpc import *
from .accounts_pb2 import *
from .accounts_pb2_grpc import *
from .drivers_pb2 import *
from .drivers_pb2_grpc import *
from .nodes_pb2 import *
from .nodes_pb2_grpc import *
from .resources_pb2 import *
from .resources_pb2_grpc import *
from .role_attachments_pb2 import *
from .role_attachments_pb2_grpc import *
from .role_grants_pb2 import *
from .role_grants_pb2_grpc import *
from .roles_pb2 import *
from .roles_pb2_grpc import *
class AccountAttachments:
    """AccountAttachments assign an account to a role."""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = AccountAttachmentsStub(channel)
    def create(self,
        account_attachment,
        options=None,
        timeout=None):
        """Create registers a new AccountAttachment."""
        req = AccountAttachmentCreateRequest()
			
        if account_attachment is not None:
            req.account_attachment.CopyFrom(plumbing.account_attachment_to_plumbing(account_attachment))
        if options is not None:
            req.options.CopyFrom(plumbing.account_attachment_create_options_to_plumbing(options))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('AccountAttachments.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountAttachmentCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account_attachment = plumbing.account_attachment_to_porcelain(plumbing_response.account_attachment)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one AccountAttachment by ID."""
        req = AccountAttachmentGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('AccountAttachments.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountAttachmentGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account_attachment = plumbing.account_attachment_to_porcelain(plumbing_response.account_attachment)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a AccountAttachment by ID."""
        req = AccountAttachmentDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('AccountAttachments.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountAttachmentDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of AccountAttachments matching a given set of criteria."""
        req = AccountAttachmentListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('AccountAttachments.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.account_attachments:
                    yield plumbing.account_attachment_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class AccountGrants:
    """AccountGrants connect a resource directly to an account, giving the account the permission to connect to that resource."""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = AccountGrantsStub(channel)
    def create(self,
        account_grant,
        timeout=None):
        """Create registers a new AccountGrant."""
        req = AccountGrantCreateRequest()
			
        if account_grant is not None:
            req.account_grant.CopyFrom(plumbing.account_grant_to_plumbing(account_grant))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('AccountGrants.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountGrantCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account_grant = plumbing.account_grant_to_porcelain(plumbing_response.account_grant)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one AccountGrant by ID."""
        req = AccountGrantGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('AccountGrants.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountGrantGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account_grant = plumbing.account_grant_to_porcelain(plumbing_response.account_grant)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a AccountGrant by ID."""
        req = AccountGrantDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('AccountGrants.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountGrantDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of AccountGrants matching a given set of criteria."""
        req = AccountGrantListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('AccountGrants.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.account_grants:
                    yield plumbing.account_grant_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class Accounts:
    """Accounts are users that have access to strongDM.
 There are two types of accounts:
 1. **Regular users:** humans who are authenticated through username and password or SSO
 2. **Service users:** machines that are authneticated using a service token"""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = AccountsStub(channel)
    def create(self,
        account,
        timeout=None):
        """Create registers a new Account."""
        req = AccountCreateRequest()
			
        if account is not None:
            req.account.CopyFrom(plumbing.account_to_plumbing(account))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('Accounts.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account = plumbing.account_to_porcelain(plumbing_response.account)
        resp.token = plumbing_response.token
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one Account by ID."""
        req = AccountGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('Accounts.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account = plumbing.account_to_porcelain(plumbing_response.account)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def update(self,
        account,
        timeout=None):
        """Update patches a Account by ID."""
        req = AccountUpdateRequest()
			
        if account is not None:
            req.account.CopyFrom(plumbing.account_to_plumbing(account))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Update(req, metadata=self.parent.get_metadata('Accounts.Update', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountUpdateResponse()
        resp.meta = plumbing.update_response_metadata_to_porcelain(plumbing_response.meta)
        resp.account = plumbing.account_to_porcelain(plumbing_response.account)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a Account by ID."""
        req = AccountDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('Accounts.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.AccountDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of Accounts matching a given set of criteria."""
        req = AccountListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('Accounts.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.accounts:
                    yield plumbing.account_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class Nodes:
    """Nodes make up the strongDM network, and allow your users to connect securely to your resources.
 There are two types of nodes:
 1. **Relay:** creates connectivity to your datasources, while maintaining the egress-only nature of your firewall
 1. **Gateways:** a relay that also listens for connections from strongDM clients"""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = NodesStub(channel)
    def create(self,
        node,
        timeout=None):
        """Create registers a new Node."""
        req = NodeCreateRequest()
			
        if node is not None:
            req.node.CopyFrom(plumbing.node_to_plumbing(node))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('Nodes.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.NodeCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.node = plumbing.node_to_porcelain(plumbing_response.node)
        resp.token = plumbing_response.token
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one Node by ID."""
        req = NodeGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('Nodes.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.NodeGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.node = plumbing.node_to_porcelain(plumbing_response.node)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def update(self,
        node,
        timeout=None):
        """Update patches a Node by ID."""
        req = NodeUpdateRequest()
			
        if node is not None:
            req.node.CopyFrom(plumbing.node_to_plumbing(node))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Update(req, metadata=self.parent.get_metadata('Nodes.Update', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.NodeUpdateResponse()
        resp.meta = plumbing.update_response_metadata_to_porcelain(plumbing_response.meta)
        resp.node = plumbing.node_to_porcelain(plumbing_response.node)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a Node by ID."""
        req = NodeDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('Nodes.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.NodeDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of Nodes matching a given set of criteria."""
        req = NodeListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('Nodes.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.nodes:
                    yield plumbing.node_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class Resources:
    """"""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = ResourcesStub(channel)
    def create(self,
        resource,
        timeout=None):
        """Create registers a new Resource."""
        req = ResourceCreateRequest()
			
        if resource is not None:
            req.resource.CopyFrom(plumbing.resource_to_plumbing(resource))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('Resources.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.ResourceCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.resource = plumbing.resource_to_porcelain(plumbing_response.resource)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one Resource by ID."""
        req = ResourceGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('Resources.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.ResourceGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.resource = plumbing.resource_to_porcelain(plumbing_response.resource)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def update(self,
        resource,
        timeout=None):
        """Update patches a Resource by ID."""
        req = ResourceUpdateRequest()
			
        if resource is not None:
            req.resource.CopyFrom(plumbing.resource_to_plumbing(resource))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Update(req, metadata=self.parent.get_metadata('Resources.Update', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.ResourceUpdateResponse()
        resp.meta = plumbing.update_response_metadata_to_porcelain(plumbing_response.meta)
        resp.resource = plumbing.resource_to_porcelain(plumbing_response.resource)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a Resource by ID."""
        req = ResourceDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('Resources.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.ResourceDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of Resources matching a given set of criteria."""
        req = ResourceListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('Resources.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.resources:
                    yield plumbing.resource_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class RoleAttachments:
    """RoleAttachments represent relationships between composite roles and the roles
 that make up those composite roles. When a composite role is attached to another
 role, the permissions granted to members of the composite role are augmented to
 include the permissions granted to members of the attached role."""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = RoleAttachmentsStub(channel)
    def create(self,
        role_attachment,
        timeout=None):
        """Create registers a new RoleAttachment."""
        req = RoleAttachmentCreateRequest()
			
        if role_attachment is not None:
            req.role_attachment.CopyFrom(plumbing.role_attachment_to_plumbing(role_attachment))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('RoleAttachments.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleAttachmentCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role_attachment = plumbing.role_attachment_to_porcelain(plumbing_response.role_attachment)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one RoleAttachment by ID."""
        req = RoleAttachmentGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('RoleAttachments.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleAttachmentGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role_attachment = plumbing.role_attachment_to_porcelain(plumbing_response.role_attachment)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a RoleAttachment by ID."""
        req = RoleAttachmentDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('RoleAttachments.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleAttachmentDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of RoleAttachments matching a given set of criteria."""
        req = RoleAttachmentListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('RoleAttachments.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.role_attachments:
                    yield plumbing.role_attachment_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class RoleGrants:
    """RoleGrants represent relationships between composite roles and the roles
 that make up those composite roles. When a composite role is attached to another
 role, the permissions granted to members of the composite role are augmented to
 include the permissions granted to members of the attached role."""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = RoleGrantsStub(channel)
    def create(self,
        role_grant,
        timeout=None):
        """Create registers a new RoleGrant."""
        req = RoleGrantCreateRequest()
			
        if role_grant is not None:
            req.role_grant.CopyFrom(plumbing.role_grant_to_plumbing(role_grant))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('RoleGrants.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleGrantCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role_grant = plumbing.role_grant_to_porcelain(plumbing_response.role_grant)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one RoleGrant by ID."""
        req = RoleGrantGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('RoleGrants.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleGrantGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role_grant = plumbing.role_grant_to_porcelain(plumbing_response.role_grant)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a RoleGrant by ID."""
        req = RoleGrantDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('RoleGrants.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleGrantDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of RoleGrants matching a given set of criteria."""
        req = RoleGrantListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('RoleGrants.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.role_grants:
                    yield plumbing.role_grant_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
class Roles:
    """Roles are tools for controlling user access to resources. Each Role holds a
 list of resources which they grant access to. Composite roles are a special
 type of Role which have no resource associations of their own, but instead
 grant access to the combined resources associated with a set of child roles.
 Each user can be a member of one Role or composite role."""
    def __init__(self, channel, client):
        self.parent = client
        self.stub = RolesStub(channel)
    def create(self,
        role,
        timeout=None):
        """Create registers a new Role."""
        req = RoleCreateRequest()
			
        if role is not None:
            req.role.CopyFrom(plumbing.role_to_plumbing(role))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Create(req, metadata=self.parent.get_metadata('Roles.Create', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleCreateResponse()
        resp.meta = plumbing.create_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role = plumbing.role_to_porcelain(plumbing_response.role)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def get(self,
        id,
        timeout=None):
        """Get reads one Role by ID."""
        req = RoleGetRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Get(req, metadata=self.parent.get_metadata('Roles.Get', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleGetResponse()
        resp.meta = plumbing.get_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role = plumbing.role_to_porcelain(plumbing_response.role)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def update(self,
        role,
        timeout=None):
        """Update patches a Role by ID."""
        req = RoleUpdateRequest()
			
        if role is not None:
            req.role.CopyFrom(plumbing.role_to_plumbing(role))
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Update(req, metadata=self.parent.get_metadata('Roles.Update', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleUpdateResponse()
        resp.meta = plumbing.update_response_metadata_to_porcelain(plumbing_response.meta)
        resp.role = plumbing.role_to_porcelain(plumbing_response.role)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def delete(self,
        id,
        timeout=None):
        """Delete removes a Role by ID."""
        req = RoleDeleteRequest()
			
        req.id = id
        tries = 0
        plumbing_response = None
        while True:
            try:
                plumbing_response = self.stub.Delete(req, metadata=self.parent.get_metadata('Roles.Delete', req), timeout=timeout)
            except Exception as e:
                if self.parent.shouldRetry(tries, e):
                    tries += 1
                    self.parent.jitterSleep(tries)
                    continue
                raise plumbing.error_to_porcelain(e) from e
            break

			
        resp = models.RoleDeleteResponse()
        resp.meta = plumbing.delete_response_metadata_to_porcelain(plumbing_response.meta)
        resp.rate_limit = plumbing.rate_limit_metadata_to_porcelain(plumbing_response.rate_limit)
        return resp
    def list(self,
        filter,
        *args,
        timeout=None):
        """List gets a list of Roles matching a given set of criteria."""
        req = RoleListRequest()
        req.meta.CopyFrom(ListRequestMetadata())
        page_size_option = self.parent._test_options.get('PageSize')
        if isinstance(page_size_option, int):
            req.meta.limit = page_size_option
			
        req.filter = plumbing.quote_filter_args(filter, *args)
        def generator(svc, req):
            tries = 0
            while True:
                try:
                    plumbing_response = svc.stub.List(req, metadata= svc.parent.get_metadata('Roles.List',req), timeout=timeout)
                except Exception as e:
                    if self.parent.shouldRetry(tries, e):
                        tries += 1
                        self.parent.jitterSleep(tries)
                        continue
                    raise plumbing.error_to_porcelain(e) from e
                tries = 0
                for plumbing_item in plumbing_response.roles:
                    yield plumbing.role_to_porcelain(plumbing_item)
                if plumbing_response.meta.next_cursor == '':
                    break
                req.meta.cursor = plumbing_response.meta.next_cursor
        return generator(self, req)
