Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-rds): "DatabaseSecret" is incompatible with protocol "ISecret" #27852

Closed
anentropic opened this issue Nov 6, 2023 · 5 comments
Closed
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort language/python Related to Python bindings p2

Comments

@anentropic
Copy link

anentropic commented Nov 6, 2023

Describe the bug

I get a type error when passing DatabaseSecret in places where a DatabaseSecret is expected

Expected Behavior

rds.Credentials.from_secret(db_secret)

docstring for from_secret says "Creates Credentials from an existing Secrets Manager Secret (or DatabaseSecret)."

so I should be able to pass a DatabaseSecret without getting a type error

Current Behavior

Error from Pyright in VS Code:

Argument of type "DatabaseSecret" cannot be assigned to parameter "secret" of type "ISecret" in function "from_secret"
"DatabaseSecret" is incompatible with protocol "ISecret"
"secret_value_from_json" is an incompatible type
Type "(json_field: str) -> SecretValue" cannot be assigned to type "(key: str) -> SecretValue"
Parameter name mismatch: "key" versus "json_field"PylancereportGeneralTypeIssues

Reproduction Steps

from aws_cdk import (
    Stack,
    aws_ec2 as ec2,
    aws_rds as rds,
)

class MyStack(Stack):
    def __init__(
        self,
        scope: Construct,
        id: str,
        db_name: str,
        **kwargs,
    ):
        super().__init__(scope, id, **kwargs)
        vpc = ec2.Vpc.from_lookup(self, "VPC", is_default=True)
        db_admin = rds.DatabaseSecret(
            self,
            "DB Connection Secret",
            username="admin",
            dbname=db_name,
        )
        database = rds.DatabaseInstance(
            self,
            "MySQL",
            engine=rds.DatabaseInstanceEngine.mysql(
                version=rds.MysqlEngineVersion.VER_8_0
            ),
            vpc=vpc,
            credentials=rds.Credentials.from_secret(db_admin),  # error here
        )
        database.add_rotation_multi_user(
            "DB Credential Rotation",
            secret=db_admin,  # error here
        )

Possible Solution

I guess make the naming consistent with the interface it's supposed to implement

Additional Information/Context

No response

CDK CLI Version

2.104.0 (build 3b99abe)

Framework Version

2.102.0

Node.js Version

v18.18.0

OS

macOS 14.1

Language

Python

Language Version

3.11

Other information

No response

@anentropic anentropic added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2023
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Nov 6, 2023
@gshpychka
Copy link
Contributor

Duplicate of aws/jsii#4541

@khushail khushail changed the title (python) aws_rds: "DatabaseSecret" is incompatible with protocol "ISecret" (aws-rds): "DatabaseSecret" is incompatible with protocol "ISecret" Nov 6, 2023
@khushail
Copy link
Contributor

khushail commented Nov 8, 2023

Hi @anentropic , this code works fine for me and I am able to pass the database secret.

        vpc = ec2.Vpc(self, "VPC",max_azs= 2)

        db_Admin = rds.DatabaseSecret(self, "AdminSecret",
                                      username="admin",
                                      secret_name="AdminSecret")
        
        database = rds.DatabaseInstance(self, "Database",
            engine=rds.DatabaseInstanceEngine.mysql(version=rds.MysqlEngineVersion.VER_8_0),
            vpc=vpc,
            credentials=rds.Credentials.from_secret(db_Admin),
        )

        database.add_rotation_multi_user("Rotation",
                                          secret=db_Admin)

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 8, 2023
@anentropic
Copy link
Author

@khushail the code works ok, but I get type errors in my IDE

I can "solve" it by from typing import cast and wrap db_Admin cast(ISecret, db_Admin)

but it seems to defeat the purpose of having interface type like ISecret if the concrete types like DatabaseSecret don't satisfy the interface for type checkers

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 9, 2023
@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Nov 30, 2023
@iliapolo
Copy link
Contributor

iliapolo commented Sep 9, 2024

Similar to #21099 and already being tracked in aws/jsii#4541

@iliapolo iliapolo closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@iliapolo iliapolo added the language/python Related to Python bindings label Sep 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort language/python Related to Python bindings p2
Projects
None yet
Development

No branches or pull requests

5 participants