• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 950534094

pending completion
950534094

push

gitlab-ci

kacf
chore: Add `StartsWith` and `EndsWith` generic utility functions.

Also use the latter in `states.cpp`.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

1 of 1 new or added line in 1 file covered. (100.0%)

4931 of 6276 relevant lines covered (78.57%)

196.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/mender-update/deployments.hpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#ifndef MENDER_UPDATE_DEPLOYMENTS_HPP
16
#define MENDER_UPDATE_DEPLOYMENTS_HPP
17

18
#include <string>
19
#include <vector>
20

21
#include <common/error.hpp>
22
#include <common/events.hpp>
23
#include <common/expected.hpp>
24
#include <common/http.hpp>
25
#include <common/io.hpp>
26
#include <common/json.hpp>
27
#include <common/optional.hpp>
28
#include <mender-update/context.hpp>
29

30
namespace mender {
31
namespace update {
32
namespace deployments {
33

34
using namespace std;
35

36
namespace context = mender::update::context;
37
namespace error = mender::common::error;
38
namespace events = mender::common::events;
39
namespace expected = mender::common::expected;
40
namespace io = mender::common::io;
41
namespace json = mender::common::json;
42
namespace optional = mender::common::optional;
43

44
enum DeploymentsErrorCode {
45
        NoError = 0,
46
        InvalidDataError,
47
        BadResponseError,
48
};
49

50
class DeploymentsErrorCategoryClass : public std::error_category {
51
public:
52
        const char *name() const noexcept override;
53
        string message(int code) const override;
54
};
55
extern const DeploymentsErrorCategoryClass DeploymentsErrorCategory;
56

57
error::Error MakeError(DeploymentsErrorCode code, const string &msg);
58

59
using CheckUpdatesAPIResponse = expected::expected<optional::optional<json::Json>, error::Error>;
60
using CheckUpdatesAPIResponseHandler = function<void(CheckUpdatesAPIResponse)>;
61

62
enum class DeploymentStatus {
63
        Installing = 0,
64
        PauseBeforeInstalling,
65
        Downloading,
66
        PauseBeforeRebooting,
67
        Rebooting,
68
        PauseBeforeCommitting,
69
        Success,
70
        Failure,
71
        AlreadyInstalled,
72

73
        // Not a valid status, just used as an int representing the number of values
74
        // above
75
        End_
76
};
77

78
string DeploymentStatusString(DeploymentStatus status);
79

80
using StatusAPIResponse = error::Error;
81
using StatusAPIResponseHandler = function<void(StatusAPIResponse)>;
82

83
using LogsAPIResponse = error::Error;
84
using LogsAPIResponseHandler = function<void(LogsAPIResponse)>;
85

86
class DeploymentAPI {
87
public:
88
        virtual ~DeploymentAPI() {
×
89
        }
×
90

91
        virtual error::Error CheckNewDeployments(
92
                context::MenderContext &ctx,
93
                const string &server_url,
94
                http::Client &client,
95
                CheckUpdatesAPIResponseHandler api_handler) = 0;
96
        virtual error::Error PushStatus(
97
                const string &deployment_id,
98
                DeploymentStatus status,
99
                const string &substate,
100
                const string &server_url,
101
                http::Client &client,
102
                StatusAPIResponseHandler api_handler) = 0;
103
        virtual error::Error PushLogs(
104
                const string &deployment_id,
105
                const string &log_file_path,
106
                const string &server_url,
107
                http::Client &client,
108
                LogsAPIResponseHandler api_handler) = 0;
109
};
110

111
class DeploymentClient : virtual public DeploymentAPI {
112
public:
113
        error::Error CheckNewDeployments(
114
                context::MenderContext &ctx,
115
                const string &server_url,
116
                http::Client &client,
117
                CheckUpdatesAPIResponseHandler api_handler) override;
118
        error::Error PushStatus(
119
                const string &deployment_id,
120
                DeploymentStatus status,
121
                const string &substate,
122
                const string &server_url,
123
                http::Client &client,
124
                StatusAPIResponseHandler api_handler) override;
125
        error::Error PushLogs(
126
                const string &deployment_id,
127
                const string &log_file_path,
128
                const string &server_url,
129
                http::Client &client,
130
                LogsAPIResponseHandler api_handler) override;
131
};
132

133
/**
134
 * A helper class only declared here because of testing. Not to be used
135
 * separately outside of PushLogs().
136
 */
137
class JsonLogMessagesReader : virtual public io::Reader {
138
public:
139
        /**
140
         * @see GetLogFileDataSize() for details about #data_size
141
         */
142
        JsonLogMessagesReader(shared_ptr<io::FileReader> raw_data_reader, size_t data_size) :
×
143
                reader_ {raw_data_reader},
144
                raw_data_size_ {data_size},
145
                rem_raw_data_size_ {data_size} {};
×
146

147
        expected::ExpectedSize Read(
148
                vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) override;
149

150
        error::Error Rewind() {
×
151
                header_rem_ = header_.size();
×
152
                closing_rem_ = closing_.size();
×
153
                rem_raw_data_size_ = raw_data_size_;
×
154
                return reader_->Rewind();
×
155
        }
156

157
        static size_t TotalDataSize(size_t raw_data_size) {
×
158
                return raw_data_size + header_.size() + closing_.size();
×
159
        }
160

161
private:
162
        shared_ptr<io::FileReader> reader_;
163
        size_t raw_data_size_;
164
        size_t rem_raw_data_size_;
165
        static const vector<uint8_t> header_;
166
        static const vector<uint8_t> closing_;
167
        io::Vsize header_rem_ = header_.size();
168
        io::Vsize closing_rem_ = closing_.size();
169
};
170

171
} // namespace deployments
172
} // namespace update
173
} // namespace mender
174

175
#endif // MENDER_UPDATE_DEPLOYMENTS_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc