network

package
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const MAX_ERR_MSG_SIZE = 2048

Don't log error messages longer than this

Variables

This section is empty.

Functions

func RedirectHandler

func RedirectHandler(req *http.Request, via []*http.Request) error

By default, the Go HTTP client does not send headers from the original request to the redirect location. See the issue at https://code.google.com/p/go/issues/detail?id=4800&q=request%20header

We want to send all headers from the original request, but we'll send the auth header only if the host of the redirect URL matches the host of the original URL.

Types

type DPNResponse

type DPNResponse struct {
	Count    int
	Next     *string
	Previous *string
	Request  *http.Request
	Response *http.Response
	Error    error
	// contains filtered or unexported fields
}

DPNResponse is the structure returned by all requests to the DPN REST servers. After making a request to a DPN REST server, you'll want to check the Error property of the response struct, and then call the method to return the type of object you requested.

func NewDPNResponse

func NewDPNResponse(objType dpn.DPNObjectType) *DPNResponse

NewDPNResponse returns a pointer to a new response object.

func (*DPNResponse) Bag

func (resp *DPNResponse) Bag() *models.DPNBag

Bag returns the Bag parsed from the HTTP response body, or nil.

func (*DPNResponse) Bags

func (resp *DPNResponse) Bags() []*models.DPNBag

Bags returns a list of Bags parsed from the HTTP response body.

func (*DPNResponse) Digest

func (resp *DPNResponse) Digest() *models.MessageDigest

Digest returns the Digest object parsed from the HTTP response body, or nil.

func (*DPNResponse) Digests

func (resp *DPNResponse) Digests() []*models.MessageDigest

Digests returns a list of Digests parsed from the HTTP response body.

func (*DPNResponse) FixityCheck

func (resp *DPNResponse) FixityCheck() *models.FixityCheck

FixityCheck returns the FixityCheck object parsed from the HTTP response body, or nil.

func (*DPNResponse) FixityChecks

func (resp *DPNResponse) FixityChecks() []*models.FixityCheck

FixityChecks returns a list of FixityChecks parsed from the HTTP response body.

func (*DPNResponse) HasNextPage

func (resp *DPNResponse) HasNextPage() bool

HasNextPage returns true if the response includes a link to the next page of results.

func (*DPNResponse) HasPreviousPage

func (resp *DPNResponse) HasPreviousPage() bool

HasPreviousPage returns true if the response includes a link to the previous page of results.

func (*DPNResponse) Ingest

func (resp *DPNResponse) Ingest() *models.Ingest

Ingest returns the Ingest object parsed from the HTTP response body, or nil.

func (*DPNResponse) Ingests

func (resp *DPNResponse) Ingests() []*models.Ingest

Ingests returns a list of Ingests parsed from the HTTP response body.

func (*DPNResponse) Member

func (resp *DPNResponse) Member() *models.Member

Member returns the Member object parsed from the HTTP response body, or nil.

func (*DPNResponse) Members

func (resp *DPNResponse) Members() []*models.Member

Members returns a list of Members parsed from the HTTP response body.

func (*DPNResponse) Node

func (resp *DPNResponse) Node() *models.Node

Node returns the Node object parsed from the HTTP response body, or nil.

func (*DPNResponse) Nodes

func (resp *DPNResponse) Nodes() []*models.Node

Nodes returns a list of Nodes parsed from the HTTP response body.

func (*DPNResponse) ObjectType

func (resp *DPNResponse) ObjectType() dpn.DPNObjectType

ObjectType returns the type of object(s) contained in this response.

func (*DPNResponse) ParamsForNextPage

func (resp *DPNResponse) ParamsForNextPage() url.Values

ParamsForNextPage returns the URL parameters to request the next page of results, or nil if there is no next page.

func (*DPNResponse) ParamsForPreviousPage

func (resp *DPNResponse) ParamsForPreviousPage() url.Values

ParamsForPreviousPage returns the URL parameters to request the previous page of results, or nil if there is no previous page.

func (*DPNResponse) RawResponseData

func (resp *DPNResponse) RawResponseData() ([]byte, error)

RawResponseData returns the raw body of the HTTP response as a byte slice. The return value may be nil.

func (*DPNResponse) ReplicationTransfer

func (resp *DPNResponse) ReplicationTransfer() *models.ReplicationTransfer

ReplicationTransfer returns the ReplicationTransfer object parsed from the HTTP response body, or nil.

func (*DPNResponse) ReplicationTransfers

func (resp *DPNResponse) ReplicationTransfers() []*models.ReplicationTransfer

ReplicationTransfers returns a list of ReplicationTransfers parsed from the HTTP response body.

func (*DPNResponse) RestoreTransfer

func (resp *DPNResponse) RestoreTransfer() *models.RestoreTransfer

RestoreTransfer returns the RestoreTransfer parsed from the HTTP response body, or nil.

func (*DPNResponse) RestoreTransfers

func (resp *DPNResponse) RestoreTransfers() []*models.RestoreTransfer

RestoreTransfers returns a list of RestoreTransfers parsed from the HTTP response body.

