-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add podman-remote quadlet command #29088
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
Open
inknos
wants to merge
1
commit into
podman-container-tools:main
Choose a base branch
from
inknos:RUN-4852
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+700
−26
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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,158 @@ | ||
| package quadlets | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
| "mime/multipart" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| "go.podman.io/podman/v6/pkg/bindings" | ||
| "go.podman.io/podman/v6/pkg/domain/entities" | ||
| ) | ||
|
|
||
| // List returns a list of quadlets on the server. | ||
| func List(ctx context.Context, options *ListOptions) ([]*entities.ListQuadlet, error) { | ||
| if options == nil { | ||
| options = new(ListOptions) | ||
| } | ||
| conn, err := bindings.GetClient(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| params, err := options.ToParams() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var quadlets []*entities.ListQuadlet | ||
| response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/quadlets/json", params, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| return quadlets, response.Process(&quadlets) | ||
| } | ||
|
|
||
| // Exists checks whether a quadlet with the given name exists on the server. | ||
| func Exists(ctx context.Context, name string, _ *ExistsOptions) (bool, error) { | ||
| conn, err := bindings.GetClient(ctx) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/quadlets/%s/exists", nil, nil, name) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| return response.IsSuccess(), nil | ||
| } | ||
|
|
||
| // Print returns the contents of a quadlet file from the server. | ||
| func Print(ctx context.Context, name string, _ *PrintOptions) (string, error) { | ||
| conn, err := bindings.GetClient(ctx) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/quadlets/%s/file", nil, nil, name) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| if !response.IsSuccess() { | ||
| return "", response.Process(nil) | ||
| } | ||
|
|
||
| body, err := io.ReadAll(response.Body) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return string(body), nil | ||
| } | ||
|
|
||
| // Install sends local quadlet files to the server for installation via multipart upload. | ||
| // fileNames provides the upload filename for each filePath (preserving relative paths | ||
| // for directory structures). It must be non-nil and the same length as filePaths. | ||
| func Install(ctx context.Context, filePaths []string, fileNames []string, options *InstallOptions) (*entities.QuadletInstallReport, error) { | ||
| if options == nil { | ||
| options = new(InstallOptions) | ||
| } | ||
| conn, err := bindings.GetClient(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| params, err := options.ToParams() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| pr, pw := io.Pipe() | ||
| writer := multipart.NewWriter(pw) | ||
|
|
||
| go func() { | ||
| defer pw.Close() | ||
| defer writer.Close() | ||
|
|
||
| for i, filePath := range filePaths { | ||
| filename := fileNames[i] | ||
| part, err := writer.CreateFormFile(filename, filename) | ||
| if err != nil { | ||
| pw.CloseWithError(err) | ||
| return | ||
| } | ||
| file, err := os.Open(filePath) | ||
| if err != nil { | ||
| pw.CloseWithError(err) | ||
| return | ||
| } | ||
| _, err = io.Copy(part, file) | ||
| file.Close() | ||
| if err != nil { | ||
| pw.CloseWithError(err) | ||
| return | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| header := make(http.Header) | ||
| header.Set("Content-Type", writer.FormDataContentType()) | ||
|
|
||
| var report entities.QuadletInstallReport | ||
| response, err := conn.DoRequest(ctx, pr, http.MethodPost, "/quadlets", params, header) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| return &report, response.Process(&report) | ||
| } | ||
|
|
||
| // Remove removes one or more quadlets from the server (batch operation). | ||
| func Remove(ctx context.Context, quadletNames []string, options *RemoveOptions) (*entities.QuadletRemoveReport, error) { | ||
| if options == nil { | ||
| options = new(RemoveOptions) | ||
| } | ||
| conn, err := bindings.GetClient(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| params, err := options.ToParams() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, name := range quadletNames { | ||
| params.Add("quadlets", name) | ||
| } | ||
|
|
||
| var report entities.QuadletRemoveReport | ||
| response, err := conn.DoRequest(ctx, nil, http.MethodDelete, "/quadlets", params, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer response.Body.Close() | ||
|
|
||
| return &report, response.Process(&report) | ||
| } | ||
This file contains hidden or 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,38 @@ | ||
| package quadlets | ||
|
|
||
| // ListOptions are optional options for listing quadlets | ||
| // | ||
| //go:generate go run ../generator/generator.go ListOptions | ||
| type ListOptions struct { | ||
| Filters map[string][]string | ||
| } | ||
|
|
||
| // ExistsOptions are optional options for checking if a quadlet exists | ||
| // | ||
| //go:generate go run ../generator/generator.go ExistsOptions | ||
| type ExistsOptions struct{} | ||
|
|
||
| // PrintOptions are optional options for printing quadlet file contents | ||
| // | ||
| //go:generate go run ../generator/generator.go PrintOptions | ||
| type PrintOptions struct{} | ||
|
|
||
| // InstallOptions are optional options for installing quadlets | ||
| // | ||
| //go:generate go run ../generator/generator.go InstallOptions | ||
| type InstallOptions struct { | ||
| Replace *bool | ||
| ReloadSystemd *bool | ||
| Application *string | ||
| } | ||
|
|
||
| // RemoveOptions are optional options for removing quadlets | ||
| // | ||
| //go:generate go run ../generator/generator.go RemoveOptions | ||
| type RemoveOptions struct { | ||
| Force *bool | ||
| All *bool | ||
| Ignore *bool | ||
| ReloadSystemd *bool | ||
| Recursive *bool | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.