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

mendersoftware / mender / 1022567176

02 Oct 2023 07:50AM UTC coverage: 80.127% (+2.5%) from 77.645%
1022567176

push

gitlab-ci

kacf
chore: Centralize selection of `std::filesystem` library.

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

6447 of 8046 relevant lines covered (80.13%)

9912.21 hits per line

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

92.31
/mender-auth/ipc/server.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 <mender-auth/ipc/server.hpp>
16

17
#include <functional>
18
#include <iostream>
19
#include <string>
20

21
#include <api/auth.hpp>
22
#include <common/error.hpp>
23
#include <common/expected.hpp>
24
#include <common/dbus.hpp>
25
#include <common/log.hpp>
26

27
namespace mender {
28
namespace auth {
29
namespace ipc {
30

31
namespace auth_client = mender::api::auth;
32
namespace error = mender::common::error;
33
namespace expected = mender::common::expected;
34
namespace dbus = mender::common::dbus;
35

36
using namespace std;
37

38
// Register DBus object handling auth methods and signals
39
error::Error Caching::Listen(const string &private_key_path, const string &identity_script_path) {
2✔
40
        // Cannot serve new tokens when not knowing where to fetch them from.
41
        AssertOrReturnError(server_url_ != "");
2✔
42

43
        auto dbus_obj = make_shared<dbus::DBusObject>("/io/mender/AuthenticationManager");
2✔
44
        dbus_obj->AddMethodHandler<dbus::ExpectedStringPair>(
2✔
45
                "io.mender.AuthenticationManager", "io.mender.Authentication1", "GetJwtToken", [this]() {
1✔
46
                        return dbus::StringPair {GetJWTToken(), GetServerURL()};
2✔
47
                });
4✔
48
        dbus_obj->AddMethodHandler<expected::ExpectedBool>(
2✔
49
                "io.mender.AuthenticationManager",
50
                "io.mender.Authentication1",
51
                "FetchJwtToken",
52
                [this, private_key_path, identity_script_path]() {
2✔
53
                        auto err = auth_client::FetchJWTToken(
54
                                client_,
1✔
55
                                server_url_,
1✔
56
                                private_key_path,
1✔
57
                                identity_script_path == "" ? default_identity_script_path_ : identity_script_path,
1✔
58
                                [this](auth_client::APIResponse resp) {
1✔
59
                                        CacheAPIResponse(server_url_, resp);
2✔
60
                                        if (resp) {
1✔
61
                                                dbus_server_.EmitSignal<dbus::StringPair>(
1✔
62
                                                        "/io/mender/AuthenticationManager",
63
                                                        "io.mender.Authentication1",
64
                                                        "JwtTokenStateChange",
65
                                                        dbus::StringPair {resp.value(), server_url_});
2✔
66
                                        } else {
67
                                                log::Error("Failed to fetch new token: " + resp.error().String());
×
68
                                        }
69
                                },
1✔
70
                                tenant_token_);
1✔
71
                        if (err != error::NoError) {
1✔
72
                                log::Error("Failed to trigger token fetching: " + err.String());
×
73
                        }
74
                        return (err == error::NoError);
1✔
75
                });
4✔
76

77
        return dbus_server_.AdvertiseObject(dbus_obj);
4✔
78
}
79

80
} // namespace ipc
81
} // namespace auth
82
} // 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