1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
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
}
|