func (*DPNResponse) UnmarshalJsonList

func (resp *DPNResponse) UnmarshalJsonList() error

UnmashalJsonList deserializes the JSON response data from the server into a list of DPN objects.

type DPNRestClient

type DPNRestClient struct {
	HostUrl    string
	APIVersion string
	APIKey     string
	Node       string
	// contains filtered or unexported fields
}

DPNRestClient is a client for the DPN REST API. Common params for "List" methods include page (the page number in a paged result set), page_size (the number of results per page to retrieve), order_by (which can be created_at or updated_at, and always returns results in descending order), before (which includes only items whose updated_at is before the specified timestamp) and after (which includes only items whose updated_at is after the specified timestamp). Additional information about the DPN server and its capabilities are available at http://chronopolis01.umiacs.umd.edu/ or any swagger server that points to https://raw.githubusercontent.com/dpn-admin/dpn-rest-spec/master/dist/swagger.yaml

The main dpn-server repo is available at https://github.com/dpn-admin/dpn-server

func NewDPNRestClient

func NewDPNRestClient(hostUrl, apiVersion, apiKey, node string, dpnConfig apt_models.DPNConfig) (*DPNRestClient, error)

NewDPNRestClient creates a new DPN REST client.

func (*DPNRestClient) BuildUrl

func (client *DPNRestClient) BuildUrl(relativeUrl string, queryParams url.Values) string

BuildUrl combines the host and protocol in client.HostUrl with relativeUrl to create an absolute URL. For example, if client.HostUrl is "http://localhost:3456", then client.BuildUrl("/path/to/action.json") would return "http://localhost:3456/path/to/action.json".

func (*DPNRestClient) DPNBagCreate

func (client *DPNRestClient) DPNBagCreate(bag *models.DPNBag) *DPNResponse

DPNBagCreate creates a new bag. Note that you can create bags only at your own node.

func (*DPNRestClient) DPNBagGet

func (client *DPNRestClient) DPNBagGet(identifier string) *DPNResponse

DPNBagGet returns a DPNResponse with the bag having the specified identifier, if it exists.

func (*DPNRestClient) DPNBagList

func (client *DPNRestClient) DPNBagList(params url.Values) *DPNResponse

DPNBagList lists bags matching the specified parameters. Valid parameters include before, after, bag_type, admin_node, ingest_node, member, replicated_by, first_version_uuid, page, page_size, order_by.

func (*DPNRestClient) DPNBagUpdate

func (client *DPNRestClient) DPNBagUpdate(bag *models.DPNBag) *DPNResponse

DPNBagUpdate updates an existing bag. Note that you can update bags only at your own node.

func (*DPNRestClient) DigestCreate

func (client *DPNRestClient) DigestCreate(digest *models.MessageDigest) *DPNResponse

DigestCreate creates a MessageDigest record.

func (*DPNRestClient) DigestGet

func (client *DPNRestClient) DigestGet(bagUUID, algorithm string) *DPNResponse

DigestGet returns the message digest for the specified bag with the specified algorithm, if it exists.

func (*DPNRestClient) DigestList

func (client *DPNRestClient) DigestList(params url.Values) *DPNResponse

DigestList returns a list of MessageDigests that match the specified criteria. Param uuid (the uuid of the bag to which the digests belong) is required according to DPN REST server docs, though server may respond without error. Optional params include before, after, page, page_size, and order_by.

func (*DPNRestClient) FixityCheckCreate

func (client *DPNRestClient) FixityCheckCreate(fixity *models.FixityCheck) *DPNResponse

FixityCheckCreate creates a new FixityCheck

func (*DPNRestClient) FixityCheckList

func (client *DPNRestClient) FixityCheckList(params url.Values) *DPNResponse

FixityCheckList returns a list of FixityCheck records. Valid params include before, after, bag, latest, node, page, page_size, order_by. Param latest is a boolean. If true, only the latest fixity check(s) for each bag will be returned. Note that the DPN 2.0 server does not implement FixityCheckGet.

func (*DPNRestClient) GetRemoteClient

func (client *DPNRestClient) GetRemoteClient(remoteNodeNamespace string, dpnConfig apt_models.DPNConfig) (*DPNRestClient, error)

Returns a DPN REST client that can talk to a remote node. This function has to connect to out local DPN node to get information about the remote node. It returns a new client that can connect to the remote node with the correct URL and API key. We use this function to get a client that can update a replication request or a restore request on the originating node.

func (*DPNRestClient) GetRemoteClients

func (client *DPNRestClient) GetRemoteClients() (map[string]*DPNRestClient, error)

GetRemoteClients returns a map of clients that can connect to remote DPN REST services. These clients are used to pull data from other nodes and to update the status of replication and restore requests on other nodes. The key in the returned map is the remote node's namespace. The value is a pointer to a client object that connects to that node.

This will return ONLY those clients for whom the config file contains a RemoteNodeToken entry, because it's impossible to connect to a remote node without a token.

func (*DPNRestClient) IngestCreate

