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

mendersoftware / mender / 1039476627

17 Oct 2023 10:49AM UTC coverage: 79.701% (-0.6%) from 80.278%
1039476627

push

gitlab-ci

oleorhagen
fix(mender-auth): Remember to pass in the needed params

Just add the missing identity script, and private key params.

Ticket: MEN-6671
Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

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

6557 of 8227 relevant lines covered (79.7%)

9764.5 hits per line

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

77.78
/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 <config.h>
19

20
#ifdef MENDER_LOG_BOOST
21
#include <boost/log/sinks/sync_frontend.hpp>
22
#include <boost/log/sinks/text_ostream_backend.hpp>
23
#include <boost/smart_ptr/shared_ptr.hpp>
24
#endif // MENDER_LOG_BOOST
25

26
#include <string>
27
#include <vector>
28

29
#include <api/client.hpp>
30
#include <common/error.hpp>
31
#include <common/events.hpp>
32
#include <common/expected.hpp>
33
#include <common/http.hpp>
34
#include <common/io.hpp>
35
#include <common/json.hpp>
36
#include <common/optional.hpp>
37
#include <mender-update/context.hpp>
38

39
namespace mender {
40
namespace update {
41
namespace deployments {
42

43
using namespace std;
44

45
#ifdef MENDER_LOG_BOOST
46
namespace sinks = boost::log::sinks;
47
#endif // MENDER_LOG_BOOST
48

49
namespace api = mender::api;
50
namespace context = mender::update::context;
51
namespace error = mender::common::error;
52
namespace events = mender::common::events;
53
namespace expected = mender::common::expected;
54
namespace io = mender::common::io;
55
namespace json = mender::common::json;
56

57
enum DeploymentsErrorCode {
58
        NoError = 0,
59
        InvalidDataError,
60
        BadResponseError,
61
        DeploymentAbortedError,
62
};
63

64
class DeploymentsErrorCategoryClass : public std::error_category {
65
public:
66
        const char *name() const noexcept override;
67
        string message(int code) const override;
68
};
69
extern const DeploymentsErrorCategoryClass DeploymentsErrorCategory;
70

71
error::Error MakeError(DeploymentsErrorCode code, const string &msg);
72

73
using CheckUpdatesAPIResponse = expected::expected<optional<json::Json>, error::Error>;
74
using CheckUpdatesAPIResponseHandler = function<void(CheckUpdatesAPIResponse)>;
75

76
enum class DeploymentStatus {
77
        Installing = 0,
78
        PauseBeforeInstalling,
79
        Downloading,
80
        PauseBeforeRebooting,
81
        Rebooting,
82
        PauseBeforeCommitting,
83
        Success,
84
        Failure,
85
        AlreadyInstalled,
86

87
        // Not a valid status, just used as an int representing the number of values
88
        // above
89
        End_
90
};
91

92
string DeploymentStatusString(DeploymentStatus status);
93

94
using StatusAPIResponse = error::Error;
95
using StatusAPIResponseHandler = function<void(StatusAPIResponse)>;
96

97
using LogsAPIResponse = error::Error;
98
using LogsAPIResponseHandler = function<void(LogsAPIResponse)>;
99

100
class DeploymentAPI {
101
public:
102
        virtual ~DeploymentAPI() {
103
        }
104

105
        virtual error::Error CheckNewDeployments(
106
                context::MenderContext &ctx,
107
                api::Client &client,
108
                CheckUpdatesAPIResponseHandler api_handler) = 0;
109
        virtual error::Error PushStatus(
110
                const string &deployment_id,
111
                DeploymentStatus status,
112
                const string &substate,
113
                api::Client &client,
114
                StatusAPIResponseHandler api_handler) = 0;
115
        virtual error::Error PushLogs(
116
                const string &deployment_id,
117
                const string &log_file_path,
118
                api::Client &client,
119
                LogsAPIResponseHandler api_handler) = 0;
120
};
121

122
class DeploymentClient : virtual public DeploymentAPI {
123
public:
124
        error::Error CheckNewDeployments(
125
                context::MenderContext &ctx,
126
                api::Client &client,
127
                CheckUpdatesAPIResponseHandler api_handler) override;
128
        error::Error PushStatus(
129
                const string &deployment_id,
130
                DeploymentStatus status,
131
                const string &substate,
132
                api::Client &client,
133
                StatusAPIResponseHandler api_handler) override;
134
        error::Error PushLogs(
135
                const string &deployment_id,
136
                const string &log_file_path,
137
                api::Client &client,
138
                LogsAPIResponseHandler api_handler) override;
139
};
140

141
/**
142
 * A helper class only declared here because of testing. Not to be used
143
 * separately outside of PushLogs().
144
 */
145
class JsonLogMessagesReader : virtual public io::Reader {
146
public:
147
        /**
148
         * @see GetLogFileDataSize() for details about #data_size
149
         */
150
        JsonLogMessagesReader(shared_ptr<io::FileReader> raw_data_reader, size_t data_size) :
×
151
                reader_ {raw_data_reader},
152
                raw_data_size_ {data_size},
153
                rem_raw_data_size_ {data_size} {};
×
154

155
        expected::ExpectedSize Read(
156
                vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) override;
157

158
        error::Error Rewind() {
3✔
159
                header_rem_ = header_.size();
3✔
160
                closing_rem_ = closing_.size();
3✔
161
                rem_raw_data_size_ = raw_data_size_;
3✔
162
                return reader_->Rewind();
3✔
163
        }
164

165
        static size_t TotalDataSize(size_t raw_data_size) {
3✔
166
                return raw_data_size + header_.size() + closing_.size();
3✔
167
        }
168

169
private:
170
        shared_ptr<io::FileReader> reader_;
171
        size_t raw_data_size_;
172
        size_t rem_raw_data_size_;
173
        static const vector<uint8_t> header_;
174
        static const vector<uint8_t> closing_;
175
        io::Vsize header_rem_ = header_.size();
176
        io::Vsize closing_rem_ = closing_.size();
177
};
178

179
class DeploymentLog {
180
public:
181
        DeploymentLog(const string &data_store_dir, const string &deployment_id) :
182
                data_store_dir_ {data_store_dir},
183
                id_ {deployment_id} {};
184
        error::Error BeginLogging();
185
        error::Error FinishLogging();
186
        ~DeploymentLog() {
187
                if (sink_) {
188
                        FinishLogging();
189
                }
190
        };
191

192
        string LogFileName();
193
        string LogFilePath();
194

195
private:
196
        const string data_store_dir_;
197
        const string id_;
198
#ifdef MENDER_LOG_BOOST
199
        typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink;
200
        boost::shared_ptr<text_sink> sink_;
201
#endif // MENDER_LOG_BOOST
202
        error::Error PrepareLogDirectory();
203
};
204

205
} // namespace deployments
206
} // namespace update
207
} // namespace mender
208

209
#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