Documentation ¶
Index ¶
- func CloseAndLog(closer io.Closer, label string, logger Logger)
- func ContextDownload(deps ContextDownloadDeps) (path string, err error)
- func Download(target DownloadTarget, remote ContentSource) error
- func WriteContent(target io.Writer, content Content, deps WriteContentDeps) error
- type Checker
- type ChecksumWriter
- type Content
- type ContentChecker
- type ContentSource
- type ContextDirectorySpec
- type ContextDownloadDeps
- type ContextDownloadDirectory
- type ContextOpenedResource
- type Directory
- type DirectoryDeps
- type DirectorySpec
- type DirectorySpecDeps
- type DownloadDirectory
- type DownloadTarget
- type Logger
- type NopChecker
- type OpenedResource
- type OpenedResourceClient
- type Resolver
- type SizeTracker
- type TempDirDeps
- type TempDirectorySpec
- type WriteContentDeps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseAndLog ¶
CloseAndLog calls the closer's Close() and logs any error returned therefrom.
func ContextDownload ¶
func ContextDownload(deps ContextDownloadDeps) (path string, err error)
ContextDownload downloads the named resource and returns the path to which it was downloaded. If the resource does not exist or has not been uploaded yet then errors.NotFound is returned.
Note that the downloaded file is checked for correctness.
func Download ¶
func Download(target DownloadTarget, remote ContentSource) error
Download downloads the resource from the provied source to the target.
func WriteContent ¶
func WriteContent(target io.Writer, content Content, deps WriteContentDeps) error
WriteContent writes the resource file to the target provided by the deps.
Types ¶
type Checker ¶
type Checker struct { // Content holds the expected content values. Content Content // SizeTracker tracks the number of bytes read. SizeTracker SizeTracker // ChecksumWriter tracks the checksum of the read bytes. ChecksumWriter ChecksumWriter }
Checker provides the functionality for verifying that read data is correct.
func NewContentChecker ¶
func NewContentChecker(content Content, sizeTracker SizeTracker, checksumWriter ChecksumWriter) *Checker
NewContentChecker returns a Checker for the provided data.
type ChecksumWriter ¶
type ChecksumWriter interface { io.Writer // Fingerprint is the fingerprint for the tracked checksum. Fingerprint() charmresource.Fingerprint }
ChecksumWriter tracks the checksum of all written bytes.
type Content ¶
type Content struct { // Data holds the resource content, ready to be read (once). Data io.Reader // Size is the byte count of the data. Size int64 // Fingerprint holds the checksum of the data. Fingerprint charmresource.Fingerprint }
Content holds a reader for the content of a resource along with details about that content.
func (Content) Verify ¶
func (c Content) Verify(size int64, fp charmresource.Fingerprint) error
Verify ensures that the actual resource content details match the expected ones.
type ContentChecker ¶
type ContentChecker interface { // WrapReader wraps the provided reader in another reader // that tracks the read data. WrapReader(io.Reader) io.Reader // Verify fails if the tracked data does not match // the expected data. Verify() error }
ContentChecker exposes functionality for verifying the data read from a reader.
type ContentSource ¶
type ContentSource interface { // Content returns the content for the opened resource. Content() Content // Info returns the info for the opened resource. Info() resource.Resource }
ContentSource represents the functionality of OpenedResource, relative to Content.
type ContextDirectorySpec ¶
type ContextDirectorySpec interface { Resolver // Initializeprepares the target directory and returns it. Initialize() (DownloadDirectory, error) // IsUpToDate indicates whether or not the resource dir is in sync // with the content. IsUpToDate(Content) (bool, error) }
ContextDirectorySpec exposes the functionality of a resource dir spec in a hook context.
func NewContextDirectorySpec ¶
func NewContextDirectorySpec(dataDir, name string, deps DirectorySpecDeps) ContextDirectorySpec
NewContextDirectorySpec returns a new directory spec for the context.
type ContextDownloadDeps ¶
type ContextDownloadDeps interface { // NewContextDirectorySpec returns the dir spec for the resource // in the hook context. NewContextDirectorySpec() ContextDirectorySpec // OpenResource reads the resource info and opens the resource // content for reading. OpenResource() (ContextOpenedResource, error) // CloseAndLog closes the closer and logs any error. CloseAndLog(io.Closer, string) // Download writes the remote to the target directory. Download(DownloadTarget, ContextOpenedResource) error }
ContextDownloadDeps provides the externally defined functions on which ContextDownload depends. The functionality all relates to a single resource.
type ContextDownloadDirectory ¶
type ContextDownloadDirectory struct {
*TempDirectorySpec
}
ContextDownloadDirectory is an adapter for TempDirectorySpec.
func (ContextDownloadDirectory) Initialize ¶
func (dir ContextDownloadDirectory) Initialize() (DownloadDirectory, error)
Initialize implements DownloadTarget.
type ContextOpenedResource ¶
type ContextOpenedResource interface { ContentSource io.Closer }
ContextOpenedResource exposes the functionality of an "opened" resource.
type Directory ¶
type Directory struct { *DirectorySpec // Deps holds the external dependencies of the directory. Deps DirectoryDeps }
Directory represents a resource directory.
func NewDirectory ¶
func NewDirectory(spec *DirectorySpec, deps DirectoryDeps) *Directory
NewDirectory returns a new directory for the provided spec.
func (*Directory) Write ¶
func (dir *Directory) Write(opened ContentSource) error
Write writes all relevant files from the given source to the directory.
type DirectoryDeps ¶
type DirectoryDeps interface { // CreateWriter creates a new writer to which the resource file // will be written. CreateWriter(string) (io.WriteCloser, error) // CloseAndLog closes the closer and logs any error. CloseAndLog(io.Closer, string) // WriteContent writes the content to the directory. WriteContent(io.Writer, Content) error }
DirectoryDeps exposes the external functionality needed by Directory.
type DirectorySpec ¶
type DirectorySpec struct { // Name is the resource name. Name string // Dirname is the path to the resource directory. Dirname string // Deps is the external dependencies of DirectorySpec. Deps DirectorySpecDeps }
DirectorySpec identifies information for a resource directory.
func NewDirectorySpec ¶
func NewDirectorySpec(dataDir, name string, deps DirectorySpecDeps) *DirectorySpec
NewDirectorySpec returns a new directory spec for the given info.
func (DirectorySpec) Initialize ¶
func (spec DirectorySpec) Initialize() (*Directory, error)
Initialize preps the spec'ed directory and returns it.
func (DirectorySpec) IsUpToDate ¶
func (spec DirectorySpec) IsUpToDate(content Content) (bool, error)
IsUpToDate determines whether or not the content matches the resource directory.
func (DirectorySpec) Resolve ¶
func (spec DirectorySpec) Resolve(path ...string) string
Resolve returns the fully resolved file path, relative to the directory.
type DirectorySpecDeps ¶
type DirectorySpecDeps interface { DirectoryDeps // FingerprintMatches determines whether or not the identified file // exists and has the provided fingerprint. FingerprintMatches(filename string, fp charmresource.Fingerprint) (bool, error) // Join exposes the functionality of filepath.Join(). Join(...string) string // MkdirAll exposes the functionality of os.MkdirAll(). MkdirAll(string) error }
DirectorySpecDeps exposes the external depenedencies of DirectorySpec.
type DownloadDirectory ¶
type DownloadDirectory interface { Resolver // Write writes all the relevant files for the provided source // to the directory. Write(ContentSource) error }
DownloadDirectory exposes the functionality of a resource directory needed by Download().
type DownloadTarget ¶
type DownloadTarget interface { // Initialize prepares the target directory and returns it. Initialize() (DownloadDirectory, error) }
DownloadTarget exposes the functionality of a directory spec needed by Download().
type Logger ¶
type Logger interface { // Errorf formats the provided log message and writes it to the log. Errorf(string, ...interface{}) }
Logger exposes the logger functionality needed by CloseAndLog.
type NopChecker ¶
type NopChecker struct{}
NopChecker is a ContentChecker that accepts all data.
func (NopChecker) WrapReader ¶
func (NopChecker) WrapReader(reader io.Reader) io.Reader
WrapReader implements ContentChecker.
type OpenedResource ¶
type OpenedResource struct { resource.Resource io.ReadCloser }
OpenedResource wraps the resource info and reader returned from the API.
func OpenResource ¶
func OpenResource(name string, client OpenedResourceClient) (*OpenedResource, error)
OpenResource opens the identified resource using the provided client.
func (OpenedResource) Content ¶
func (or OpenedResource) Content() Content
Content returns the "content" for the opened resource.
func (OpenedResource) Info ¶
func (or OpenedResource) Info() resource.Resource
Info returns the info for the opened resource.
type OpenedResourceClient ¶
type OpenedResourceClient interface { // GetResource returns the resource info and content for the given // name (and unit-implied application). GetResource(resourceName string) (resource.Resource, io.ReadCloser, error) }
OpenedResourceClient exposes the API functionality needed by OpenResource.
type Resolver ¶
type Resolver interface { // Resolve returns the fully resolved path for the provided path items. Resolve(...string) string }
Resolver exposes the functionality of DirectorySpec needed by DownloadIndirect.
type SizeTracker ¶
SizeTracker tracks the number of bytes written.
type TempDirDeps ¶
type TempDirDeps interface { DirectorySpecDeps // NewTempDir returns the path to a new temporary directory. NewTempDir() (string, error) // RemoveDir deletes the specified directory. RemoveDir(string) error }
TempDirDeps exposes the external functionality needed by NewTempDirectorySpec().
type TempDirectorySpec ¶
type TempDirectorySpec struct { *DirectorySpec // CleanUp cleans up the temp directory in which the resource // directory is placed. CleanUp func() error }
TempDirectorySpec represents a resource directory placed under a temporary data dir.
func NewTempDirectorySpec ¶
func NewTempDirectorySpec(name string, deps TempDirDeps) (*TempDirectorySpec, error)
NewTempDirectorySpec creates a new temp directory spec for the given resource.
func (TempDirectorySpec) Close ¶
func (spec TempDirectorySpec) Close() error
Close implements io.Closer.
type WriteContentDeps ¶
type WriteContentDeps interface { //NewChecker provides a content checker for the given content. NewChecker(Content) ContentChecker // Copy copies the data from the reader into the writer. Copy(io.Writer, io.Reader) error }
WriteContentDeps exposes the external functionality needed by WriteContent.