func (client *DPNRestClient) IngestCreate(ingest *models.Ingest) *DPNResponse

IngestCreate creates a new Ingest record.

func (*DPNRestClient) IngestList

func (client *DPNRestClient) IngestList(params url.Values) *DPNResponse

IngestList returns a list of Ingest records that match the specified criteria. Valid params include before, after, bag, ingested, latest, page, page_size, order_by. See the swagger docs for more info. Note that the DPN 2.0 server does not implement IngestGet.

func (*DPNRestClient) MemberCreate

func (client *DPNRestClient) MemberCreate(member *models.Member) *DPNResponse

MemberCreate creates a new member in the DPN repository.

func (*DPNRestClient) MemberGet

func (client *DPNRestClient) MemberGet(identifier string) *DPNResponse

MemberGet returns a DPNResponse containing the member with the specified identifier, if that member exists.

func (*DPNRestClient) MemberList

func (client *DPNRestClient) MemberList(params url.Values) *DPNResponse

MemberList returns a DPNResponse members that match the specific params. Valid params include before, after, page, page_size and order_by.

func (*DPNRestClient) MemberUpdate

func (client *DPNRestClient) MemberUpdate(member *models.Member) *DPNResponse

MemberUpdate creates a new member in the DPN repository.

func (*DPNRestClient) NewJsonRequest

func (client *DPNRestClient) NewJsonRequest(method, targetUrl string, body io.Reader) (*http.Request, error)

newJsonGet returns a new request with headers indicating JSON request and response formats.

func (*DPNRestClient) NodeGet

func (client *DPNRestClient) NodeGet(identifier string) *DPNResponse

NodeGet returns the node with the specified identifier (namespace).

func (*DPNRestClient) NodeGetLastPullDate

func (client *DPNRestClient) NodeGetLastPullDate(identifier string) (time.Time, error)

NodeGetLastPullDate returns the last time we pulled data from the specified node. The last pull date is derived from the latest updated_at timestamp for bags from the specified admin_node.

func (*DPNRestClient) NodeList

func (client *DPNRestClient) NodeList(params url.Values) *DPNResponse

NodeList returns a DPNResponse containing nodes that match the specified params. Valid params include before, after, page, page_size, and order_by. This call is deprecated in DPN 2.0 and may disappear in later versions.

func (*DPNRestClient) NodeUpdate

func (client *DPNRestClient) NodeUpdate(node *models.Node) *DPNResponse

NodeUpdate updates a DPN Node record. You can update node records only if you are the admin on the server where you're updating the record. Though this method lets you update any attributes related to the node, you should update only the LastPullDate attribute through this client. Use the web admin interface to perform more substantive node updates.

func (*DPNRestClient) ReplicationTransferCreate

func (client *DPNRestClient) ReplicationTransferCreate(xfer *models.ReplicationTransfer) *DPNResponse

ReplicationTransferCreate creates a ReplicationTransfer. You can only create transfers on your own node.

func (*DPNRestClient) ReplicationTransferGet

func (client *DPNRestClient) ReplicationTransferGet(identifier string) *DPNResponse

ReplicationTransferGet returns the ReplicationTransfer with the specified ReplicationId, if it exists. The ReplicationId is a UUID string.

func (*DPNRestClient) ReplicationTransferList

func (client *DPNRestClient) ReplicationTransferList(params url.Values) *DPNResponse

ReplicationTransferList returns a list of ReplicationTransfers matching the specified criteria. Valid params include before, after, bag, to_node, from_node, store_requested, stored, cancelled, cancel_reason, page, page_size, order_by.

func (*DPNRestClient) ReplicationTransferUpdate

func (client *DPNRestClient) ReplicationTransferUpdate(xfer *models.ReplicationTransfer) *DPNResponse

ReplicationTransferUpdate updates a ReplicationTransfer. You can updated transfers on remote nodes if they are the from_node and you are the to_node.

func (*DPNRestClient) RestoreTransferCreate

func (client *DPNRestClient) RestoreTransferCreate(xfer *models.RestoreTransfer) *DPNResponse

RestoreTransferCreate creates a RestoreTransfer request, which you can do only on your own node.

func (*DPNRestClient) RestoreTransferGet

func (client *DPNRestClient) RestoreTransferGet(identifier string) *DPNResponse

RestoreTransferGet returns the RestoreTransfer with the specified identifier.

func (*DPNRestClient) RestoreTransferList

func (client *DPNRestClient) RestoreTransferList(params url.Values) *DPNResponse

RestoreTransferList returns a list of RestoreTransfers matching the specified criteria. Valid params include before, after, bag, to_node, from_node, accepted, finished, cancelled, cancel_reason, page, page_size, order_by.

func (*DPNRestClient) RestoreTransferUpdate

func (client *DPNRestClient) RestoreTransferUpdate(xfer *models.RestoreTransfer) *DPNResponse

RestoreTransferUpdate updates a RestoreTransfer request, which you can do on your own node if you are the to_node, or on the to_node if you are the from_node.

Jump to

Keyboard shortcuts

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