client

package
v0.0.0-...-5331e25 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright 2017 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2018 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2017 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	StatusInstalling       = "installing"
	StatusDownloading      = "downloading"
	StatusRebooting        = "rebooting"
	StatusSuccess          = "success"
	StatusFailure          = "failure"
	StatusAlreadyInstalled = "already-installed"
)
View Source
const (
	EmptyAuthToken = AuthToken("")
)

Variables

View Source
var AuthErrorUnauthorized = errors.New("authentication request rejected")
View Source
var (
	ErrDeploymentAborted = errors.New("deployment was aborted")
)
View Source
var (
	ErrNotAuthorized = errors.New("client not authorized")
)
View Source
var ExponentialBackoffSmallestUnit time.Duration = time.Minute

Normally one minute, but used in tests to lower the interval to avoid waiting.

Functions

func GetExponentialBackoffTime

func GetExponentialBackoffTime(tried int, maxInterval time.Duration) (time.Duration, error)

Simple algorithm: Start with one minute, and try three times, then double interval (maxInterval is maximum) and try again. Repeat until we tried three times with maxInterval.

Types

type APIError

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

APIError is an error type returned after receiving an error message from the server. It wraps a regular error with the request_id - and if the server returns an error message, this is also returned.

func NewAPIError

func NewAPIError(err error, resp *http.Response) *APIError

func (*APIError) Cause

func (a *APIError) Cause() error

Cause returns the underlying error, as an APIError is merely an error wrapper.

func (*APIError) Error

func (a *APIError) Error() string

type ApiClient

type ApiClient struct {
	http.Client
}

wrapper for http.Client with additional methods

func New

func New(conf Config) (*ApiClient, error)

New initializes new client

func NewApiClient

func NewApiClient(conf Config) (*ApiClient, error)

func (*ApiClient) Request

func (a *ApiClient) Request(code AuthToken, nextServerIterator ServerManagementFunc, reauth ClientReauthorizeFunc) *ApiRequest

Return a new ApiRequest

type ApiRequest

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

ApiRequester compatible helper. The helper can be used for executing API requests that require authorization as provided Do() method will automatically setup authorization information in the request.

func (*ApiRequest) Do

func (ar *ApiRequest) Do(req *http.Request) (*http.Response, error)

Do is a wrapper for http.Do function for ApiRequests. This function in addition to calling http.Do handles client-server authorization header / reauthorization, as well as attempting failover servers (if given) whenever the server "refuse" to serve the request.

type ApiRequester

type ApiRequester interface {
	Do(req *http.Request) (*http.Response, error)
}

Mender API Client wrapper. A standard http.Client is compatible with this interface and can be used without further configuration where ApiRequester is expected. Instead of instantiating the client by yourself, one can also use a wrapper call NewApiClient() that sets up TLS handling according to passed configuration.

type AuthClient

type AuthClient struct {
}

Auth client wrapper. Instantiate by yourself or use `NewAuthClient()` helper

func NewAuth

func NewAuth() *AuthClient

func (*AuthClient) Request

func (u *AuthClient) Request(api ApiRequester, server string, dataSrc AuthDataMessenger) ([]byte, error)

type AuthDataMessenger

type AuthDataMessenger interface {
	// Build authorization request data, returns auth request or an error
	MakeAuthRequest() (*AuthRequest, error)
	// Receive authorization token. Normally, the recipient should store the token
	// in a safe place, so that the token can be used in subsequent API requests.
	RecvAuthResponse([]byte) error
}

Interface capturing a functionality of generating and parsing on authorization messages

type AuthReqData

type AuthReqData struct {
	// identity data
	IdData string `json:"id_data"`
	// tenant token
	TenantToken string `json:"tenant_token"`
	// client's public key
	Pubkey string `json:"pubkey"`
}

Structure representing authorization request data. The caller must fill each field.

func (*AuthReqData) ToBytes

func (ard *AuthReqData) ToBytes() ([]byte, error)

Produce a raw byte sequence with authorization data encoded in a format expected by the backend

type AuthRequest

type AuthRequest struct {
	// raw request message data
	Data []byte
	// tenant's authorization token
	Token AuthToken
	// request signature
	Signature []byte
}

A wrapper for authorization request

type AuthRequester

