Skip to content

Commit

Permalink
exose session helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jakesylvestre committed Mar 15, 2021
1 parent 71a4012 commit 6c6afda
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c6afda

Please sign in to comment.