class OrganizationsApi(object): """Implementation for '/api/v2/orgs' endpoint.""" def __init__(self, influxdb_client): """Initialize defaults.""" self._influxdb_client = influxdb_client self._organizations_service = OrganizationsService( influxdb_client.api_client) self._users_service = UsersService(influxdb_client.api_client) def me(self): """Return the current authenticated user.""" user = self._users_service.get_me() return user def find_organization(self, org_id): """Retrieve an organization.""" return self._organizations_service.get_orgs_id(org_id=org_id) def find_organizations(self): """List all organizations.""" return self._organizations_service.get_orgs().orgs def create_organization(self, name: str = None, organization: Organization = None) -> Organization: """Create an organization.""" if organization is None: organization = Organization(name=name) return self._organizations_service.post_orgs(organization=organization) def delete_organization(self, org_id: str): """Delete an organization.""" return self._organizations_service.delete_orgs_id(org_id=org_id)
class OrganizationsApi(object): """ The client of the InfluxDB 2.0 that implements Organizations HTTP API endpoint. """ def __init__(self, influxdb_client): self._influxdb_client = influxdb_client self._organizations_service = OrganizationsService(influxdb_client.api_client) self._users_service = UsersService(influxdb_client.api_client) def me(self): user = self._users_service.get_me() return user def find_organization(self, org_id): return self._organizations_service.get_orgs_id(org_id=org_id) def find_organizations(self): return self._organizations_service.get_orgs().orgs def create_organization(self, name: str = None, organization: Organization = None) -> Organization: if organization is None: organization = Organization(name=name) return self._organizations_service.post_orgs(organization=organization) def delete_organization(self, org_id: str): return self._organizations_service.delete_orgs_id(org_id=org_id)
class OrganizationsApi(object): """Implementation for '/api/v2/orgs' endpoint.""" def __init__(self, influxdb_client): """Initialize defaults.""" self._influxdb_client = influxdb_client self._organizations_service = OrganizationsService( influxdb_client.api_client) self._users_service = UsersService(influxdb_client.api_client) def me(self): """Return the current authenticated user.""" user = self._users_service.get_me() return user def find_organization(self, org_id): """Retrieve an organization.""" return self._organizations_service.get_orgs_id(org_id=org_id) def find_organizations(self, **kwargs): """ List all organizations. :key int offset: Offset for pagination :key int limit: Limit for pagination :key bool descending: :key str org: Filter organizations to a specific organization name. :key str org_id: Filter organizations to a specific organization ID. :key str user_id: Filter organizations to a specific user ID. """ return self._organizations_service.get_orgs(**kwargs).orgs def create_organization(self, name: str = None, organization: Organization = None) -> Organization: """Create an organization.""" if organization is None: organization = Organization(name=name) return self._organizations_service.post_orgs( post_organization_request=organization) def update_organization(self, organization: Organization) -> Organization: """Update an organization. :param organization: Organization update to apply (required) :return: Organization """ request = PatchOrganizationRequest( name=organization.name, description=organization.description) return self._organizations_service.patch_orgs_id( org_id=organization.id, patch_organization_request=request) def delete_organization(self, org_id: str): """Delete an organization.""" return self._organizations_service.delete_orgs_id(org_id=org_id)
class UsersApi(object): """Implementation for '/api/v2/users' endpoint.""" def __init__(self, influxdb_client): """Initialize defaults.""" self._influxdb_client = influxdb_client self._service = UsersService(influxdb_client.api_client) def me(self) -> User: """Return the current authenticated user.""" user = self._service.get_me() return user def create_user(self, name: str) -> User: """Create a user.""" user = User(name=name) return self._service.post_users(user=user) def update_user(self, user: User) -> UserResponse: """Update a user. :param user: User update to apply (required) :return: User """ return self._service.patch_users_id(user_id=user.id, user=user) def delete_user(self, user: Union[str, User, UserResponse]) -> None: """Delete a user. :param user: user id or User :return: User """ if isinstance(user, User): user_id = user.id elif isinstance(user, UserResponse): user_id = user.id else: user_id = user return self._service.delete_users_id(user_id=user_id) def find_users(self, **kwargs) -> Users: """List all users. :key int offset: Offset for pagination :key int limit: Limit for pagination :key str after: The last resource ID from which to seek from (but not including). This is to be used instead of `offset`. :key str name: The user name. :key str id: The user ID. :return: Buckets """ return self._service.get_users(**kwargs)
class UsersApi(object): def __init__(self, influxdb_client): self._influxdb_client = influxdb_client self._service = UsersService(influxdb_client.api_client) def me(self) -> User: user = self._service.get_me() return user def create_user(self, name: str) -> User: user = User(name=name) return self._service.post_users(user=user)
class UsersApi(object): """Implementation for '/api/v2/users' endpoint.""" def __init__(self, influxdb_client): """Initialize defaults.""" self._influxdb_client = influxdb_client self._service = UsersService(influxdb_client.api_client) def me(self) -> User: """Return the current authenticated user.""" user = self._service.get_me() return user def create_user(self, name: str) -> User: """Create a user.""" user = User(name=name) return self._service.post_users(user=user)