summaryrefslogtreecommitdiff
path: root/pkg/bindings/network/network.go
diff options
context:
space:
mode:
authorMoritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>2021-11-15 15:42:39 +0100
committerMoritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>2021-11-15 15:42:39 +0100
commit5df883e87d7d4faec24c53c89bab3255057de0bc (patch)
tree933a4e9cb734652ac7523f86ba3df3c84b84fe12 /pkg/bindings/network/network.go
parentcca6df428cb9ce187ae1341740ac1137c7a67a75 (diff)
downloadpodman-5df883e87d7d4faec24c53c89bab3255057de0bc.tar.gz
podman-5df883e87d7d4faec24c53c89bab3255057de0bc.tar.bz2
podman-5df883e87d7d4faec24c53c89bab3255057de0bc.zip
bindings: reuse context for API requests
One of the main uses of context.Context is to provide cancellation for go-routines, including API requests. While all user-facing bindings already used a context parameter, it was only used to pass the client information around. This commit changes the internal DoRequest wrapper to take an additional context argument, and pass that to the http request. Previously, the context was derived from context.Background(), which made it impossible to cancel once started. All the convenience wrappers already supported the context parameter, so the only user facing change is that cancelling those context now works as one would expect. Signed-off-by: Moritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>
Diffstat (limited to 'pkg/bindings/network/network.go')
-rw-r--r--pkg/bindings/network/network.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go
index 5a0a34f56..172598be1 100644
--- a/pkg/bindings/network/network.go
+++ b/pkg/bindings/network/network.go
@@ -28,7 +28,7 @@ func Create(ctx context.Context, network *types.Network) (types.Network, error)
return report, err
}
reader := strings.NewReader(networkConfig)
- response, err := conn.DoRequest(reader, http.MethodPost, "/networks/create", nil, nil)
+ response, err := conn.DoRequest(ctx, reader, http.MethodPost, "/networks/create", nil, nil)
if err != nil {
return report, err
}
@@ -44,7 +44,7 @@ func Inspect(ctx context.Context, nameOrID string, _ *InspectOptions) (types.Net
if err != nil {
return net, err
}
- response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/json", nil, nil, nameOrID)
+ response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/networks/%s/json", nil, nil, nameOrID)
if err != nil {
return net, err
}
@@ -69,7 +69,7 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*en
if err != nil {
return nil, err
}
- response, err := conn.DoRequest(nil, http.MethodDelete, "/networks/%s", params, nil, nameOrID)
+ response, err := conn.DoRequest(ctx, nil, http.MethodDelete, "/networks/%s", params, nil, nameOrID)
if err != nil {
return nil, err
}
@@ -92,7 +92,7 @@ func List(ctx context.Context, options *ListOptions) ([]types.Network, error) {
if err != nil {
return nil, err
}
- response, err := conn.DoRequest(nil, http.MethodGet, "/networks/json", params, nil)
+ response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/networks/json", params, nil)
if err != nil {
return netList, err
}
@@ -128,7 +128,7 @@ func Disconnect(ctx context.Context, networkName string, ContainerNameOrID strin
return err
}
stringReader := strings.NewReader(body)
- response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/%s/disconnect", params, nil, networkName)
+ response, err := conn.DoRequest(ctx, stringReader, http.MethodPost, "/networks/%s/disconnect", params, nil, networkName)
if err != nil {
return err
}
@@ -163,7 +163,7 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrID string,
return err
}
stringReader := strings.NewReader(body)
- response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/%s/connect", params, nil, networkName)
+ response, err := conn.DoRequest(ctx, stringReader, http.MethodPost, "/networks/%s/connect", params, nil, networkName)
if err != nil {
return err
}
@@ -178,7 +178,7 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool,
if err != nil {
return false, err
}
- response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/exists", nil, nil, nameOrID)
+ response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/networks/%s/exists", nil, nil, nameOrID)
if err != nil {
return false, err
}
@@ -204,7 +204,7 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.NetworkPrune
return nil, err
}
- response, err := conn.DoRequest(nil, http.MethodPost, "/networks/prune", params, nil)
+ response, err := conn.DoRequest(ctx, nil, http.MethodPost, "/networks/prune", params, nil)
if err != nil {
return nil, err
}