1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
From f73106b1f204b49930922e8bb4d1fdec6ac64b7d Mon Sep 17 00:00:00 2001
From: Scott Murray <scott.murray@konsulko.com>
Date: Sat, 5 Aug 2023 12:19:45 -0400
Subject: [PATCH 5/5] Make install locations configurable
Make binary, certificate, and configuration file install locations
configurable, including generation and installation of an accurate
default config.ini as well as a header file so that the server
binary uses the specified defaults. This allows configuring a
build that installs files into locations more along the lines of
the Linux FHS. An effort has been made to ensure that the previous
default locations are maintained.
Upstream-Status: Pending
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
kuksa-val-server/config.ini | 7 ----
kuksa-val-server/config.ini.in | 7 ++++
kuksa-val-server/src/CMakeLists.txt | 59 +++++++++++++++++++++--------
kuksa-val-server/src/config.hpp.in | 27 +++++++++++++
kuksa-val-server/src/main.cpp | 5 ++-
5 files changed, 81 insertions(+), 24 deletions(-)
delete mode 100644 kuksa-val-server/config.ini
create mode 100644 kuksa-val-server/config.ini.in
create mode 100644 kuksa-val-server/src/config.hpp.in
diff --git a/kuksa-val-server/config.ini b/kuksa-val-server/config.ini
deleted file mode 100644
index 8fcd63c..0000000
--- a/kuksa-val-server/config.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-vss = vss_release_4.0.json
-log-level = ALL
-cert-path = .
-
-[mqtt]
- publish =
- topic-prefix = vss
diff --git a/kuksa-val-server/config.ini.in b/kuksa-val-server/config.ini.in
new file mode 100644
index 0000000..3793bd6
--- /dev/null
+++ b/kuksa-val-server/config.ini.in
@@ -0,0 +1,7 @@
+vss = @KUKSA_DEFAULT_DATADIR@/vss_release_4.0.json
+log-level = ALL
+cert-path = @KUKSA_DEFAULT_CERTDIR@
+
+[mqtt]
+ publish =
+ topic-prefix = vss
diff --git a/kuksa-val-server/src/CMakeLists.txt b/kuksa-val-server/src/CMakeLists.txt
index 908c66c..b749a7a 100644
--- a/kuksa-val-server/src/CMakeLists.txt
+++ b/kuksa-val-server/src/CMakeLists.txt
@@ -161,6 +161,35 @@ if(BUILD_EXE)
######
# Setup server install and packaging
+ set(KUKSA_INSTALL_BINDIR "bin/${SERVER_EXE_NAME}" CACHE STRING "Server binary install directory")
+
+ if(DEFINED KUKSA_INSTALL_DATADIR)
+ set(KUKSA_DEFAULT_DATADIR_INTERNAL "${KUKSA_INSTALL_DATADIR}")
+ else()
+ set(KUKSA_DEFAULT_DATADIR_INTERNAL ".")
+ endif()
+ set(KUKSA_INSTALL_DATADIR "${KUKSA_INSTALL_BINDIR}" CACHE STRING "Data install directory")
+ set(KUKSA_DEFAULT_DATADIR "${KUKSA_DEFAULT_DATADIR_INTERNAL}" CACHE STRING "Default data location")
+
+ if(DEFINED KUKSA_INSTALL_CONFIGDIR)
+ set(KUKSA_DEFAULT_CONFIG "${KUKSA_INSTALL_CONFIGDIR}/config.ini" CACHE STRING "Default config.ini location")
+ else()
+ set(KUKSA_DEFAULT_CONFIG "config.ini" CACHE STRING "Default config.ini location")
+ endif()
+ set(KUKSA_INSTALL_CONFIGDIR "${KUKSA_INSTALL_BINDIR}" CACHE STRING "config.ini install directory")
+
+ if(DEFINED KUKSA_INSTALL_CERTDIR)
+ set(KUKSA_DEFAULT_CERTDIR_INTERNAL "${KUKSA_INSTALL_CERTDIR}")
+ else()
+ set(KUKSA_DEFAULT_CERTDIR_INTERNAL ".")
+ endif()
+ set(KUKSA_INSTALL_CERTDIR "${KUKSA_INSTALL_BINDIR}" CACHE STRING "Certificate install directory")
+ set(KUKSA_DEFAULT_CERTDIR "${KUKSA_DEFAULT_CERTDIR_INTERNAL}" CACHE STRING "Default certificate location")
+
+ # Generate header for main.cpp to pick up default locations
+ configure_file(config.hpp.in config.hpp @ONLY)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/jwt/jwt.key.pub ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.pem ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.key ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
@@ -173,23 +202,23 @@ if(BUILD_EXE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.0.json ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.1.1.json ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_4.0.json ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../config.ini ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../config.ini.in ${CMAKE_CURRENT_BINARY_DIR}/config.ini @COPY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../config_grpc_client.ini ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
- install( TARGETS ${SERVER_EXE_NAME} DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/jwt/jwt.key.pub DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.pem DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.key DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Client.pem DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Client.key DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/CA.pem DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.0.json DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.1.json DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.2.json DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.0.json DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.1.1.json DESTINATION bin/${SERVER_EXE_NAME})
- install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_4.0.json DESTINATION bin/${SERVER_EXE_NAME})
-
+ install( TARGETS ${SERVER_EXE_NAME} DESTINATION ${KUKSA_INSTALL_BINDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/jwt/jwt.key.pub DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.pem DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Server.key DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Client.pem DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/Client.key DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../kuksa_certificates/CA.pem DESTINATION ${KUKSA_INSTALL_CERTDIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.0.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.1.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_2.2.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.0.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_3.1.1.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../data/vss-core/vss_release_4.0.json DESTINATION ${KUKSA_INSTALL_DATADIR})
+ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/config.ini DESTINATION ${KUKSA_INSTALL_CONFIGDIR})
# CPack
INCLUDE(InstallRequiredSystemLibraries)
diff --git a/kuksa-val-server/src/config.hpp.in b/kuksa-val-server/src/config.hpp.in
new file mode 100644
index 0000000..24226d2
--- /dev/null
+++ b/kuksa-val-server/src/config.hpp.in
@@ -0,0 +1,27 @@
+/**********************************************************************
+ * Copyright (c) 2022 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ **********************************************************************/
+
+#ifndef __CONFIG_H___
+
+// Default configuration file location
+#cmakedefine KUKSA_DEFAULT_CONFIG "@KUKSA_DEFAULT_CONFIG@"
+
+// Default Certificate directory
+#cmakedefine KUKSA_DEFAULT_CERTDIR "@KUKSA_DEFAULT_CERTDIR@"
+
+#endif
diff --git a/kuksa-val-server/src/main.cpp b/kuksa-val-server/src/main.cpp
index f3e6dd1..8346188 100644
--- a/kuksa-val-server/src/main.cpp
+++ b/kuksa-val-server/src/main.cpp
@@ -47,6 +47,7 @@
#include "exception.hpp"
#include "grpcHandler.hpp"
#include "OverlayLoader.hpp"
+#include "config.hpp"
#include "../buildinfo.h"
@@ -107,7 +108,7 @@ int main(int argc, const char *argv[]) {
program_options::options_description desc{"OPTIONS"};
desc.add_options()
("help,h", "Help screen")
- ("config-file,c", program_options::value<boost::filesystem::path>()->default_value(boost::filesystem::path{"config.ini"}),
+ ("config-file,c", program_options::value<boost::filesystem::path>()->default_value(boost::filesystem::path{KUKSA_DEFAULT_CONFIG}),
"Configuration file with `kuksa-val-server` input parameters."
"Configuration file can replace command-line parameters and through different files multiple configurations can be handled more easily (e.g. test and production setup)."
"Sample of configuration file parameters looks like:\n"
@@ -116,7 +117,7 @@ int main(int argc, const char *argv[]) {
"log-level = ALL\n")
("vss", program_options::value<boost::filesystem::path>()->required(), "[mandatory] Path to VSS data file describing VSS data tree structure which `kuksa-val-server` shall handle. Sample 'vss_release_4.0.json' file can be found under [data](./data/vss-core/vss_release_4.0.json)")
("overlays", program_options::value<boost::filesystem::path>(), "Path to a directory cotaiing additional VSS models. All json files will be applied on top of the main vss file given by the -vss parameter in alphanumerical order")
- ("cert-path", program_options::value<boost::filesystem::path>()->required()->default_value(boost::filesystem::path(".")),
+ ("cert-path", program_options::value<boost::filesystem::path>()->required()->default_value(boost::filesystem::path(KUKSA_DEFAULT_CERTDIR)),
"[mandatory] Directory path where 'Server.pem', 'Server.key' and 'jwt.key.pub' are located. ")
("insecure", program_options::bool_switch()->default_value(false), "By default, `kuksa-val-server` shall accept only SSL (TLS) secured connections. If provided, `kuksa-val-server` shall also accept plain un-secured connections for Web-Socket and GRPC API connections, and also shall not fail connections due to self-signed certificates.")
("use-keycloak", "Use KeyCloak for permission management")
--
2.41.0
|