-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,195 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ issues: | |
- path: ._test\.go | ||
linters: | ||
- goerr113 | ||
- gocritic | ||
- errcheck | ||
- funlen | ||
- dupl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/s0rg/decompose | ||
|
||
go 1.21.0 | ||
go 1.21.1 | ||
|
||
require ( | ||
github.com/antonmedv/expr v1.15.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
//go:build !test | ||
|
||
// i/o here, nothing to test | ||
|
||
package builder | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
//go:build !test | ||
|
||
// i/o here, nothing to test | ||
|
||
package builder | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
//go:build !test | ||
|
||
// i/o here, nothing to test | ||
|
||
package builder | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build !test | ||
|
||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os/exec" | ||
"strconv" | ||
|
||
"github.com/docker/docker/client" | ||
"github.com/s0rg/decompose/internal/graph" | ||
) | ||
|
||
func Default() (rv DockerClient, err error) { | ||
rv, err = client.NewClientWithOpts( | ||
client.FromEnv, | ||
client.WithAPIVersionNegotiation(), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("docker: %w", err) | ||
} | ||
|
||
return rv, nil | ||
} | ||
|
||
func Nsenter( | ||
ctx context.Context, | ||
pid int, | ||
proto graph.NetProto, | ||
parse func(io.Reader) error, | ||
) ( | ||
err error, | ||
) { | ||
arg := append([]string{"-t", strconv.Itoa(pid), "-n"}, netstat(proto)...) | ||
cmd := exec.CommandContext(ctx, nsenterCmd, arg...) | ||
|
||
pipe, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return fmt.Errorf("pipe: %w", err) | ||
} | ||
|
||
defer pipe.Close() | ||
|
||
if err = cmd.Start(); err != nil { | ||
return fmt.Errorf("exec: %w", err) | ||
} | ||
|
||
if err = parse(pipe); err != nil { | ||
return fmt.Errorf("parse: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.