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

Make basic get/create/set functions public #102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions client/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,43 +129,43 @@ 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
}
}

// 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
}
}

// 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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down