apt

package
v0.0.0-...-96e1417 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2019 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapFlags

type CapFlags int

CapFlags represents a set of Apt Capabilities.

const (
	// CapSingleInstance indicates to Apt that the method may only have one
	// instance running at any given time.
	CapSingleInstance CapFlags = 0x01

	// CapPipeline indicates to Apt that it may send multiple requests to the
	// method without waiting for each one to finish.
	CapPipeline CapFlags = 0x02

	// CapSendConfig tells Apt to send a configuration message back with the
	// config values.
	CapSendConfig CapFlags = 0x04

	// CapLocalOnly indicates to Apt that the resources are fetched locally.
	CapLocalOnly CapFlags = 0x08

	// CapNeedsCleanup tells Apt not to terminate the process when done.
	CapNeedsCleanup CapFlags = 0x10

	// CapRemovable tells Apt the method is working on a removable medium such
	// as a CDROM or USB drive.
	CapRemovable CapFlags = 0x20

	// CapAuxRequests indicates to Apt that the method handles AuxRequests.
	CapAuxRequests CapFlags = 0x40
)

type CloudflaredMethod

type CloudflaredMethod struct {
	// contains filtered or unexported fields
}

CloudflaredMethod holds the fields needed to run the apt method.

func NewCloudflaredMethod

func NewCloudflaredMethod(client *http.Client, output io.Writer, input *bufio.Reader) (*CloudflaredMethod, error)

NewCloudflaredMethod creates a new CloudflaredMethod with the given fields.

func (*CloudflaredMethod) Acquire

func (cfd *CloudflaredMethod) Acquire(uri *url.URL, requrl, filename string) error

Acquire fetches the requested resource.

func (*CloudflaredMethod) BuildRequest

func (cfd *CloudflaredMethod) BuildRequest(client *http.Client, uri *url.URL) (*http.Request, error)

BuildRequest creates a new http.Request for the given URI.

func (*CloudflaredMethod) HandleAcquire

func (cfd *CloudflaredMethod) HandleAcquire(msg *Message)

HandleAcquire handles a '600 Acquire URI' message from apt.

This attempts to get a token for the given host and make a request for the resource with the cf-access-token headers.

TODO: Figure out what an IMS-Hit indicates, and if that applies to this method

func (*CloudflaredMethod) ParseConfig

func (cfd *CloudflaredMethod) ParseConfig(msg *Message) error

ParseConfig takes a config message from apt and sets config values from it.

func (*CloudflaredMethod) Run

func (cfd *CloudflaredMethod) Run() bool

Run is the main entry point for the method.

This function reads messages from apt indefinitely and attempts to handle as many of them as possible.

type Field

type Field struct {
	Key   string
	Value string
}

Field represents a value field in a mesage.

type HeaderEntry

type HeaderEntry struct {
	Key   string
	Value string
}

HeaderEntry represents a header to be added to a request.

type Message

type Message struct {
	StatusCode  uint64
	Description string
	Fields      map[string]string
}

Message represents a generic message as read from os.Stdin.

func NewMessage

func NewMessage(statusCode uint64, description string, fields ...Field) *Message

NewMessage creates a new message with the given fields.

func ParseHeader

func ParseHeader(line string) (*Message, error)

ParseHeader attempts to parse a header out of the given string.

type MessageReader

type MessageReader struct {
	// contains filtered or unexported fields
}

MessageReader implements an interface for reading messages from an input stream.

func NewMessageReader

func NewMessageReader(reader *bufio.Reader) *MessageReader

NewMessageReader creates a new MessageReader instance.

This function sets the underlying bufio.Reader and sets the state such that there is no currently processing message.

func (*MessageReader) ReadLine

func (r *MessageReader) ReadLine() (*Message, error)

ReadLine reads a line from the input and processes it.

This function will read exactly 1 line from the input Reader, and do one of a few things depending on state and the value of the line. If no Message is currently being parsed, then this method will attempt to read a header line and start a new Message instance. If there is a Message being processed, then it will attempt to parse the line as a Field (Name: Value). If the line is empty, then the message is considered done and is returned.

func (*MessageReader) ReadMessage

