trust-store 2.0.3
Provides a common implementation of a trust store to be used by trusted helpers.
store.h
Go to the documentation of this file.
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18
19#ifndef CORE_TRUST_STORE_H_
20#define CORE_TRUST_STORE_H_
21
22#include <core/trust/request.h>
25
26#include <functional>
27#include <memory>
28#include <stdexcept>
29
30namespace core
31{
44namespace trust
45{
50{
51public:
53 struct Errors
54 {
56 Errors() = delete;
58
62 struct ErrorOpeningStore : public std::runtime_error
63 {
64 ErrorOpeningStore(const char* implementation_specific)
65 : std::runtime_error(implementation_specific)
66 {
67 }
68 };
69
73 struct ErrorResettingStore : public std::runtime_error
74 {
75 ErrorResettingStore(const char* implementation_specific)
76 : std::runtime_error(implementation_specific)
77 {
78 }
79 };
80
81 };
82
86 class Query
87 {
88 public:
90 struct Errors
91 {
93 Errors() = delete;
98 struct QueryIsInErrorState : public std::runtime_error
99 {
100 QueryIsInErrorState() : std::runtime_error("Query is in error state, cannot extract result.")
101 {
102 }
103 };
104
108 struct NoCurrentResult : public std::runtime_error
109 {
110 NoCurrentResult() : std::runtime_error("Query does not have a current result.")
111 {
112 }
113 };
114 };
115
117 enum class Status
118 {
119 armed,
120 has_more_results,
121 eor,
122 error
123 };
124
125 Query(const Query&) = delete;
126 virtual ~Query() = default;
127
129 virtual Status status() const = 0;
130
132 virtual void for_application_id(const std::string& id) = 0;
133
135 virtual void for_feature(Feature feature) = 0;
136
138 virtual void for_interval(const Request::Timestamp& begin, const Request::Timestamp& end) = 0;
139
141 virtual void for_answer(Request::Answer answer) = 0;
142
144 virtual void all() = 0;
145
147 virtual void execute() = 0;
148
150 virtual void next() = 0;
151
153 virtual void erase() = 0;
154
156 virtual Request current() = 0;
157
158 protected:
159 Query() = default;
160 };
161
162 Store(const Store&) = delete;
163 virtual ~Store() = default;
164
165 Store& operator=(const Store&) = delete;
166 bool operator==(const Store&) const = delete;
167
171 virtual void reset() = 0;
172
176 virtual void add(const Request& request) = 0;
177
181 virtual void remove_application(const std::string& id) = 0;
182
186 virtual std::shared_ptr<Query> query() = 0;
187
188protected:
189 Store() = default;
190};
191
193struct Errors
194{
196 Errors() = delete;
198
203 struct ServiceNameMustNotBeEmpty : public std::runtime_error
204 {
205 ServiceNameMustNotBeEmpty() : std::runtime_error("Service name must not be empty")
206 {
207 }
208 };
209};
210
217CORE_TRUST_DLL_PUBLIC std::shared_ptr<Store> create_default_store(const std::string& service_name);
218}
219}
220
221#endif // CORE_TRUST_STORE_H_
virtual void for_feature(Feature feature)=0
Limit the query to a service-specific feature.
virtual void erase()=0
After successful execution, erase the current element and advance to the next request.
virtual void for_application_id(const std::string &id)=0
Limit the query to a specific application Id.
virtual ~Query()=default
virtual void next()=0
After successful execution, advance to the next request.
virtual Request current()=0
Access the request the query currently points to.
Status
The state of the query.
Definition store.h:118
virtual void for_interval(const Request::Timestamp &begin, const Request::Timestamp &end)=0
Limit the query to the specified time interval.
virtual void execute()=0
Execute the query against the store.
virtual Status status() const =0
Access the status of the query.
Query(const Query &)=delete
virtual void for_answer(Request::Answer answer)=0
Limit the query for a specific answer.
virtual void all()=0
Query all stored requests.
virtual ~Store()=default
virtual void remove_application(const std::string &id)=0
Remove all requests issued by the given application.
Store(const Store &)=delete
bool operator==(const Store &) const =delete
Store & operator=(const Store &)=delete
virtual std::shared_ptr< Query > query()=0
Create a query for this store.
virtual void add(const Request &request)=0
Add the provided request to the store. When this function returns true, the request has been persiste...
virtual void reset()=0
Resets the state of the store, implementations should discard all persistent and non-persistent state...
Contains functionality for implementing Ubuntu's trust model.
Definition agent.h:31
TaggedInteger< tag::Feature, std::uint64_t > Feature
Our internal service-feature type.
CORE_TRUST_DLL_PUBLIC std::shared_ptr< Store > create_default_store(const std::string &service_name)
Creates an instance for the default store implementation.
Definition agent.h:29
All core::trust-specific error/exception types go here.
Definition store.h:194
The Request struct encapsulates information about a trust request answered by the user.
Definition request.h:55
Answer
Enumerates the possible answers given by a user.
Definition request.h:66
std::chrono::system_clock::time_point Timestamp
Requests are timestamped with wallclock time.
Definition request.h:59
ErrorOpeningStore(const char *implementation_specific)
Definition store.h:64
ErrorResettingStore(const char *implementation_specific)
Definition store.h:75
All Store-specific error/exception types go here.
Definition store.h:54
All Query-specific error/exception types go here.
Definition store.h:91
#define CORE_TRUST_DLL_PUBLIC
Definition visibility.h:26