From 6c6afda6b6c6ec4545b5b43294c05f8dd967dcbb Mon Sep 17 00:00:00 2001 From: Jake Sylvestre Date: Sun, 14 Mar 2021 18:44:28 -0700 Subject: [PATCH] exose session helpers --- network.go | 2 +- teardown.go | 6 +++--- util.go | 8 ++++---- volume.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/network.go b/network.go index cd48d99..8b41046 100644 --- a/network.go +++ b/network.go @@ -10,7 +10,7 @@ func (c Client) CreateNetwork(name string) (networkID string, err error) { types.NetworkCreate{ CheckDuplicate: true, Attachable: true, - Labels: c.getSessionLabels(), + Labels: c.GetSessionLabels(), }) if err != nil { return "", err diff --git a/teardown.go b/teardown.go index 9e5701f..5b804b1 100644 --- a/teardown.go +++ b/teardown.go @@ -26,7 +26,7 @@ func (c *Client) TeardownSession() (err error) { // the current session is determined based on the Client so this method should be called // once per Client func (c *Client) TeardownSessionVolumes() (err error) { - volumes, err := c.VolumeList(c.Ctx, filterByLabels(c.getSessionLabels())) + volumes, err := c.VolumeList(c.Ctx, FilterByLabels(c.GetSessionLabels())) if err != nil { return err @@ -46,7 +46,7 @@ func (c *Client) TeardownSessionVolumes() (err error) { // and RemoveContainer the current session is determined based on the Client // so this method should be called once per Client func (c *Client) TeardownSessionNetworks() (err error) { - networks, err := c.NetworkList(c.Ctx, types.NetworkListOptions{Filters: filterByLabels(c.getSessionLabels())}) + networks, err := c.NetworkList(c.Ctx, types.NetworkListOptions{Filters: FilterByLabels(c.GetSessionLabels())}) if err != nil { return err } @@ -66,7 +66,7 @@ func (c *Client) TeardownSessionNetworks() (err error) { func (c *Client) TeardownSessionContainers() (err error) { filter := types.ContainerListOptions{ All: true, - Filters: filterByLabels(c.getSessionLabels()), + Filters: FilterByLabels(c.GetSessionLabels()), } containers, err := c.ContainerList(c.Ctx, filter) diff --git a/util.go b/util.go index 0b06599..7fea3ce 100644 --- a/util.go +++ b/util.go @@ -6,16 +6,16 @@ import ( "github.com/docker/docker/api/types/filters" ) -// getSessionLabels gets labels set for all resources created in this session -func (c Client) getSessionLabels() map[string]string { +// GetSessionLabels gets labels set for all resources created in this session +func (c Client) GetSessionLabels() map[string]string { return map[string]string{ "sessionId": c.SessionID, "created-by": "docker-utils", } } -// filterByLabels creates filters.Args based on a set of labels -func filterByLabels(labels map[string]string) (args filters.Args) { +// FilterByLabels creates filters.Args based on a set of labels +func FilterByLabels(labels map[string]string) (args filters.Args) { var kvps []filters.KeyValuePair for key, value := range labels { kvps = append(kvps, filters.KeyValuePair{ diff --git a/volume.go b/volume.go index fb08b09..019aa44 100644 --- a/volume.go +++ b/volume.go @@ -55,7 +55,7 @@ func (c *Client) CreateVolume(name string) (err error) { vol, err := c.VolumeCreate(c.Ctx, volume.VolumeCreateBody{ Driver: Driver, Name: name, - Labels: c.getSessionLabels(), + Labels: c.GetSessionLabels(), }) if err != nil { return err