type AuthRequester interface {
	Request(api ApiRequester, server string, dataSrc AuthDataMessenger) ([]byte, error)
}

type AuthToken

type AuthToken string

type ClientReauthorizeFunc

type ClientReauthorizeFunc func(string) (AuthToken, error)

function type for reauthorization closure (see func reauthorize@mender.go)

type ClientServerCertificateError

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

func (*ClientServerCertificateError) Error

type Config

type Config struct {
	ServerCert string
	IsHttps    bool
	NoVerify   bool
}

type CurrentUpdate

type CurrentUpdate struct {
	Artifact   string
	DeviceType string
}

CurrentUpdate describes currently installed update. Non empty fields will be used when querying for the next update.

type InventoryAttribute

type InventoryAttribute struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

type InventoryClient

type InventoryClient struct {
}

func (*InventoryClient) Submit

func (i *InventoryClient) Submit(api ApiRequester, url string, data interface{}) error

Submit reports status information to the backend

type InventoryData

type InventoryData []InventoryAttribute

func (*InventoryData) ReplaceAttributes

func (id *InventoryData) ReplaceAttributes(attr []InventoryAttribute) error

type InventorySubmitter

type InventorySubmitter interface {
	Submit(api ApiRequester, server string, data interface{}) error
}

func NewInventory

func NewInventory() InventorySubmitter

type LogData

type LogData struct {
	DeploymentID string `json:"-"`
	Messages     []byte `json:"messages"`
}

type LogUploadClient

type LogUploadClient struct {
}

func (*LogUploadClient) Upload

func (u *LogUploadClient) Upload(api ApiRequester, url string, logs LogData) error

Report status information to the backend

type LogUploader

type LogUploader interface {
	Upload(api ApiRequester, server string, logs LogData) error
}

func NewLog

func NewLog() LogUploader

type MenderServer

type MenderServer struct {
	ServerURL string
}

MenderServer is a placeholder for a full server definition used when multiple servers are given. The fields corresponds to the definitions given in menderConfig.

type RequestProcessingFunc

type RequestProcessingFunc func(response *http.Response) (interface{}, error)

type ServerManagementFunc

type ServerManagementFunc func() *MenderServer

function type for setting server (in case of multiple fallover servers)

type StatusClient

type StatusClient struct {
}

func (*StatusClient) Report

func (u *StatusClient) Report(api ApiRequester, url string, report StatusReport) error

Report status information to the backend

type StatusReport

type StatusReport struct {
	DeploymentID string `json:"-"`
	Status       string `json:"status"`
	SubState     string `json:"substate,omitempty"`
}

type StatusReportWrapper

type StatusReportWrapper struct {
	Report StatusReport
	API    ApiRequester
	URL    string
}

StatusReportWrapper holds the data that is passed to the statescript functions upon reporting script exectution-status to the backend.

type StatusReporter

type StatusReporter interface {
	Report(api ApiRequester, server string, report StatusReport) error
}

func NewStatus

func NewStatus() StatusReporter

type UpdateClient

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

func NewUpdate

func NewUpdate() *UpdateClient

func (*UpdateClient) FetchUpdate

func (u *UpdateClient) FetchUpdate(api ApiRequester, url string, maxWait time.Duration) (io.ReadCloser, int64, error)

FetchUpdate returns a byte stream which is a download of the given link.

func (*UpdateClient) GetScheduledUpdate

func (u *UpdateClient) GetScheduledUpdate(api ApiRequester, server string,
	current CurrentUpdate) (interface{}, error)

type UpdateResumer

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

func NewUpdateResumer

func NewUpdateResumer(stream io.ReadCloser,
	contentLength int64,
	maxWait time.Duration,
	apiReq ApiRequester,
	req *http.Request) *UpdateResumer

Note: It is important that nothing has been read from the stream yet.

func (*UpdateResumer) Close

func (h *UpdateResumer) Close() error

func (*UpdateResumer) Read

func (h *UpdateResumer) Read(buf []byte) (int, error)

type Updater

type Updater interface {
	GetScheduledUpdate(api ApiRequester, server string, current CurrentUpdate) (interface{}, error)
	FetchUpdate(api ApiRequester, url string, maxWait time.Duration) (io.ReadCloser, int64, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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