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

mendersoftware / mender / 1054591953

30 Oct 2023 10:02AM UTC coverage: 80.194% (+0.06%) from 80.137%
1054591953

push

gitlab-ci

kacf
fix: Make sure `device_type` is submitted with inventory data.

Changelog: None
Ticket: None

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

6871 of 8568 relevant lines covered (80.19%)

9388.93 hits per line

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

92.59
/common/inventory_parser/platform/c++17/inventory_parser.cpp
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
#include <common/inventory_parser.hpp>
16

17
#include <filesystem>
18

19
#include <common/key_value_parser.hpp>
20
#include <common/processes.hpp>
21
#include <common/log.hpp>
22

23
namespace mender {
24
namespace common {
25
namespace inventory_parser {
26

27
using namespace std;
28
namespace kvp = mender::common::key_value_parser;
29
namespace procs = mender::common::processes;
30
namespace log = mender::common::log;
31
namespace err = mender::common::error;
32
namespace fs = std::filesystem;
33

34
kvp::ExpectedKeyValuesMap GetInventoryData(const string &generators_dir) {
9✔
35
        bool any_success = false;
36
        bool any_failure = false;
37
        kvp::KeyValuesMap data;
38

39
        fs::path dir_path(generators_dir);
18✔
40
        if (!fs::exists(dir_path)) {
9✔
41
                return kvp::ExpectedKeyValuesMap(data);
×
42
        }
43

44
        for (const auto &entry : fs::directory_iterator {dir_path}) {
41✔
45
                fs::path file_path = entry.path();
26✔
46
                if (!fs::is_regular_file(file_path)) {
14✔
47
                        continue;
2✔
48
                }
49

50
                string file_path_str = file_path.string();
14✔
51
                if (file_path.filename().string().find("mender-inventory-") != 0) {
28✔
52
                        log::Warning(
1✔
53
                                "'" + file_path_str + "' doesn't have the 'mender-inventory-' prefix, skipping");
2✔
54
                        continue;
1✔
55
                }
56

57
                fs::perms perms = entry.status().permissions();
58
                if ((perms & (fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec))
13✔
59
                        == fs::perms::none) {
60
                        log::Warning("'" + file_path_str + "' is not executable");
2✔
61
                        continue;
1✔
62
                }
63
                procs::Process proc({file_path_str});
60✔
64
                auto ex_line_data = proc.GenerateLineData();
12✔
65
                if (!ex_line_data) {
12✔
66
                        log::Error("'" + file_path_str + "' failed: " + ex_line_data.error().message);
×
67
                        any_failure = true;
68
                        continue;
69
                }
70

71
                auto err = kvp::AddParseKeyValues(data, ex_line_data.value());
12✔
72
                if (error::NoError != err) {
12✔
73
                        log::Error("Failed to parse data from '" + file_path_str + "': " + err.message);
8✔
74
                        any_failure = true;
75
                } else {
76
                        any_success = true;
77
                }
78
        }
79

80
        if (any_success || !any_failure) {
9✔
81
                return kvp::ExpectedKeyValuesMap(data);
8✔
82
        } else {
83
                err::Error error = MakeError(
84
                        kvp::KeyValueParserErrorCode::NoDataError,
85
                        "No data successfully read from inventory scripts in '" + generators_dir + "'");
2✔
86
                return expected::unexpected(error);
2✔
87
        }
88
}
89

90
} // namespace inventory_parser
91
} // namespace common
92
} // namespace mender
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