juju: github.com/wallyworld/juju/resource/context/internal Index | Files

package internal

import "github.com/wallyworld/juju/resource/context/internal"


Package Files

content.go context.go download.go resource.go resourcedir.go util.go

func CloseAndLog Uses

func CloseAndLog(closer io.Closer, label string, logger Logger)

CloseAndLog calls the closer's Close() and logs any error returned therefrom.

func ContextDownload Uses

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 Uses

func Download(target DownloadTarget, remote ContentSource) error

Download downloads the resource from the provied source to the target.

func WriteContent Uses

func WriteContent(target io.Writer, content Content, deps WriteContentDeps) error

WriteContent writes the resource file to the target provided by the deps.

type Checker Uses

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 Uses

func NewContentChecker(content Content, sizeTracker SizeTracker, checksumWriter ChecksumWriter) *Checker

NewContentChecker returns a Checker for the provided data.

func (Checker) Verify Uses

func (c Checker) Verify() error

Verify implements ContentChecker.

func (Checker) WrapReader Uses

func (c Checker) WrapReader(reader io.Reader) io.Reader

WrapReader implements ContentChecker.

type ChecksumWriter Uses

type ChecksumWriter interface {

    // Fingerprint is the fingerprint for the tracked checksum.
    Fingerprint() charmresource.Fingerprint

ChecksumWriter tracks the checksum of all written bytes.

type Content Uses

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 Uses

func (c Content) Verify(size int64, fp charmresource.Fingerprint) error

Verify ensures that the actual resource content details match the expected ones.

type ContentChecker Uses

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 Uses

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 Uses

type ContextDirectorySpec interface {

    // 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 Uses

func NewContextDirectorySpec(dataDir, name string, deps DirectorySpecDeps) ContextDirectorySpec

NewContextDirectorySpec returns a new directory spec for the context.

type ContextDownloadDeps Uses

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 Uses

type ContextDownloadDirectory struct {

ContextDownloadDirectory is an adapter for TempDirectorySpec.

func (ContextDownloadDirectory) Initialize Uses

func (dir ContextDownloadDirectory) Initialize() (DownloadDirectory, error)

Initialize implements DownloadTarget.

type ContextOpenedResource Uses

type ContextOpenedResource interface {

ContextOpenedResource exposes the functionality of an "opened" resource.

type Directory Uses

type Directory struct {

    // Deps holds the external dependencies of the directory.
    Deps DirectoryDeps

Directory represents a resource directory.

func NewDirectory Uses

func NewDirectory(spec *DirectorySpec, deps DirectoryDeps) *Directory

NewDirectory returns a new directory for the provided spec.

func (*Directory) Write Uses

func (dir *Directory) Write(opened ContentSource) error

Write writes all relevant files from the given source to the directory.

func (*Directory) WriteContent Uses

func (dir *Directory) WriteContent(relPath string, content Content) error

WriteContent writes the resource file to the given path within the directory.

type DirectoryDeps Uses

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 Uses

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 Uses

func NewDirectorySpec(dataDir, name string, deps DirectorySpecDeps) *DirectorySpec

NewDirectorySpec returns a new directory spec for the given info.

func (DirectorySpec) Initialize Uses

func (spec DirectorySpec) Initialize() (*Directory, error)

Initialize preps the spec'ed directory and returns it.

func (DirectorySpec) IsUpToDate Uses

func (spec DirectorySpec) IsUpToDate(content Content) (bool, error)

IsUpToDate determines whether or not the content matches the resource directory.

func (DirectorySpec) Resolve Uses

func (spec DirectorySpec) Resolve(path ...string) string

Resolve returns the fully resolved file path, relative to the directory.

type DirectorySpecDeps Uses

type DirectorySpecDeps interface {

    // 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 Uses

type DownloadDirectory interface {

    // 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 Uses

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 Uses

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 Uses

type NopChecker struct{}

NopChecker is a ContentChecker that accepts all data.

func (NopChecker) Verify Uses

func (NopChecker) Verify() error

Verify implements ContentChecker.

func (NopChecker) WrapReader Uses

func (NopChecker) WrapReader(reader io.Reader) io.Reader

WrapReader implements ContentChecker.

type OpenedResource Uses

type OpenedResource struct {

OpenedResource wraps the resource info and reader returned from the API.

func OpenResource Uses

func OpenResource(name string, client OpenedResourceClient) (*OpenedResource, error)

OpenResource opens the identified resource using the provided client.

func (OpenedResource) Content Uses

func (or OpenedResource) Content() Content

Content returns the "content" for the opened resource.

func (OpenedResource) Info Uses

func (or OpenedResource) Info() resource.Resource

Info returns the info for the opened resource.

type OpenedResourceClient Uses

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 Uses

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 Uses

type SizeTracker interface {

    // Size returns the number of bytes written.
    Size() int64

SizeTracker tracks the number of bytes written.

type TempDirDeps Uses

type TempDirDeps interface {

    // 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 Uses

type TempDirectorySpec struct {

    // 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 Uses

func NewTempDirectorySpec(name string, deps TempDirDeps) (*TempDirectorySpec, error)

NewTempDirectorySpec creates a new temp directory spec for the given resource.

func (TempDirectorySpec) Close Uses

func (spec TempDirectorySpec) Close() error

Close implements io.Closer.

type WriteContentDeps Uses

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.

Package internal imports 9 packages (graph). Updated 2020-05-17. Refresh now. Tools for package owners.