Skip to content

Commit 07ee70d

Browse files
committed
MINIFICPP-2765 Move GCP Extension to stable C API
1 parent b89c26e commit 07ee70d

34 files changed

Lines changed: 799 additions & 626 deletions

behave_framework/src/minifi_behave/steps/checking_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def verify_minifi_logs_match_regex(context, regex, duration):
119119
@step('no errors were generated on the http-proxy regarding "{url}"')
120120
def verify_no_errors_on_http_proxy(context: MinifiTestContext, url: str):
121121
http_proxy_container = next(container for container in context.containers.values() if isinstance(container, HttpProxy))
122-
assert http_proxy_container.check_http_proxy_access(url) or http_proxy_container.log_app_output()
122+
assert http_proxy_container.check_http_proxy_access(url) or log_due_to_failure(context)
123123

124124

125125
@then('in the "{container}" container no files are placed in the "{directory}" directory in {duration} of running time')

core-framework/common/include/core/PropertyDefinitionBuilder.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,21 @@ namespace org::apache::nifi::minifi::core {
2727
namespace detail {
2828
template<typename... Types>
2929
inline constexpr auto TypeNames = std::array<std::string_view, sizeof...(Types)>{core::className<Types>()...};
30-
}
30+
31+
template <size_t N>
32+
struct StringLiteral {
33+
char value[N];
34+
constexpr StringLiteral(const char (&str)[N]) { // NOLINT(runtime/explicit)
35+
for (size_t i = 0; i < N; ++i) {
36+
value[i] = str[i];
37+
}
38+
}
39+
};
40+
41+
// A variable template that creates permanent static memory for the span to point to
42+
template <StringLiteral str>
43+
inline constexpr auto StaticAllowedType = std::array<std::string_view, 1>{std::string_view{str.value, sizeof(str.value) - 1}};
44+
} // namespace detail
3145

