예제 #1
0
def _ensure_auth_user(user_data: dict, company_id: str, log: Logger, revoke: bool = False):
    key, secret = user_data.get("key"), user_data.get("secret")
    if not (key and secret):
        credentials = None
    else:
        creds = Credentials(key=key, secret=secret)

        user = AuthUser.objects(credentials__match=creds).first()
        if user:
            if revoke:
                user.credentials = []
                user.save()
            return user.id

        credentials = [] if revoke else [creds]

    user_id = user_data.get("id", f"__{user_data['name']}__")

    log.info(f"Creating user: {user_data['name']}")

    user = AuthUser(
        id=user_id,
        name=user_data["name"],
        company=company_id,
        role=user_data["role"],
        email=user_data["email"],
        created=datetime.utcnow(),
        credentials=credentials,
    )

    user.save()

    return user.id
예제 #2
0
def _ensure_auth_user(user_data: dict,
                      company_id: str,
                      log: Logger,
                      revoke: bool = False):
    ensure_credentials = {"key", "secret"}.issubset(user_data)
    if ensure_credentials:
        user = AuthUser.objects(credentials__match=Credentials(
            key=user_data["key"], secret=user_data["secret"])).first()
        if user:
            if revoke:
                user.credentials = []
                user.save()
            return user.id

    user_id = user_data.get("id", f"__{user_data['name']}__")

    log.info(f"Creating user: {user_data['name']}")
    user = AuthUser(
        id=user_id,
        name=user_data["name"],
        company=company_id,
        role=user_data["role"],
        email=user_data["email"],
        created=datetime.utcnow(),
        credentials=[
            Credentials(key=user_data["key"], secret=user_data["secret"])
        ] if not revoke else [] if ensure_credentials else None,
    )

    user.save()

    return user.id
예제 #3
0
def _ensure_auth_user(user_data, company_id):
    ensure_credentials = {"key", "secret"}.issubset(user_data.keys())
    if ensure_credentials:
        user = AuthUser.objects(credentials__match=Credentials(
            key=user_data["key"], secret=user_data["secret"])).first()
        if user:
            return user.id

    log.info(f"Creating user: {user_data['name']}")
    user = AuthUser(
        id=user_data.get("id", f"__{user_data['name']}__"),
        name=user_data["name"],
        company=company_id,
        role=user_data["role"],
        email=user_data["email"],
        created=datetime.utcnow(),
        credentials=[
            Credentials(key=user_data["key"], secret=user_data["secret"])
        ] if ensure_credentials else None,
    )

    user.save()

    return user.id