github.com/release-engineering/exodus-rsync@v1.11.2/internal/gw/gw.go (about) 1 package gw 2 3 import ( 4 "context" 5 6 "github.com/aws/aws-sdk-go/aws/session" 7 "github.com/release-engineering/exodus-rsync/internal/conf" 8 "github.com/release-engineering/exodus-rsync/internal/walk" 9 ) 10 11 //go:generate go run -modfile ../../go.tools.mod github.com/golang/mock/mockgen -package $GOPACKAGE -destination mock.go -source $GOFILE 12 13 // Interface defines the public interface of this package. 14 type Interface interface { 15 // NewClient creates and returns a new exodus-gw client with the given 16 // configuration. 17 NewClient(context.Context, conf.Config) (Client, error) 18 19 // NewDryRunClient creates and returns a new exodus-gw client in dry-run 20 // mode. This client replaces any write operations with stubs. 21 NewDryRunClient(context.Context, conf.Config) (Client, error) 22 } 23 24 type impl struct{} 25 26 // Package provides the default implementation of this package's interface. 27 var Package Interface = impl{} 28 29 // External dependencies which may be overridden from tests. 30 var ext = struct { 31 awsSessionProvider func(session.Options) (*session.Session, error) 32 }{ 33 session.NewSessionWithOptions, 34 } 35 36 // Client provides a high-level interface to the exodus-gw HTTP API. 37 type Client interface { 38 // EnsureUploaded will process every given item for sync and ensure that the content 39 // is present in the target exodus-gw environment. 40 // 41 // For each item, onUploaded is invoked if the item was uploaded during the call; 42 // onPresent is invoked if the item was already present prior to the call; 43 // onDuplicate is invoked if a duplicate item is detected within the publish. 44 // 45 // Returning from the callback with an error will cause EnsureUploaded to stop and 46 // return the same error. 47 EnsureUploaded(ctx context.Context, items []walk.SyncItem, 48 onUploaded func(walk.SyncItem) error, 49 onPresent func(walk.SyncItem) error, 50 onDuplicate func(walk.SyncItem) error, 51 ) error 52 53 // NewPublish creates and returns a new publish object within exodus-gw. 54 NewPublish(context.Context) (Publish, error) 55 56 // GetPublish returns a handle to an existing publish object within exodus-gw. 57 GetPublish(ctx context.Context, id string) (Publish, error) 58 59 // WhoAmI returns raw authentication & authorization info for this exodus-gw client 60 // in the format provided by the "/whoami" endpoint. 61 // 62 // This function is intended for debugging purposes only. 63 WhoAmI(context.Context) (map[string]interface{}, error) 64 } 65 66 // Publish represents a publish object in exodus-gw. 67 type Publish interface { 68 // ID is the unique identifier of a publish. 69 ID() string 70 71 // AddItems will add all of the specified items onto this publish. 72 // This may involve multiple requests to exodus-gw. 73 AddItems(context.Context, []ItemInput) error 74 75 // Commit will cause this publish object to become committed, making all of 76 // the included content available from the CDN. 77 // 78 // The commit operation within exodus-gw is asynchronous. This method will 79 // wait for the commit to complete fully and will return nil only if the 80 // commit has succeeded. 81 // 82 // 'mode' is the desired commit mode (see exodus-gw docs). It can be empty 83 // to not request any particular mode. 84 Commit(ctx context.Context, mode string) error 85 } 86 87 // Task represents a single task object within exodus-gw. 88 type Task interface { 89 // ID is the unique ID of this task. 90 ID() string 91 92 // Await will repeatedly refresh the state of this task from exodus-gw 93 // and return once the task has reached a terminal state. 94 // 95 // The return value will be nil if and only if the task succeeded. 96 Await(context.Context) error 97 }