docker / libcompose

*Unmaintained/Deprecated* An experimental go library providing Compose-like functionality
https://godoc.org/github.com/docker/libcompose
Apache License 2.0
586 stars 191 forks source link

Attempting to expose docker auth configs to libcompose users #453

Closed vito-c closed 7 years ago

vito-c commented 7 years ago

RFC: I ran into an issue the other day: https://github.com/docker/libcompose/issues/186#issuecomment-287549617 after a recent update to docker. Essentially libcompose no longer worked with the specific format of auth file on my computer.

I was going to try to fix this directly in my own project but I was getting errors accessing the vendor structs and type mismatch errors when trying to use the docker libraries directly. It was really kind of frustrating to have to dig into all of the auth just to get a access to a private registry.

I then went on to realize I could just do something like this:

        // ac is a AuthConfig from docker library
    dockerContext.AuthLookup = auth.NewConfigLookup(dockerContext.ConfigFile)
    thing := dockerContext.ConfigFile.AuthConfigs["docker.example.com"]
    thing.Username=      ac.Username
    thing.Password=      ac.Password
    thing.Auth=          ac.Auth
    thing.Email=         ac.Email
    thing.ServerAddress= ac.ServerAddress
    thing.IdentityToken= ac.IdentityToken
    thing.RegistryToken= ac.RegistryToken
    dockerContext.ConfigFile.AuthConfigs["docker.example.com"] = thing

I had already written the code that exposed a auth.Config struct and the helper methods. I'm not really sure which way is better and I still have to write some unit tests around the code I am submitting. There could be something else entirely that I missed so I thought best to open a PR and discuss.