Skip to content

Implement Connector interface #671

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

Closed
julienschmidt opened this issue Sep 23, 2017 · 7 comments
Closed

Implement Connector interface #671

julienschmidt opened this issue Sep 23, 2017 · 7 comments
Assignees
Milestone

Comments

@julienschmidt
Copy link
Member

See golang/go@e6358c7

@agruetz
Copy link

agruetz commented Nov 10, 2017

Would it be possible to implement this in a way that a call back function could be passed in so that the caller could pass in their own connection function. The use case for me would be I want to implement AWS RDS IAM Authentication and the DSN Credentials need to refreshed every 15 min.

Something along these lines:

func (d MySQLDriver) Connect(c context.Context) (driver.Conn, error) {
conn,err := d.CB()
if err != nil {
return nil, err
}
return conn, err
}

@methane
Copy link
Member

methane commented Nov 10, 2017

@agruetz You can create own connector which wraps this driver.

@agruetz
Copy link

agruetz commented Nov 10, 2017

Methane that is absolutely an option as well. I guess the real question is what does this driver plan to do with the connector interface. Seems like it would be a helpful implementation to allow the user of the driver to be able to decide what the connector does and then possibly offer a handful of functions that the driver already contains that could be passed in as well.

Either way I would be interested in helping.

@methane
Copy link
Member

methane commented Nov 11, 2017

Seems like it would be a helpful implementation to allow the user of the driver to be able to decide what the connector does

That's what new Connector interface does. So I don't think mysql driver should provide such API.

I don't know about AWS authentication. But it will looks like:

type CustomConnector {
    m sync.Mutex
    config *mysql.Config
}

func (c *CustomConnector) Connect(ctx, context.Context) (driver.Conn, error) {
    pwd := refreshPassword()
    c.m.Lock()
    c.config.Passwd = pwd
    c.m.Unlock()
    return c.config.Connect(ctx)
}

func (c *CustomConnector) Driver() driver.Driver {
    return c.config.Driver()
}

and then possibly offer a handful of functions that the driver already contains that could be passed in as well.

You can help by:

  • Show more concrete example when asking question.
  • Implement connector interface and send pull request.
  • Or just wait until someone does it.

@agruetz
Copy link

agruetz commented Nov 12, 2017

I think I see what you are driving at. Just have the connecter interface implement a connect function in the driver that just makes a connection to MySQL based on the config vs Parsing a DSN that populates the config. Then the caller can just wrap the mysql driver connector to do whatever special they want to the config.

Only down side there is it forces the caller to implement a driver connecter interface to wrap the mysql driver connector interface. Which I guess seems more reasonable because the way I was thinking about it would require them to implement the full conneciton.

I will try to take a whack at implementing it. Hopefully it will not be to ugly of an implementation that you guys just laugh at me =).

@a-h
Copy link

a-h commented Feb 1, 2019

@agruetz - I had the same use case as you, and thought I'd try implementing the connector interface outside of the go-sql-driver package and integrating with the AWS Secrets Manager based on @methane's example. I'd be interested in feedback: https://github.com/a-h/go-sql-driver-rds-credentials

@julienschmidt
Copy link
Member Author

Fixed by #941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants