From 0db53fd2443127e013470c0f6f2056edf15f51bf Mon Sep 17 00:00:00 2001 From: David Trudgian Date: Thu, 17 Dec 2020 11:20:24 -0600 Subject: [PATCH] Make basic get/create/set functions public Closes #101 --- client/api.go | 38 +++++++++++++++++++------------------- client/api_test.go | 16 ++++++++-------- client/push.go | 16 ++++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/client/api.go b/client/api.go index 44ea24a..f9f82ba 100644 --- a/client/api.go +++ b/client/api.go @@ -16,9 +16,9 @@ import ( jsonresp "github.com/sylabs/json-resp" ) -// getEntity returns the specified entity; returns ErrNotFound if entity is not +// GetEntity returns the specified entity; returns ErrNotFound if entity is not // found, otherwise error -func (c *Client) getEntity(ctx context.Context, entityRef string) (*Entity, error) { +func (c *Client) GetEntity(ctx context.Context, entityRef string) (*Entity, error) { entJSON, err := c.apiGet(ctx, "v1/entities/"+entityRef) if err != nil { return nil, err @@ -30,9 +30,9 @@ func (c *Client) getEntity(ctx context.Context, entityRef string) (*Entity, erro return &res.Data, nil } -// getCollection returns the specified collection; returns ErrNotFound if +// GetCollection returns the specified collection; returns ErrNotFound if // collection is not found, otherwise error. -func (c *Client) getCollection(ctx context.Context, collectionRef string) (*Collection, error) { +func (c *Client) GetCollection(ctx context.Context, collectionRef string) (*Collection, error) { colJSON, err := c.apiGet(ctx, "v1/collections/"+collectionRef) if err != nil { return nil, err @@ -44,9 +44,9 @@ func (c *Client) getCollection(ctx context.Context, collectionRef string) (*Coll return &res.Data, nil } -// getContainer returns container by ref id; returns ErrNotFound if container +// GetContainer returns container by ref id; returns ErrNotFound if container // is not found, otherwise error. -func (c *Client) getContainer(ctx context.Context, containerRef string) (*Container, error) { +func (c *Client) GetContainer(ctx context.Context, containerRef string) (*Container, error) { conJSON, err := c.apiGet(ctx, "v1/containers/"+containerRef) if err != nil { return nil, err @@ -58,8 +58,8 @@ func (c *Client) getContainer(ctx context.Context, containerRef string) (*Contai return &res.Data, nil } -// createEntity creates an entity (must be authorized) -func (c *Client) createEntity(ctx context.Context, name string) (*Entity, error) { +// CreateEntity creates an entity (must be authorized) +func (c *Client) CreateEntity(ctx context.Context, name string) (*Entity, error) { e := Entity{ Name: name, Description: "No description", @@ -75,8 +75,8 @@ func (c *Client) createEntity(ctx context.Context, name string) (*Entity, error) return &res.Data, nil } -// createCollection creates a new collection -func (c *Client) createCollection(ctx context.Context, name string, entityID string) (*Collection, error) { +// CreateCollection creates a new collection +func (c *Client) CreateCollection(ctx context.Context, name string, entityID string) (*Collection, error) { newCollection := Collection{ Name: name, Description: "No description", @@ -93,8 +93,8 @@ func (c *Client) createCollection(ctx context.Context, name string, entityID str return &res.Data, nil } -// createContainer creates a container in the specified collection -func (c *Client) createContainer(ctx context.Context, name string, collectionID string) (*Container, error) { +// CreateContainer creates a container in the specified collection +func (c *Client) CreateContainer(ctx context.Context, name string, collectionID string) (*Container, error) { newContainer := Container{ Name: name, Description: "No description", @@ -111,8 +111,8 @@ func (c *Client) createContainer(ctx context.Context, name string, collectionID return &res.Data, nil } -// createImage creates a new image -func (c *Client) createImage(ctx context.Context, hash string, containerID string, description string) (*Image, error) { +// CreateImage creates a new image +func (c *Client) CreateImage(ctx context.Context, hash string, containerID string, description string) (*Image, error) { i := Image{ Hash: hash, Description: description, @@ -129,10 +129,10 @@ func (c *Client) createImage(ctx context.Context, hash string, containerID strin return &res.Data, nil } -// setTags applies tags to the specified container -func (c *Client) setTags(ctx context.Context, containerID, imageID string, tags []string) error { +// SetTags applies tags to the specified container +func (c *Client) SetTags(ctx context.Context, containerID, imageID string, tags []string) error { // Get existing tags, so we know which will be replaced - existingTags, err := c.getTags(ctx, containerID) + existingTags, err := c.GetTags(ctx, containerID) if err != nil { return err } @@ -156,8 +156,8 @@ func (c *Client) setTags(ctx context.Context, containerID, imageID string, tags return nil } -// getTags returns a tag map for the specified containerID -func (c *Client) getTags(ctx context.Context, containerID string) (TagMap, error) { +// GetTags returns a tag map for the specified containerID +func (c *Client) GetTags(ctx context.Context, containerID string) (TagMap, error) { url := fmt.Sprintf("v1/tags/%s", containerID) c.Logger.Logf("getTags calling %s", url) req, err := c.newRequest(http.MethodGet, url, "", nil) diff --git a/client/api_test.go b/client/api_test.go index c2d3592..e29d134 100644 --- a/client/api_test.go +++ b/client/api_test.go @@ -254,7 +254,7 @@ func Test_getEntity(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - entity, err := c.getEntity(context.Background(), tt.entityRef) + entity, err := c.GetEntity(context.Background(), tt.entityRef) if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -336,7 +336,7 @@ func Test_getCollection(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - collection, err := c.getCollection(context.Background(), tt.collectionRef) + collection, err := c.GetCollection(context.Background(), tt.collectionRef) if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -418,7 +418,7 @@ func Test_getContainer(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - container, err := c.getContainer(context.Background(), tt.containerRef) + container, err := c.GetContainer(context.Background(), tt.containerRef) if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -571,7 +571,7 @@ func Test_createEntity(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - entity, err := c.createEntity(context.Background(), tt.entityRef) + entity, err := c.CreateEntity(context.Background(), tt.entityRef) if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -627,7 +627,7 @@ func Test_createCollection(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - collection, err := c.createCollection(context.Background(), tt.collectionRef, "5cb9c34d7d960d82f5f5bc50") + collection, err := c.CreateCollection(context.Background(), tt.collectionRef, "5cb9c34d7d960d82f5f5bc50") if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -683,7 +683,7 @@ func Test_createContainer(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - container, err := c.createContainer(context.Background(), tt.containerRef, "5cb9c34d7d960d82f5f5bc51") + container, err := c.CreateContainer(context.Background(), tt.containerRef, "5cb9c34d7d960d82f5f5bc51") if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -747,7 +747,7 @@ func Test_createImage(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - image, err := c.createImage(context.Background(), tt.imageRef, "5cb9c34d7d960d82f5f5bc52", "No Description") + image, err := c.CreateImage(context.Background(), tt.imageRef, "5cb9c34d7d960d82f5f5bc52", "No Description") if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) @@ -810,7 +810,7 @@ func Test_setTags(t *testing.T) { t.Errorf("Error initializing client: %v", err) } - err = c.setTags(context.Background(), tt.containerRef, tt.imageRef, tt.tags) + err = c.SetTags(context.Background(), tt.containerRef, tt.imageRef, tt.tags) if err != nil && !tt.expectError { t.Errorf("Unexpected error: %v", err) diff --git a/client/push.go b/client/push.go index 507a606..30d6bc0 100644 --- a/client/push.go +++ b/client/push.go @@ -129,13 +129,13 @@ func (c *Client) UploadImage(ctx context.Context, r io.ReadSeeker, path, arch st c.Logger.Logf("Image hash computed as %s", imageHash) // Find or create entity - entity, err := c.getEntity(ctx, entityName) + entity, err := c.GetEntity(ctx, entityName) if err != nil { if err != ErrNotFound { return nil, err } c.Logger.Logf("Entity %s does not exist in library - creating it.", entityName) - entity, err = c.createEntity(ctx, entityName) + entity, err = c.CreateEntity(ctx, entityName) if err != nil { return nil, err } @@ -143,14 +143,14 @@ func (c *Client) UploadImage(ctx context.Context, r io.ReadSeeker, path, arch st // Find or create collection qualifiedCollectionName := fmt.Sprintf("%s/%s", entityName, collectionName) - collection, err := c.getCollection(ctx, qualifiedCollectionName) + collection, err := c.GetCollection(ctx, qualifiedCollectionName) if err != nil { if err != ErrNotFound { return nil, err } // create collection c.Logger.Logf("Collection %s does not exist in library - creating it.", collectionName) - collection, err = c.createCollection(ctx, collectionName, entity.ID) + collection, err = c.CreateCollection(ctx, collectionName, entity.ID) if err != nil { return nil, err } @@ -158,14 +158,14 @@ func (c *Client) UploadImage(ctx context.Context, r io.ReadSeeker, path, arch st // Find or create container computedName := fmt.Sprintf("%s/%s", qualifiedCollectionName, containerName) - container, err := c.getContainer(ctx, computedName) + container, err := c.GetContainer(ctx, computedName) if err != nil { if err != ErrNotFound { return nil, err } // Create container c.Logger.Logf("Container %s does not exist in library - creating it.", containerName) - container, err = c.createContainer(ctx, containerName, collection.ID) + container, err = c.CreateContainer(ctx, containerName, collection.ID) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func (c *Client) UploadImage(ctx context.Context, r io.ReadSeeker, path, arch st } // Create image c.Logger.Logf("Image %s does not exist in library - creating it.", imageHash) - image, err = c.createImage(ctx, "sha256."+imageHash, container.ID, description) + image, err = c.CreateImage(ctx, "sha256."+imageHash, container.ID, description) if err != nil { return nil, err } @@ -222,7 +222,7 @@ func (c *Client) UploadImage(ctx context.Context, r io.ReadSeeker, path, arch st c.Logger.Logf("This tag will replace any already uploaded with the same name.") - if err := c.setTags(ctx, container.ID, image.ID, append(tags, parsedTags...)); err != nil { + if err := c.SetTags(ctx, container.ID, image.ID, append(tags, parsedTags...)); err != nil { return nil, err } return res, nil