Source code for airflow.providers.fab.auth_manager.schemas.user_schema

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.
from __future__ import annotations

from typing import NamedTuple

from marshmallow import Schema, fields
from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field

from airflow.api_connexion.parameters import validate_istimezone
from airflow.providers.fab.auth_manager.models import User
from airflow.providers.fab.auth_manager.schemas.role_and_permission_schema import RoleSchema


[docs]class UserCollectionItemSchema(SQLAlchemySchema): """user collection item schema."""
[docs] class Meta: """Meta."""
[docs] model = User
[docs] dateformat = "iso"
[docs] first_name = auto_field()
[docs] last_name = auto_field()
[docs] username = auto_field()
[docs] active = auto_field(dump_only=True)
[docs] email = auto_field()
[docs] last_login = auto_field(dump_only=True)
[docs] login_count = auto_field(dump_only=True)
[docs] fail_login_count = auto_field(dump_only=True)
[docs] roles = fields.List(fields.Nested(RoleSchema, only=("name",)))
[docs] created_on = auto_field(validate=validate_istimezone, dump_only=True)
[docs] changed_on = auto_field(validate=validate_istimezone, dump_only=True)
[docs]class UserSchema(UserCollectionItemSchema): """User schema."""
[docs] password = auto_field(load_only=True)
[docs]class UserCollection(NamedTuple): """User collection."""
[docs] users: list[User]
[docs] total_entries: int
[docs]class UserCollectionSchema(Schema): """User collection schema."""
[docs] users = fields.List(fields.Nested(UserCollectionItemSchema))
[docs] total_entries = fields.Int()
[docs]user_collection_item_schema = UserCollectionItemSchema()
[docs]user_schema = UserSchema()
[docs]user_collection_schema = UserCollectionSchema()

Was this entry helpful?