3246
template<size_t NumAllowedValues = 0>
3347
struct PropertyDefinitionBuilder {
@@ -81,6 +95,12 @@ struct PropertyDefinitionBuilder {
8195
return *this;
8296
}
8397

98+
template <detail::StringLiteral TypeName>
99+
constexpr PropertyDefinitionBuilder<NumAllowedValues> withAllowedType() {
100+
property.allowed_types = detail::StaticAllowedType<TypeName>;
101+
return *this;
102+
}
103+
84104
constexpr PropertyDefinitionBuilder<NumAllowedValues> withValidator(const PropertyValidator& property_validator) {
85105
property.validator = gsl::make_not_null(&property_validator);
86106
return *this;

extension-framework/cpp-extension-lib/include/api/core/ProcessContext.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
#pragma once
1919

20-
#include <string>
2120
#include <expected>
21+
#include <string>
2222

2323
#include "api/core/FlowFile.h"
24+
#include "api/utils/Proxy.h"
2425
#include "api/utils/Ssl.h"
2526
#include "minifi-c.h"
2627
#include "minifi-cpp/core/PropertyDefinition.h"
@@ -44,7 +45,8 @@ class ProcessContext {
4445
[[nodiscard]] virtual bool hasNonEmptyProperty(std::string_view name) const = 0;
4546
[[nodiscard]] virtual std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const = 0;
4647

47-
[[nodiscard]] virtual std::expected<utils::net::SslData, std::error_code> getSslData(std::string_view name) const = 0;
48+
[[nodiscard]] virtual std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const = 0;
49+
[[nodiscard]] virtual std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const = 0;
4850
};
4951

5052
class CffiProcessContext : public ProcessContext {
@@ -58,7 +60,8 @@ class CffiProcessContext : public ProcessContext {
5860
[[nodiscard]] std::map<std::string, std::string> getDynamicProperties(const FlowFile* flow_file) const override;
5961
[[nodiscard]] bool hasNonEmptyProperty(std::string_view name) const override;
6062

61-
[[nodiscard]] std::expected<utils::net::SslData, std::error_code> getSslData(std::string_view name) const override;
63+
[[nodiscard]] std::expected<std::optional<utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
64+
[[nodiscard]] std::expected<std::optional<utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const override;
6265

6366
private:
6467
[[nodiscard]] std::expected<std::string, std::error_code> getProperty(std::string_view name, const FlowFile* flow_file) const;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include <filesystem>
20+
#include <optional>
21+
#include <string>
22+
23+
namespace org::apache::nifi::minifi::api::utils {
24+
25+
enum class ProxyType {
26+
DIRECT,
27+
HTTP
28+
};
29+
30+
struct BasicAuthCredentials {
31+
std::string username;
32+
std::string password;
33+
};
34+
35+
struct ProxyData {
36+
std::string host;
37+
uint16_t port;
38+
std::optional<BasicAuthCredentials> proxy_credentials;
39+
ProxyType proxy_type;
40+
};
41+
42+
} // namespace org::apache::nifi::minifi::api::utils

extension-framework/cpp-extension-lib/include/api/utils/Ssl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
#pragma once
1818

1919
#include <string>
20-
#include <memory>
21-
#include <optional>
2220
#include <filesystem>
2321

24-
#include "utils/Enum.h"
25-
2622
namespace org::apache::nifi::minifi::api::utils::net {
2723

2824
enum class ClientAuthOption {

extension-framework/cpp-extension-lib/mocklib/include/MockProcessContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class MockProcessContext : public api::core::ProcessContext {
3434
[[nodiscard]] std::map<std::string, std::string> getDynamicProperties(const api::core::FlowFile* flow_file) const override;
3535
[[nodiscard]] bool hasNonEmptyProperty(std::string_view name) const override;
3636

37-
[[nodiscard]] std::expected<api::utils::net::SslData, std::error_code> getSslData(std::string_view name) const override;
37+
[[nodiscard]] std::expected<std::optional<api::utils::net::SslData>, std::error_code> getSslData(const minifi::core::PropertyReference& prop) const override;
38+
[[nodiscard]] std::expected<std::optional<api::utils::ProxyData>, std::error_code> getProxyData(const minifi::core::PropertyReference& prop) const override;
3839

3940
std::map<std::string, std::string, std::less<>> properties_;
4041

extension-framework/cpp-extension-lib/mocklib/src/MockProcessContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ bool MockProcessContext::hasNonEmptyProperty(const std::string_view name) const
4444
return properties_.contains(name);
4545
}
4646

47-
std::expected<api::utils::net::SslData, std::error_code> MockProcessContext::getSslData(std::string_view) const {
48-
return api::utils::net::SslData{};
47+
std::expected<std::optional<api::utils::net::SslData>, std::error_code> MockProcessContext::getSslData(const minifi::core::PropertyReference&) const {
48+
return std::nullopt;
49+
}
50+
51+
[[nodiscard]] std::expected<std::optional<api::utils::ProxyData>, std::error_code> MockProcessContext::getProxyData(const minifi::core::PropertyReference&) const {
52+
return std::nullopt;
4953
}
5054
} // namespace org::apache::nifi::minifi::mock

extension-framework/cpp-extension-lib/src/core/ProcessContext.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ std::map<std::string, std::string> CffiProcessContext::getDynamicProperties(cons
6969
return result;
7070
}
7171

72-
std::expected<utils::net::SslData, std::error_code> CffiProcessContext::getSslData(const std::string_view name) const {
72+
std::expected<std::optional<utils::net::SslData>, std::error_code> CffiProcessContext::getSslData(const minifi::core::PropertyReference& prop) const {
73+
const auto controller_name = getProperty(prop, nullptr);
74+
if (!controller_name) { return std::nullopt; }
75+
7376
auto ssl_data = utils::net::SslData{};
7477

75-
if (const auto status = MinifiProcessContextGetSslData(impl_, utils::minifiStringView(name), [](void* data, const MinifiSslData* minifi_ssl_data) {
78+
if (const auto status = MinifiProcessContextGetSslData(impl_, utils::minifiStringView(*controller_name), [](void* data, const MinifiSslData* minifi_ssl_data) {
7679
auto* my_ssl_data = static_cast<utils::net::SslData*>(data);
7780
my_ssl_data->ca_loc = utils::toString(minifi_ssl_data->ca_certificate_file);
7881
my_ssl_data->cert_loc = utils::toString(minifi_ssl_data->certificate_file);
@@ -86,4 +89,36 @@ std::expected<utils::net::SslData, std::error_code> CffiProcessContext::getSslDa
8689
return ssl_data;
8790
}
8891

92+
std::expected<std::optional<utils::ProxyData>, std::error_code> CffiProcessContext::getProxyData(const minifi::core::PropertyReference& prop) const {
93+
const auto controller_name = getProperty(prop, nullptr);
94+
if (!controller_name) { return std::nullopt; }
95+
96+
auto proxy_data = utils::ProxyData{};
97+
if (const auto status = MinifiProcessContextGetProxyData(
98+
impl_,
99+
utils::minifiStringView(*controller_name),
100+
[](void* data, const MinifiProxyData* minifi_proxy_data) {
101+
auto* proxy = static_cast<utils::ProxyData*>(data);
102+
proxy->host = utils::toString(minifi_proxy_data->hostname);
103+
proxy->port = minifi_proxy_data->port;
104+
if (minifi_proxy_data->password && minifi_proxy_data->username) {
105+
proxy->proxy_credentials = utils::BasicAuthCredentials{.username = utils::toString(*minifi_proxy_data->username),
106+
.password = utils::toString(*minifi_proxy_data->password)};
107+
} else {
108+
proxy->proxy_credentials = std::nullopt;
109+
}
110+
if (minifi_proxy_data->proxy_type == MINIFI_PROXY_TYPE_HTTP) {
111+
proxy->proxy_type = utils::ProxyType::HTTP;
112+
} else {
113+
proxy->proxy_type = utils::ProxyType::DIRECT;
114+
}
115+
},
116+
&proxy_data);
117+
status != MINIFI_STATUS_SUCCESS) {
118+
return std::unexpected{utils::make_error_code(status)};
119+
}
120+
121+
return proxy_data;
122+
}
123+
89124
} // namespace org::apache::nifi::minifi::api::core

extensions/gcp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ add_minifi_library(minifi-gcp SHARED ${SOURCES})
3030
if (NOT WIN32)
3131
target_compile_options(minifi-gcp PRIVATE -Wno-error=deprecated-declarations) # Suppress deprecation warnings for std::rel_ops usage
3232
endif()
33-
target_link_libraries(minifi-gcp ${LIBMINIFI} google-cloud-cpp::storage)
34-
target_include_directories(minifi-gcp SYSTEM PUBLIC ${google-cloud-cpp_INCLUDE_DIRS})
33+
target_link_libraries(minifi-gcp minifi-cpp-extension-lib google-cloud-cpp::storage)
3534

36-
register_extension(minifi-gcp "GCP EXTENSIONS" GCP-EXTENSIONS "This enables Google Cloud Platform support" "extensions/gcp/tests")
35+
target_include_directories(minifi-gcp SYSTEM PUBLIC ${google-cloud-cpp_INCLUDE_DIRS})
3736

37+
register_c_api_extension(minifi-gcp "GCP EXTENSIONS" GCP-EXTENSIONS "This enables Google Cloud Platform support" "extensions/gcp/tests")
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "../../extension-framework/cpp-extension-lib/include/api/core/Resource.h"
19+
#include "api/core/Resource.h"
20+
#include "api/utils/minifi-c-utils.h"
21+
#include "processors/DeleteGCSObject.h"
22+
#include "processors/FetchGCSObject.h"
23+
#include "processors/ListGCSBucket.h"
24+
#include "processors/PutGCSObject.h"
25+
26+
#define MKSOC(x) #x
27+
#define MAKESTRING(x) MKSOC(x) // NOLINT(cppcoreguidelines-macro-usage)
28+
29+
namespace minifi = org::apache::nifi::minifi;
30+
31+
CEXTENSIONAPI const uint32_t MinifiApiVersion = MINIFI_API_VERSION;
32+
33+
CEXTENSIONAPI void MinifiInitExtension(MinifiExtensionContext* extension_context) {
34+
const MinifiExtensionDefinition extension_definition{
35+
.name = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_NAME)),
36+
.version = minifi::api::utils::minifiStringView(MAKESTRING(EXTENSION_VERSION)),
37+
.deinit = nullptr,
38+
.user_data = nullptr
39+
};
40+
auto* extension = MinifiRegisterExtension(extension_context, &extension_definition);
41+
minifi::api::core::registerProcessors<minifi::extensions::gcp::DeleteGCSObject,
42+
minifi::extensions::gcp::FetchGCSObject,
43+
minifi::extensions::gcp::ListGCSBucket,
44+
minifi::extensions::gcp::PutGCSObject>(extension);
45+
minifi::api::core::registerControllerServices<minifi::extensions::gcp::GCPCredentialsControllerService>(extension);
46+
}

0 commit comments

Comments
 (0)