Documentation ¶
Overview ¶
Copyright 2023 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 2023 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 2023 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 2023 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 2023 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 2022 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 2023 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 2023 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
- Variables
- func GetExponentialBackoffTime(tried int, maxInterval time.Duration, maxAttempts int) (time.Duration, error)
- func GetUpdateControlMap(api ApiRequester, serverURL, deploymentID string) (cm *updatecontrolmap.UpdateControlMap, err error)
- func NewWebsocketDialer(conf Config) (*websocket.Dialer, error)
- type APIError
- type ApiClient
- type ApiRequester
- type AuthClient
- type AuthDataMessenger
- type AuthReqData
- type AuthRequest
- type AuthRequester
- type AuthToken
- type AuthorizedApiRequester
- type ClientReauthorizeFunc
- type Config
- type Connectivity
- type CurrentUpdate
- type HttpsClient
- type InventoryAttribute
- type InventoryClient
- type InventoryData
- type InventorySubmitter
- type LogData
- type LogUploadClient
- type LogUploader
- type MenderServer
- type ReauthorizingClient
- type RequestProcessingFunc
- type Security
- type ServerURL
- type StatusClient
- type StatusReport
- type StatusReportWrapper
- type StatusReporter
- type UpdateClient
- type UpdateResponse
- type UpdateResumer
- type UpdateV2Body
- type Updater
Constants ¶
const ( StatusInstalling = "installing" StatusDownloading = "downloading" StatusRebooting = "rebooting" StatusSuccess = "success" StatusFailure = "failure" )
const (
EmptyAuthToken = AuthToken("")
)
Variables ¶
var ( ErrNotAuthorized = errors.New("client not authorized") ErrNoDeploymentAvailable = errors.New("no deployment available") ErrServerInvalidResponse = errors.New("Invalid response received from the server") )
var (
)var (
ErrDeploymentAborted = errors.New("deployment was aborted")
)
var ExponentialBackoffSmallestUnit time.Duration = time.Minute
Normally one minute, but used in tests to lower the interval to avoid waiting.
var MaxRetriesExceededError = errors.New("Tried maximum amount of times")
var ProxyURLFromHostPortGetter = func(addr string) (*url.URL, error) { u, err := url.Parse("https://" + addr) if err != nil { return u, err } return http.ProxyFromEnvironment(&http.Request{URL: u}) }
http.ProxyFromEnvironment returns nil if parameter req.URL is localhost. This function variable is public so it can be overriden in tests.
Functions ¶
func GetExponentialBackoffTime ¶
func GetExponentialBackoffTime(tried int, maxInterval time.Duration, maxAttempts int) (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.
func GetUpdateControlMap ¶
func GetUpdateControlMap( api ApiRequester, serverURL, deploymentID string, ) (cm *updatecontrolmap.UpdateControlMap, err error)
GetUpdateControlMap - requests an udpate control map refresh from the server
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.
type ApiClient ¶
func NewApiClient ¶
type ApiRequester ¶
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) }
Interface capturing functionality of generating 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 AuthorizedApiRequester ¶
type AuthorizedApiRequester interface { ApiRequester ClearAuthorization() }
An ApiRequester which internally authorizes automatically. It's possible to call ClearAuthorization() in order to force reauthorization.
type ClientReauthorizeFunc ¶
function type for reauthorization closure (see func reauthorize@mender.go)
type Config ¶
type Config struct { ServerCert string *HttpsClient *Connectivity NoVerify bool }
type Connectivity ¶
type Connectivity struct { // If set to true, there will be no persistent connections, and every // HTTP transaction will try to establish a new connection DisableKeepAlive bool `json:",omitempty"` // A number of seconds after which a connection is considered idle and closed. // The longer this is the longer connections are up after the first call over HTTP IdleConnTimeoutSeconds int `json:",omitempty"` }
Connectivity instructs the client how we want to treat the keep alive connections and when a connection is considered idle and therefore closed NOTE: Careful when changing this, the struct is exposed directly in the 'mender.conf' file.
type CurrentUpdate ¶
type CurrentUpdate struct { Artifact string `json:"artifact_name"` DeviceType string `json:"device_type"` Provides map[string]string }
CurrentUpdate describes currently installed update. Non empty fields will be used when querying for the next update.
func (*CurrentUpdate) MarshalJSON ¶
func (u *CurrentUpdate) MarshalJSON() ([]byte, error)
type HttpsClient ¶
type HttpsClient struct { Certificate string `json:",omitempty"` Key string `json:",omitempty"` SSLEngine string `json:",omitempty"` }
HttpsClient holds the configuration for the client side mTLS configuration NOTE: Careful when changing this, the struct is exposed directly in the 'mender.conf' file.
func (*HttpsClient) Validate ¶
func (h *HttpsClient) Validate()
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 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 ReauthorizingClient ¶
type ReauthorizingClient struct { // contains filtered or unexported fields }
func NewReauthorizingClient ¶
func NewReauthorizingClient( conf Config, reauth ClientReauthorizeFunc, ) (*ReauthorizingClient, error)
func (*ReauthorizingClient) ClearAuthorization ¶
func (c *ReauthorizingClient) ClearAuthorization()
type RequestProcessingFunc ¶
type Security ¶
type Security struct { AuthPrivateKey string `json:",omitempty"` SSLEngine string `json:",omitempty"` }
Security structure holds the configuration for the client Added for MEN-3924 in order to provide a way to specify PKI params outside HttpsClient. NOTE: Careful when changing this, the struct is exposed directly in the 'mender.conf' file.
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 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 UpdateResponse ¶
type UpdateResponse struct { *datastore.UpdateInfo // The Update Control Map unmarshaller rejects unknown fields. This is // in contrast to the rest of the response, where we allow unknown // fields. UpdateControlMap *updatecontrolmap.UpdateControlMap `json:"update_control_map"` }
func (*UpdateResponse) Validate ¶
func (u *UpdateResponse) Validate() (err 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
type UpdateV2Body ¶
type UpdateV2Body struct { DeviceProvides *CurrentUpdate `json:"device_provides"` UpdateControlMap bool `json:"update_control_map"` }
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) }