Implement client interface for transfer service
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
81afd9c36e
commit
e506cd103f
@ -18,16 +18,8 @@ package images
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands/content"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -87,11 +79,17 @@ command. As part of this process, we do the following:
|
||||
}
|
||||
defer done(ctx)
|
||||
|
||||
config, err := content.NewFetchConfig(ctx, context)
|
||||
if err != nil {
|
||||
// TODO: Handle this locally via transfer config
|
||||
//config, err := content.NewFetchConfig(ctx, context)
|
||||
// if err != nil {
|
||||
// return err
|
||||
//}
|
||||
|
||||
if err := client.Transfer(ctx, nil, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
img, err := content.Fetch(ctx, client, ref, config)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -138,6 +136,7 @@ command. As part of this process, we do the following:
|
||||
}
|
||||
}
|
||||
fmt.Printf("done: %s\t\n", time.Since(start))
|
||||
*/
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
74
transfer.go
Normal file
74
transfer.go
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package containerd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
transferapi "github.com/containerd/containerd/api/services/transfer/v1"
|
||||
"github.com/containerd/containerd/pkg/streaming"
|
||||
"github.com/containerd/containerd/pkg/transfer"
|
||||
"github.com/containerd/typeurl"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
)
|
||||
|
||||
func (c *Client) Transfer(ctx context.Context, src interface{}, dst interface{}, opts ...transfer.Opt) error {
|
||||
// Conver Options
|
||||
// Convert Source
|
||||
// Convert Destinations
|
||||
// Get Stream Manager
|
||||
|
||||
asrc, err := c.toAny(ctx, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
adst, err := c.toAny(ctx, dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = transferapi.NewTransferClient(c.conn).Transfer(ctx, &transferapi.TransferRequest{
|
||||
Source: &anypb.Any{
|
||||
TypeUrl: asrc.GetTypeUrl(),
|
||||
Value: asrc.GetValue(),
|
||||
},
|
||||
Destination: &anypb.Any{
|
||||
TypeUrl: adst.GetTypeUrl(),
|
||||
Value: adst.GetValue(),
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) toAny(ctx context.Context, i interface{}) (a typeurl.Any, err error) {
|
||||
switch v := i.(type) {
|
||||
case toAny:
|
||||
//Get stream manager
|
||||
a, err = v.ToAny(ctx, nil)
|
||||
case typeurl.Any:
|
||||
a = v
|
||||
default:
|
||||
a, err = typeurl.MarshalAny(i)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type toAny interface {
|
||||
ToAny(context.Context, streaming.StreamManager) (typeurl.Any, error)
|
||||
}
|
Loading…
Reference in New Issue
Block a user