func (r *MessageReader) ReadMessage() (*Message, error)

ReadMessage reads a full message from the input.

This function calls MessageReader.ReadLine() until a Message is returned and then returns that.

type MessageWriter

type MessageWriter struct {
	// contains filtered or unexported fields
}

MessageWriter is a wrapper around an io.Writer which writes APT messages.

func NewMessageWriter

func NewMessageWriter(w io.Writer) *MessageWriter

NewMessageWriter creates a new MessageWriter.

func (*MessageWriter) AuxRequest

func (mw *MessageWriter) AuxRequest(uri, auxURI, descShort, descLong string, maximumSize uint64, usedMirror bool)

AuxRequest writes a '351 Aux Request' message.

func (*MessageWriter) Capabilities

func (mw *MessageWriter) Capabilities(version string, caps CapFlags)

Capabilities writes a '100 Capabilities' message.

Version must be non-empty. caps may be 0 for no capabilities, though it probably should at least be CapSendConfig (or CapDefault)

func (*MessageWriter) FailedURI

func (mw *MessageWriter) FailedURI(uri, message, failReason string, transientError, usedMirror bool)

FailedURI writes a '400 URI Failure' message.

The message parameter should be "" unless the intent is to send a malformed URI Failure message failReason is only used if transientError is false

func (*MessageWriter) FinishURI

func (mw *MessageWriter) FinishURI(uri, filename, resumePoint, altIMSHit string,
	imsHit, usedMirror bool, extra ...Field)

FinishURI writes a '201 URI Done' message.

func (*MessageWriter) GeneralFailure

func (mw *MessageWriter) GeneralFailure(msg string)

GeneralFailure writes a '401 General Failure' message.

func (*MessageWriter) GeneralFailuref

func (mw *MessageWriter) GeneralFailuref(fmtspec string, args ...interface{})

GeneralFailuref writes a '401 General Failure' message and formats the arguments into it.

func (*MessageWriter) Log

func (mw *MessageWriter) Log(msg string)

Log writes a '101 Log' message.

func (*MessageWriter) Logf

func (mw *MessageWriter) Logf(fmtspec string, args ...interface{})

Logf writes a '101 Log' message and formats the arguments into it.

func (*MessageWriter) MediaChange

func (mw *MessageWriter) MediaChange(media, drive string)

MediaChange writes a '403 Media Change' message.

func (*MessageWriter) Redirect

func (mw *MessageWriter) Redirect(uri, newURI, altURIs string, usedMirror bool)

Redirect writes a '103 Redirect' message

func (*MessageWriter) StartURI

func (mw *MessageWriter) StartURI(uri, resumePoint string, size int64, usedMirror bool)

StartURI writes a '200 URI Start' message.

func (*MessageWriter) Status

func (mw *MessageWriter) Status(msg string)

Status writes a '102 status' message.

func (*MessageWriter) Statusf

func (mw *MessageWriter) Statusf(fmtspec string, args ...interface{})

Statusf writes a '102 status' message and formats the arguments into if.

func (*MessageWriter) Warning

func (mw *MessageWriter) Warning(msg string)

Warning writes a '104 Warning' message.

func (*MessageWriter) Warningf

func (mw *MessageWriter) Warningf(fmtspec string, args ...interface{})

Warningf writes a '104 Warning' message and formats the arguments into it.

func (*MessageWriter) WriteMessage

func (mw *MessageWriter) WriteMessage(msg *Message)

WriteMessage writes a generic Message object as created by NewMessage.

This method is less efficient than the dedicated message functions, as it has to format every part of the message.

type URLWriter

type URLWriter struct {
	// contains filtered or unexported fields
}

URLWriter is a io.Writer which only writes URLS

func NewURLWriter

func NewURLWriter(w io.Writer, prefix string) *URLWriter

NewURLWriter creates a new URLWriter instance.

func (*URLWriter) Write

func (uw *URLWriter) Write(data []byte) (int, error)

Write implements the io.Writer interface.

Write buffers data until it hits a newline, at which point it checks if the buffered data is a URL. If it is, it writes that URL to the MessageWriter instance it was created with, along with the prefix prepended.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL