grim/port-authority
Start of moving this to a go http client
--- a/README.txt Tue Apr 16 02:25:00 2019 -0500
+++ b/README.txt Mon Apr 27 21:53:44 2020 -0500
@@ -1,21 +1,28 @@
+Port Authority is a simple golang http client that handles all of the +authentication involved when interacting with a container registry. This means +it's a dumb client and it's up to you, the user to know the API endpoints you +want to hit. At some point in the future this may change, but for now it only - * clone the source tree
- * navigate to "chrome://extensions"
- * check "Developer mode" in the top right
- * click "Load unpacked extension..."
- * Navigate to the cloned source tree
- * The application is now installed
+ pa "bitbucket.org/rw_grim/port-authority" + client := pa.NewClient()
+ client.AddRegistry("index.docker.io", "username", "password") + resp, _ := client.Get("/v2/username/foo/tags") - * Click on the apps button in your bookmarks bar
- * Click "Docker Manifest"
- * Enter a docker registry hostname (doesn't work on registry.hub.docker.com)
+ fmt.Printf("%#v\n", resp) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client.go Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,22 @@
+ registryLock sync.Mutex + registries map[string]registry +func NewClient() *Client { + Transport: NewTransport(), + registries: map[string]registry{}, --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/go.mod Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,5 @@
+module keep.imfreedom.org/grim/port-authority +require github.com/stretchr/testify v1.3.0 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/go.sum Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,7 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/registry.go Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,7 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/registry_test.go Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,26 @@
+ "github.com/stretchr/testify/assert" +func TestAddRepository(t *testing.T) { + assert := assert.New(t) + c.AddRegistry("host", "user", "pass") + username, password := c.GetRegistry("host") + assert.Equal(username, "user") + assert.Equal(password, "pass") + c.RemoveRegistry("host") + username, password = c.GetRegistry("host") + assert.Equal(username, "") + assert.Equal(password, "") --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/transport.go Mon Apr 27 21:53:44 2020 -0500
@@ -0,0 +1,43 @@
+ Transport http.RoundTripper + registryLock sync.Mutex + registries map[string]registry +func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) { +func (t *Transport) AddRegistry(hostname, username, password string) { + defer t.registryLock.Unlock() + t.registries[hostname] = registry{username, password} +func (t *Transport) GetRegistry(hostname string) (string, string) { + defer t.registryLock.Unlock() + if reg, found := c.registries[hostname]; found { + return reg.username, reg.password +func (t *Transport) RemoveRegistry(hostname string) { + defer t.registryLock.Unlock() + delete(t.registries, hostname)