Ejemplo n.º 1
0
def entities_conflict_summary(conflicts: Dict[str, Dict[str, FrozenSet[str]]],
                              namespace: str) -> None:
    for k, field_values in conflicts.items():
        for field, errors in field_values.items():
            p1 = "they are" if len(errors) > 1 else "it is"
            log.error(
                '[appgate-operator/%s] Entity: %s references: [%s] (field %s), but %s not defined '
                'in the system.', namespace, k, ', '.join(errors), field, p1)
Ejemplo n.º 2
0
 async def request(
         self,
         verb: str,
         path: str,
         data: Optional[Dict[str, Any]] = None) -> Optional[Dict[str, Any]]:
     verbs = {
         'POST': self._session.post,
         'DELETE': self._session.delete,
         'PUT': self._session.put,
         'GET': self._session.get,
     }
     method = verbs.get(verb)
     if not method:
         raise AppgateException(f'Unknown HTTP method: {verb}')
     headers = {
         'Accept': f'application/vnd.appgate.peer-v{self.version}+json',
         'Content-Type': 'application/json'
     }
     auth_header = self.auth_header()
     if auth_header:
         headers['Authorization'] = auth_header
     url = f'{self.controller}/{path}'
     try:
         async with method(
                 url=url,  # type: ignore
                 headers=headers,
                 json=data,
                 ssl=self.ssl_context,
                 verify_ssl=not self.no_verify) as resp:
             status_code = resp.status // 100
             if status_code == 2:
                 if resp.status == 204:
                     return {}
                 else:
                     return await resp.json()
             else:
                 error_data = await resp.text()
                 log.error('[aggpate-client] %s :: %s: %s', url,
                           resp.status, error_data)
                 if data:
                     log.error('[appgate-client] payload :: %s', data)
                 raise AppgateException(
                     f'Error: [{method} {url} {resp.status}] {error_data}')
     except InvalidURL:
         log.error('[appgate-client] Error preforming query: %s', url)
         raise AppgateException(f'Error: [{method} {url}] InvalidURL')
     except ClientConnectorCertificateError as e:
         log.error(
             '[appgate-client] Certificate error when connecting to %s: %s',
             e.host, e.certificate_error)
         raise AppgateException(f'Error: {e.certificate_error}')
     except ClientConnectorError as e:
         log.error(
             '[appgate-client] Error establishing connection with %s: %s',
             e.host, e.strerror)
         raise AppgateException(f'Error: {e.strerror}')
Ejemplo n.º 3
0
def load_latest_entity_generation(key: str,
                                  value: str) -> LatestEntityGeneration:
    try:
        generation, modified = value.split(',', maxsplit=2)
        return LatestEntityGeneration(generation=int(generation),
                                      modified=parse_datetime(modified))
    except Exception:
        log.error(
            'Error getting entry from configmap entry %s, defaulting to generation 0',
            key)
        return LatestEntityGeneration()
Ejemplo n.º 4
0
 async def post(self, entity: Entity_T) -> Optional[Entity_T]:
     log.info('[appgate-client/%s] POST %s [%s]', entity.__class__.__name__,
              entity.name, entity.id)
     body = self.dump(entity)
     body['id'] = entity.id
     data = await self._client.post(self.path, body=body)
     if not data:
         log.error(
             '[aggpate-client] POST %s :: Expecting a response but we got empty data',
             self.path)
         return None
     return self.load(data)  # type: ignore
Ejemplo n.º 5
0
 async def get(self) -> Optional[List[Entity_T]]:
     data = await self._client.get(self.path)
     if not data:
         log.error(
             '[aggpate-client] GET %s :: Expecting a response but we got empty data',
             self.path)
         return None
     # TODO: We should discover this from the api spec
     if 'data' in data:
         return [self.load(e) for e in data['data']]
     else:
         return [self.load(data)]
Ejemplo n.º 6
0
 def with_entity(self, entity: EntityWrapper, op: str,
                 current_appgate_state: 'AppgateState') -> None:
     """
     Get the entity with op and register in the current state
     These entities are coming from k8s so they don't have any id
     """
     entities_fn = lambda state: state.entities_set.get(
         type(entity.value).__name__)
     entities = entities_fn(self)
     current_entities = entities_fn(current_appgate_state)
     if not entities or not current_entities:
         log.error('[appgate-operator] Unknown entity type: %s',
                   type(entity))
         return
     # TODO: Fix linter here!
     entities_op(entities, entity, op, current_entities)  # type: ignore