@@ -5,13 +5,15 @@ import (
5
5
"fmt"
6
6
"io"
7
7
"net/http"
8
+ "time"
8
9
9
10
"github.com/pkg/errors"
10
11
log "github.com/sirupsen/logrus"
11
12
12
13
"github.com/teran/archived/cli/service/source"
13
14
cache "github.com/teran/archived/cli/service/stat_cache"
14
15
v1proto "github.com/teran/archived/manager/presenter/grpc/proto/v1"
16
+ ptr "github.com/teran/go-ptr"
15
17
)
16
18
17
19
type Service interface {
@@ -20,11 +22,12 @@ type Service interface {
20
22
ListNamespaces () func (ctx context.Context ) error
21
23
DeleteNamespace (namespaceName string ) func (ctx context.Context ) error
22
24
23
- CreateContainer (namespaceName , containerName string ) func (ctx context.Context ) error
25
+ CreateContainer (namespaceName , containerName string , ttl time. Duration ) func (ctx context.Context ) error
24
26
MoveContainer (namespaceName , containerName , destinationNamespace string ) func (ctx context.Context ) error
25
27
RenameContainer (namespaceName , oldName , newName string ) func (ctx context.Context ) error
26
28
ListContainers (namespaceName string ) func (ctx context.Context ) error
27
29
DeleteContainer (namespaceName , containerName string ) func (ctx context.Context ) error
30
+ SetContainerParameters (namespaceName , containerName string , ttl time.Duration ) func (ctx context.Context ) error
28
31
29
32
CreateVersion (namespaceName , containerName string , shouldPublish bool , src source.Source ) func (ctx context.Context ) error
30
33
DeleteVersion (namespaceName , containerName , versionID string ) func (ctx context.Context ) error
@@ -103,11 +106,12 @@ func (s *service) DeleteNamespace(namespaceName string) func(ctx context.Context
103
106
}
104
107
}
105
108
106
- func (s * service ) CreateContainer (namespaceName , containerName string ) func (ctx context.Context ) error {
109
+ func (s * service ) CreateContainer (namespaceName , containerName string , ttl time. Duration ) func (ctx context.Context ) error {
107
110
return func (ctx context.Context ) error {
108
111
_ , err := s .cli .CreateContainer (ctx , & v1proto.CreateContainerRequest {
109
- Namespace : namespaceName ,
110
- Name : containerName ,
112
+ Namespace : namespaceName ,
113
+ Name : containerName ,
114
+ TtlSeconds : ptr .Int64 (int64 (ttl .Seconds ())),
111
115
})
112
116
if err != nil {
113
117
return errors .Wrap (err , "error creating container" )
@@ -178,6 +182,22 @@ func (s *service) DeleteContainer(namespaceName, containerName string) func(ctx
178
182
}
179
183
}
180
184
185
+ func (s * service ) SetContainerParameters (namespaceName , containerName string , ttl time.Duration ) func (ctx context.Context ) error {
186
+ return func (ctx context.Context ) error {
187
+ _ , err := s .cli .SetContainerParameters (ctx , & v1proto.SetContainerParametersRequest {
188
+ Namespace : namespaceName ,
189
+ Name : containerName ,
190
+ TtlSeconds : ptr .Int64 (int64 (ttl .Seconds ())),
191
+ })
192
+ if err != nil {
193
+ return errors .Wrap (err , "error setting container versions TTL" )
194
+ }
195
+
196
+ fmt .Printf ("container `%s` versions TTL set to %s\n " , containerName , ttl )
197
+ return nil
198
+ }
199
+ }
200
+
181
201
func (s * service ) CreateVersion (namespaceName , containerName string , shouldPublish bool , src source.Source ) func (ctx context.Context ) error {
182
202
return func (ctx context.Context ) error {
183
203
log .Tracef ("creating version ..." )
0 commit comments