예제 #1
0
 def __init__(self, api_server_url: str = None, refresh_token: str = None, debug: bool = False,
              log: logging.Logger = None) -> None:
     self._debug = debug
     self._log = log
     self._progress_callback = None
     self._access_token = None
     self._api_url = self._normalize_url(api_server_url or os.getenv('BANYAN_API_URL')
                                         or BanyanApiClient.DEFAULT_API_URL)
     self._refresh_token = refresh_token or os.getenv('BANYAN_REFRESH_TOKEN')
     if not self._refresh_token:
         raise BanyanError("Refresh token must be set")
     if self._debug:
         requests_log = logging.getLogger('requests.packages.urllib3')
         requests_log.setLevel(logging.DEBUG)
         requests_log.propagate = True
     self._http = self._create_session()
     self._services = ServiceAPI(self)
     self._policies = PolicyAPI(self)
     self._attach = AttachmentAPI(self)
     self._roles = RoleAPI(self)
     self._shields = ShieldAPI(self)
     self._agents = NetagentAPI(self)
     self._users = UserAPI(self)
     self._devices = DeviceAPI(self)
     self._events = EventV2API(self)
     self._audit = AuditAPI(self)
예제 #2
0
 def detach(self, policy: PolicyInfoOrName, service: ServiceInfoOrName) -> str:
     from banyan.api.service import ServiceAPI
     policy = self.find(policy)
     service = ServiceAPI(self._client).find(service)
     json_response = self._client.api_request('DELETE', '/delete_security_attach_policy',
                                              params={
                                                  'PolicyID': policy.id,
                                                  'ServiceID': service.id
                                              })
     return json_response['Message']
예제 #3
0
 def attach(self, policy: PolicyInfoOrName, service: ServiceInfoOrName, enforcing: bool) -> PolicyAttachInfo:
     from banyan.api.service import ServiceAPI
     policy = self.find(policy)
     service = ServiceAPI(self._client).find(service)
     json_response = self._client.api_request('POST', '/insert_security_attach_policy',
                                              params={
                                                  'PolicyID': policy.id,
                                                  'ServiceID': service.id,
                                                  'Enabled': str(enforcing).upper()
                                              })
     return PolicyAttachInfo.Schema().load(json_response)