mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

Add the command along with the abi and tunnel support Add e2e tests Add man page Add apiv2 test to ensure return codes Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
98 lines
2.9 KiB
Go
98 lines
2.9 KiB
Go
package tunnel
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/containers/podman/v4/pkg/bindings/secrets"
|
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
|
"github.com/containers/podman/v4/pkg/errorhandling"
|
|
)
|
|
|
|
func (ic *ContainerEngine) SecretCreate(ctx context.Context, name string, reader io.Reader, options entities.SecretCreateOptions) (*entities.SecretCreateReport, error) {
|
|
opts := new(secrets.CreateOptions).
|
|
WithDriver(options.Driver).
|
|
WithDriverOpts(options.DriverOpts).
|
|
WithName(name).
|
|
WithLabels(options.Labels)
|
|
created, err := secrets.Create(ic.ClientCtx, reader, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return created, nil
|
|
}
|
|
|
|
func (ic *ContainerEngine) SecretInspect(ctx context.Context, nameOrIDs []string) ([]*entities.SecretInfoReport, []error, error) {
|
|
allInspect := make([]*entities.SecretInfoReport, 0, len(nameOrIDs))
|
|
errs := make([]error, 0, len(nameOrIDs))
|
|
for _, name := range nameOrIDs {
|
|
inspected, err := secrets.Inspect(ic.ClientCtx, name, nil)
|
|
if err != nil {
|
|
errModel, ok := err.(*errorhandling.ErrorModel)
|
|
if !ok {
|
|
return nil, nil, err
|
|
}
|
|
if errModel.ResponseCode == 404 {
|
|
errs = append(errs, fmt.Errorf("no such secret %q", name))
|
|
continue
|
|
}
|
|
return nil, nil, err
|
|
}
|
|
allInspect = append(allInspect, inspected)
|
|
}
|
|
return allInspect, errs, nil
|
|
}
|
|
|
|
func (ic *ContainerEngine) SecretList(ctx context.Context, opts entities.SecretListRequest) ([]*entities.SecretInfoReport, error) {
|
|
options := new(secrets.ListOptions).WithFilters(opts.Filters)
|
|
secrs, _ := secrets.List(ic.ClientCtx, options)
|
|
return secrs, nil
|
|
}
|
|
|
|
func (ic *ContainerEngine) SecretRm(ctx context.Context, nameOrIDs []string, options entities.SecretRmOptions) ([]*entities.SecretRmReport, error) {
|
|
allRm := make([]*entities.SecretRmReport, 0, len(nameOrIDs))
|
|
if options.All {
|
|
allSecrets, err := secrets.List(ic.ClientCtx, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, secret := range allSecrets {
|
|
allRm = append(allRm, &entities.SecretRmReport{
|
|
Err: secrets.Remove(ic.ClientCtx, secret.ID),
|
|
ID: secret.ID,
|
|
})
|
|
}
|
|
return allRm, nil
|
|
}
|
|
for _, name := range nameOrIDs {
|
|
secret, err := secrets.Inspect(ic.ClientCtx, name, nil)
|
|
if err != nil {
|
|
errModel, ok := err.(*errorhandling.ErrorModel)
|
|
if !ok {
|
|
return nil, err
|
|
}
|
|
if errModel.ResponseCode == 404 {
|
|
allRm = append(allRm, &entities.SecretRmReport{
|
|
Err: fmt.Errorf("no secret with name or id %q: no such secret ", name),
|
|
ID: "",
|
|
})
|
|
continue
|
|
}
|
|
}
|
|
allRm = append(allRm, &entities.SecretRmReport{
|
|
Err: secrets.Remove(ic.ClientCtx, name),
|
|
ID: secret.ID,
|
|
})
|
|
}
|
|
return allRm, nil
|
|
}
|
|
|
|
func (ic *ContainerEngine) SecretExists(ctx context.Context, nameOrID string) (*entities.BoolReport, error) {
|
|
exists, err := secrets.Exists(ic.ClientCtx, nameOrID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &entities.BoolReport{Value: exists}, nil
|
|
}
|