-
Notifications
You must be signed in to change notification settings - Fork 99
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
Port API: support specifying IP version explicitly ("tcp4", "tcp6") #232
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9a9958b
API: support `GET /info`
AkihiroSuda 1034dbf
Port API: support specifying IP version explicitly ("tcp4", "tcp6")
AkihiroSuda 0aa4165
rootlesskit-docker-proxy: support libnetwork >= 20201216 convention
AkihiroSuda f17d87b
port/builtin: support v6-to-v6 forwarding
AkihiroSuda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var infoCommand = cli.Command{ | ||
Name: "info", | ||
Usage: "Show info", | ||
ArgsUsage: "[flags]", | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "json", | ||
Usage: "Prints as JSON", | ||
}, | ||
}, | ||
Action: infoAction, | ||
} | ||
|
||
func infoAction(clicontext *cli.Context) error { | ||
w := clicontext.App.Writer | ||
c, err := newClient(clicontext) | ||
if err != nil { | ||
return err | ||
} | ||
ctx := context.Background() | ||
info, err := c.Info(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if clicontext.Bool("json") { | ||
m, err := json.MarshalIndent(info, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintln(w, string(m)) | ||
return nil | ||
} | ||
fmt.Fprintf(w, "- REST API version: %s\n", info.APIVersion) | ||
fmt.Fprintf(w, "- Implementation version: %s\n", info.Version) | ||
fmt.Fprintf(w, "- State Directory: %s\n", info.StateDir) | ||
fmt.Fprintf(w, "- Child PID: %d\n", info.ChildPID) | ||
if info.NetworkDriver != nil { | ||
fmt.Fprintf(w, "- Network Driver: %s\n", info.NetworkDriver.Driver) | ||
fmt.Fprintf(w, " - DNS: %v\n", info.NetworkDriver.DNS) | ||
} | ||
if info.PortDriver != nil { | ||
fmt.Fprintf(w, "- Port Driver: %s\n", info.PortDriver.Driver) | ||
fmt.Fprintf(w, " - Supported protocols: %v\n", info.PortDriver.Protos) | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# REST API | ||
|
||
RootlessKit listens REST API on `${ROOTLESSKIT_STATE_DIR}/api.sock`. | ||
|
||
```console | ||
(host)$ rootlesskit --net=slirp4netns --port-driver=builtin bash | ||
(rootlesskit)# curl -s --unix-socket "${ROOTLESSKIT_STATE_DIR}/api.sock" http://rootlesskit/v1/info | jq . | ||
{ | ||
"apiVersion": "1.1.0", | ||
"version": "0.13.2+dev", | ||
"stateDir": "/tmp/rootlesskit957151185", | ||
"childPID": 157684, | ||
"networkDriver": { | ||
"driver": "slirp4netns", | ||
"dns": [ | ||
"10.0.2.3" | ||
] | ||
}, | ||
"portDriver": { | ||
"driver": "builtin", | ||
"protos": [ | ||
"tcp", | ||
"udp" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## openapi.yaml | ||
|
||
See [`../pkg/api/openapi.yaml`](../pkg/api/openapi.yaml) | ||
|
||
## rootlessctl CLI | ||
|
||
`rootlessctl` is the CLI for the API. | ||
|
||
```console | ||
$ rootlessctl --help | ||
NAME: | ||
rootlessctl - RootlessKit API client | ||
|
||
USAGE: | ||
rootlessctl [global options] command [command options] [arguments...] | ||
|
||
VERSION: | ||
0.13.2+dev | ||
|
||
COMMANDS: | ||
list-ports List ports | ||
add-ports Add ports | ||
remove-ports Remove ports | ||
info Show info | ||
help, h Shows a list of commands or help for one command | ||
|
||
GLOBAL OPTIONS: | ||
--debug debug mode (default: false) | ||
--socket value Path to api.sock (under the "rootlesskit --state-dir" directory), defaults to $ROOTLESSKIT_STATE_DIR/api.sock | ||
--help, -h show help (default: false) | ||
--version, -v print the version (default: false) | ||
``` | ||
|
||
e.g., `rootlessctl --socket /foo/bar/sock info --json` |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️