Пример #1
0
def connect(
    user: str,
    database: str,
    password: str,
    port: int = 5439,
    host: str = "localhost",
    source_address: typing.Optional[str] = None,
    unix_sock: typing.Optional[str] = None,
    ssl: bool = True,
    sslmode: str = "verify-ca",
    timeout: typing.Optional[int] = None,
    max_prepared_statements: int = 1000,
    tcp_keepalive: bool = True,
    application_name: typing.Optional[str] = None,
    replication: typing.Optional[str] = None,
    idp_host: typing.Optional[str] = None,
    db_user: typing.Optional[str] = None,
    app_id: typing.Optional[str] = None,
    app_name: str = "amazon_aws_redshift",
    preferred_role: typing.Optional[str] = None,
    principal_arn: typing.Optional[str] = None,
    access_key_id: typing.Optional[str] = None,
    secret_access_key: typing.Optional[str] = None,
    session_token: typing.Optional[str] = None,
    profile: typing.Optional[str] = None,
    credentials_provider: typing.Optional[str] = None,
    region: typing.Optional[str] = None,
    cluster_identifier: typing.Optional[str] = None,
    iam: bool = False,
    client_id: typing.Optional[str] = None,
    idp_tenant: typing.Optional[str] = None,
    client_secret: typing.Optional[str] = None,
    partner_sp_id: typing.Optional[str] = None,
    idp_response_timeout: int = 120,
    listen_port: int = 7890,
    login_url: typing.Optional[str] = None,
    auto_create: bool = False,
    db_groups: typing.List[str] = list(),
    force_lowercase: bool = False,
    allow_db_user_override: bool = False,
    client_protocol_version: int = DEFAULT_PROTOCOL_VERSION,
    database_metadata_current_db_only: bool = True,
    ssl_insecure: typing.Optional[bool] = None,
    web_identity_token: typing.Optional[str] = None,
    role_session_name: typing.Optional[str] = None,
    role_arn: typing.Optional[str] = None,
) -> Connection:

    info: RedshiftProperty = RedshiftProperty()
    IamHelper.set_iam_properties(
        info,
        user=user,
        host=host,
        database=database,
        port=port,
        password=password,
        source_address=source_address,
        unix_sock=unix_sock,
        ssl=ssl,
        sslmode=sslmode,
        timeout=timeout,
        max_prepared_statements=max_prepared_statements,
        tcp_keepalive=tcp_keepalive,
        application_name=application_name,
        replication=replication,
        idp_host=idp_host,
        db_user=db_user,
        app_id=app_id,
        app_name=app_name,
        preferred_role=preferred_role,
        principal_arn=principal_arn,
        access_key_id=access_key_id,
        secret_access_key=secret_access_key,
        session_token=session_token,
        profile=profile,
        credentials_provider=credentials_provider,
        region=region,
        cluster_identifier=cluster_identifier,
        iam=iam,
        client_id=client_id,
        idp_tenant=idp_tenant,
        client_secret=client_secret,
        partner_sp_id=partner_sp_id,
        idp_response_timeout=idp_response_timeout,
        listen_port=listen_port,
        login_url=login_url,
        auto_create=auto_create,
        db_groups=db_groups,
        force_lowercase=force_lowercase,
        allow_db_user_override=allow_db_user_override,
        client_protocol_version=client_protocol_version,
        database_metadata_current_db_only=database_metadata_current_db_only,
        ssl_insecure=ssl_insecure,
        web_identity_token=web_identity_token,
        role_session_name=role_session_name,
        role_arn=role_arn,
    )

    return Connection(
        user=info.user_name,
        host=info.host,
        database=info.db_name,
        port=info.port,
        password=info.password,
        source_address=info.source_address,
        unix_sock=info.unix_sock,
        ssl=info.ssl,
        sslmode=info.sslmode,
        timeout=info.timeout,
        max_prepared_statements=info.max_prepared_statements,
        tcp_keepalive=info.tcp_keepalive,
        application_name=info.application_name,
        replication=info.replication,
        client_protocol_version=info.client_protocol_version,
        database_metadata_current_db_only=database_metadata_current_db_only,
    )
def test_set_iam_properties_fails_when_info_is_none(missing_param):
    keywords: typing.Dict = {missing_param: None}
    with pytest.raises(InterfaceError) as excinfo:
        IamHelper.set_iam_properties(**get_set_iam_properties_args(**keywords))
    assert "Invalid connection property setting" in str(excinfo.value)