You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "tdiesler (via GitHub)" <gi...@apache.org> on 2026/07/22 09:46:18 UTC

[PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

tdiesler opened a new pull request, #25012:
URL: https://github.com/apache/camel/pull/25012

   # Description
   
   * Update method on how to setup Conjur and obtain an API key (i.e. file not server logs)
   * Update tests to install install their respective policy 
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   # AI-assisted contributions
   
   - [ ] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "tdiesler (via GitHub)" <gi...@apache.org>.
tdiesler commented on code in PR #25012:
URL: https://github.com/apache/camel/pull/25012#discussion_r3631673768


##########
components/camel-cyberark-vault/src/test/java/org/apache/camel/component/cyberark/vault/integration/CyberArkTestSupport.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.component.cyberark.vault.integration;
+
+import java.net.URI;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class CyberArkTestSupport extends CamelTestSupport {
+
+    static final Logger LOG = LoggerFactory.getLogger(CyberArkTestSupport.class);
+
+    static HttpClient httpClient;
+    static String authToken;
+
+    @EndpointInject("mock:result")
+    MockEndpoint mockResult;
+
+    @BeforeAll
+    public static void beforeAll() throws Exception {
+        httpClient = HttpClient.newBuilder()
+                .connectTimeout(Duration.ofSeconds(10))
+                .build();
+
+        authToken = authenticate();
+    }
+
+    @AfterAll
+    public static void afterAll() throws Exception {
+        authToken = null;
+        httpClient = null;
+    }
+
+    private static String authenticate() throws Exception {
+        String url = String.format("%s/authn/%s/%s/authenticate",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                System.getProperty("camel.cyberark.username"));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(url))
+                .header("Content-Type", "text/plain")
+                .header("Accept-Encoding", "base64")
+                .POST(HttpRequest.BodyPublishers.ofString(System.getProperty("camel.cyberark.apiKey")))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Authenticate", response);
+
+        return response.body();
+    }
+
+    static void loadPolicy(String policy) throws Exception {
+
+        String policyUrl = String.format("%s/policies/%s/policy/%s",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                URLEncoder.encode("root", StandardCharsets.UTF_8));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(policyUrl))
+                .header("Authorization", "Token token=\"" + authToken + "\"")
+                .header("Content-Type", "text/plain")
+                .method("PATCH", HttpRequest.BodyPublishers.ofString(policy))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Load policy", response);
+    }
+
+    static void createSecret(String secretId, String secretValue) {
+        try {
+            String url = String.format("%s/secrets/%s/variable/%s",
+                    System.getProperty("camel.cyberark.url"),

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25012:
URL: https://github.com/apache/camel/pull/25012#issuecomment-5045049330

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "tdiesler (via GitHub)" <gi...@apache.org>.
tdiesler merged PR #25012:
URL: https://github.com/apache/camel/pull/25012


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #25012:
URL: https://github.com/apache/camel/pull/25012#discussion_r3630946669


##########
components/camel-cyberark-vault/src/test/java/org/apache/camel/component/cyberark/vault/integration/CyberArkTestSupport.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.component.cyberark.vault.integration;
+
+import java.net.URI;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class CyberArkTestSupport extends CamelTestSupport {
+
+    static final Logger LOG = LoggerFactory.getLogger(CyberArkTestSupport.class);
+
+    static HttpClient httpClient;
+    static String authToken;
+
+    @EndpointInject("mock:result")
+    MockEndpoint mockResult;
+
+    @BeforeAll
+    public static void beforeAll() throws Exception {
+        httpClient = HttpClient.newBuilder()
+                .connectTimeout(Duration.ofSeconds(10))
+                .build();
+
+        authToken = authenticate();
+    }
+
+    @AfterAll
+    public static void afterAll() throws Exception {
+        authToken = null;
+        httpClient = null;
+    }
+
+    private static String authenticate() throws Exception {
+        String url = String.format("%s/authn/%s/%s/authenticate",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                System.getProperty("camel.cyberark.username"));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(url))
+                .header("Content-Type", "text/plain")
+                .header("Accept-Encoding", "base64")
+                .POST(HttpRequest.BodyPublishers.ofString(System.getProperty("camel.cyberark.apiKey")))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Authenticate", response);
+
+        return response.body();
+    }
+
+    static void loadPolicy(String policy) throws Exception {
+
+        String policyUrl = String.format("%s/policies/%s/policy/%s",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                URLEncoder.encode("root", StandardCharsets.UTF_8));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(policyUrl))
+                .header("Authorization", "Token token=\"" + authToken + "\"")
+                .header("Content-Type", "text/plain")
+                .method("PATCH", HttpRequest.BodyPublishers.ofString(policy))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Load policy", response);
+    }
+
+    static void createSecret(String secretId, String secretValue) {
+        try {
+            String url = String.format("%s/secrets/%s/variable/%s",
+                    System.getProperty("camel.cyberark.url"),

Review Comment:
   Minor: `secretId` is not URL-encoded here, but test secrets use paths with `/` (e.g., `app/config`, `test/secret`). The production code in `ConjurClientImpl.createSecret()` correctly calls `URLEncoder.encode(secretId, StandardCharsets.UTF_8)`, and the `loadPolicy()` method below also uses `URLEncoder.encode()`. Consider adding encoding here for consistency:
   
   ```java
   String encodedSecretId = URLEncoder.encode(secretId, StandardCharsets.UTF_8);
   ```
   
   This is pre-existing from the old per-test code, so not a blocker.



##########
components/camel-cyberark-vault/src/test/java/org/apache/camel/component/cyberark/vault/integration/CyberArkTestSupport.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.component.cyberark.vault.integration;
+
+import java.net.URI;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class CyberArkTestSupport extends CamelTestSupport {
+
+    static final Logger LOG = LoggerFactory.getLogger(CyberArkTestSupport.class);
+
+    static HttpClient httpClient;
+    static String authToken;
+
+    @EndpointInject("mock:result")
+    MockEndpoint mockResult;
+
+    @BeforeAll
+    public static void beforeAll() throws Exception {
+        httpClient = HttpClient.newBuilder()
+                .connectTimeout(Duration.ofSeconds(10))
+                .build();
+
+        authToken = authenticate();
+    }
+
+    @AfterAll
+    public static void afterAll() throws Exception {
+        authToken = null;
+        httpClient = null;
+    }
+
+    private static String authenticate() throws Exception {
+        String url = String.format("%s/authn/%s/%s/authenticate",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                System.getProperty("camel.cyberark.username"));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(url))
+                .header("Content-Type", "text/plain")
+                .header("Accept-Encoding", "base64")
+                .POST(HttpRequest.BodyPublishers.ofString(System.getProperty("camel.cyberark.apiKey")))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Authenticate", response);
+
+        return response.body();
+    }
+
+    static void loadPolicy(String policy) throws Exception {
+
+        String policyUrl = String.format("%s/policies/%s/policy/%s",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                URLEncoder.encode("root", StandardCharsets.UTF_8));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(policyUrl))
+                .header("Authorization", "Token token=\"" + authToken + "\"")
+                .header("Content-Type", "text/plain")
+                .method("PATCH", HttpRequest.BodyPublishers.ofString(policy))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Load policy", response);
+    }
+
+    static void createSecret(String secretId, String secretValue) {
+        try {
+            String url = String.format("%s/secrets/%s/variable/%s",
+                    System.getProperty("camel.cyberark.url"),
+                    System.getProperty("camel.cyberark.account"),
+                    secretId);
+
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(URI.create(url))
+                    .header("Authorization", "Token token=\"" + authToken + "\"")
+                    .header("Content-Type", "application/octet-stream")
+                    .POST(HttpRequest.BodyPublishers.ofString(secretValue))
+                    .build();
+
+            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+            requireSuccess("Created secret", response);
+
+        } catch (Exception e) {
+            LOG.warn("Could not create secret '{}': {}", secretId, e.getMessage());

Review Comment:
   The `catch (Exception e)` here swallows exceptions from `requireSuccess()` (called at line 113), rendering the success check ineffective. If secret creation fails, subsequent tests will get misleading errors about missing secrets rather than the actual HTTP failure.
   
   In contrast, `loadPolicy()` below declares `throws Exception` and lets `requireSuccess()` propagate. Consider the same pattern here for consistency:
   
   ```java
   static void createSecret(String secretId, String secretValue) throws Exception {
       // ... (remove the try/catch or at least re-throw)
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #25012:
URL: https://github.com/apache/camel/pull/25012#issuecomment-5045194526

   There are uncommitted changes
   HEAD detached at pull/25012/merge
   Changes not staged for commit:
     (use "git add <file>..." to update what will be committed)
     (use "git restore <file>..." to discard changes in working directory)
   	modified:   catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cyberark-vault-component.adoc


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25012:
URL: https://github.com/apache/camel/pull/25012#issuecomment-5047372331

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `catalog/camel-catalog`
   - `components/camel-cyberark-vault`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 10 tested, 28 compile-only — current: 9 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **38 affected modules** (current approach: 9).
   
   <details><summary>:warning: Modules only in Scalpel (29)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   **Skip-tests mode would test 10 modules** (2 direct + 8 downstream), **skip tests for 28** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (10)</summary>
   
   - `camel-catalog`
   - `camel-cyberark-vault`
   - `camel-jbang-mcp`
   - `camel-jbang-plugin-mcp`
   - `camel-jbang-plugin-route-parser`
   - `camel-jbang-plugin-tui`
   - `camel-jbang-plugin-validate`
   - `camel-launcher-container`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   
   </details>
   
   <details><summary>Modules with tests skipped (28)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (38 modules)</summary>
   
   - Camel :: All Components Sync point
   - Camel :: Assembly
   - Camel :: Catalog :: CSimple Maven Plugin (deprecated)
   - Camel :: Catalog :: Camel Catalog
   - Camel :: Catalog :: Camel Report Maven Plugin
   - Camel :: Catalog :: Camel Route Parser
   - Camel :: Catalog :: Console
   - Camel :: Catalog :: Dummy Component
   - Camel :: Catalog :: Lucene (deprecated)
   - Camel :: Catalog :: Maven
   - Camel :: Catalog :: Suggest
   - Camel :: Component DSL
   - Camel :: Coverage
   - Camel :: CyberArk Vault
   - Camel :: Docs
   - Camel :: Endpoint DSL
   - Camel :: Endpoint DSL :: Support
   - Camel :: Integration Tests
   - Camel :: JBang :: Core
   - Camel :: JBang :: Integration tests
   - Camel :: JBang :: MCP
   - Camel :: JBang :: Main
   - Camel :: JBang :: Plugin :: Edit
   - Camel :: JBang :: Plugin :: Generate
   - Camel :: JBang :: Plugin :: Kubernetes
   - Camel :: JBang :: Plugin :: MCP
   - Camel :: JBang :: Plugin :: Route Parser
   - Camel :: JBang :: Plugin :: TUI
   - Camel :: JBang :: Plugin :: Testing
   - Camel :: JBang :: Plugin :: Validate
   - Camel :: Kamelet Main
   - Camel :: Launcher
   - Camel :: Launcher :: Container
   - Camel :: YAML DSL
   - Camel :: YAML DSL :: Deserializers
   - Camel :: YAML DSL :: Maven Plugins
   - Camel :: YAML DSL :: Validator
   - Camel :: YAML DSL :: Validator Maven Plugin
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/29922110206)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24236: camel-cyberark-vault - add support for cyberark policies [camel]

Posted by "tdiesler (via GitHub)" <gi...@apache.org>.
tdiesler commented on code in PR #25012:
URL: https://github.com/apache/camel/pull/25012#discussion_r3633785683


##########
components/camel-cyberark-vault/src/test/java/org/apache/camel/component/cyberark/vault/integration/CyberArkTestSupport.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.camel.component.cyberark.vault.integration;
+
+import java.net.URI;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class CyberArkTestSupport extends CamelTestSupport {
+
+    static final Logger LOG = LoggerFactory.getLogger(CyberArkTestSupport.class);
+
+    static HttpClient httpClient;
+    static String authToken;
+
+    @EndpointInject("mock:result")
+    MockEndpoint mockResult;
+
+    @BeforeAll
+    public static void beforeAll() throws Exception {
+        httpClient = HttpClient.newBuilder()
+                .connectTimeout(Duration.ofSeconds(10))
+                .build();
+
+        authToken = authenticate();
+    }
+
+    @AfterAll
+    public static void afterAll() throws Exception {
+        authToken = null;
+        httpClient = null;
+    }
+
+    private static String authenticate() throws Exception {
+        String url = String.format("%s/authn/%s/%s/authenticate",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                System.getProperty("camel.cyberark.username"));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(url))
+                .header("Content-Type", "text/plain")
+                .header("Accept-Encoding", "base64")
+                .POST(HttpRequest.BodyPublishers.ofString(System.getProperty("camel.cyberark.apiKey")))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Authenticate", response);
+
+        return response.body();
+    }
+
+    static void loadPolicy(String policy) throws Exception {
+
+        String policyUrl = String.format("%s/policies/%s/policy/%s",
+                System.getProperty("camel.cyberark.url"),
+                System.getProperty("camel.cyberark.account"),
+                URLEncoder.encode("root", StandardCharsets.UTF_8));
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create(policyUrl))
+                .header("Authorization", "Token token=\"" + authToken + "\"")
+                .header("Content-Type", "text/plain")
+                .method("PATCH", HttpRequest.BodyPublishers.ofString(policy))
+                .build();
+
+        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        requireSuccess("Load policy", response);
+    }
+
+    static void createSecret(String secretId, String secretValue) {
+        try {
+            String url = String.format("%s/secrets/%s/variable/%s",
+                    System.getProperty("camel.cyberark.url"),
+                    System.getProperty("camel.cyberark.account"),
+                    secretId);
+
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(URI.create(url))
+                    .header("Authorization", "Token token=\"" + authToken + "\"")
+                    .header("Content-Type", "application/octet-stream")
+                    .POST(HttpRequest.BodyPublishers.ofString(secretValue))
+                    .build();
+
+            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+            requireSuccess("Created secret", response);
+
+        } catch (Exception e) {
+            LOG.warn("Could not create secret '{}': {}", secretId, e.getMessage());

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org