Skip to content

Commit

Permalink
chore: adopt new operate client (SaaS config)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Dec 27, 2023
1 parent 0555bf2 commit cd1462b
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("!test")
public class SaaSConfiguration {

@Value("${camunda.saas.secrets.projectId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@
*/
package io.camunda.connector.runtime.saas;

import io.camunda.common.auth.Authentication;
import io.camunda.common.auth.JwtConfig;
import io.camunda.common.auth.JwtCredential;
import io.camunda.common.auth.Product;
import io.camunda.common.auth.SaaSAuthentication;
import io.camunda.connector.api.secret.SecretProvider;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.zeebe.spring.client.properties.OperateClientConfigurationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("!test")
public class SaaSOperateClientFactory {

private static final Logger LOG = LoggerFactory.getLogger(SaaSOperateClientFactory.class);
Expand All @@ -41,33 +36,39 @@ public class SaaSOperateClientFactory {

private final SecretProvider internalSecretProvider;

@Value("${camunda.operate.client.baseUrl}")
private String operateBaseUrl;

@Value("${camunda.operate.client.authUrl}")
private String operateAuthUrl;

@Value("${camunda.operate.client.url}")
private String operateUrl;

public SaaSOperateClientFactory(@Autowired SaaSConfiguration saaSConfiguration) {
this.internalSecretProvider = saaSConfiguration.getInternalSecretProvider();
}

@Bean
public OperatePropertiesPostProcessor operatePropertiesPostProcessor() {
return new OperatePropertiesPostProcessor();
}

@Bean
public CamundaOperateClient camundaOperateClientBundle() {
String operateClientId = internalSecretProvider.getSecret(SECRET_NAME_CLIENT_ID);
String operateClientSecret = internalSecretProvider.getSecret(SECRET_NAME_SECRET);
JwtConfig jwtConfig = new JwtConfig();
jwtConfig.addProduct(
Product.OPERATE,
new JwtCredential(operateClientId, operateClientSecret, operateBaseUrl, operateAuthUrl));
return CamundaOperateClient.builder().operateUrl(operateUrl).setup().build();
}

public class OperatePropertiesPostProcessor implements BeanPostProcessor {

public OperatePropertiesPostProcessor() {
LOG.info("OperatePropertiesPostProcessor created");
}

Authentication authentication = SaaSAuthentication.builder().jwtConfig(jwtConfig).build();
return CamundaOperateClient.builder()
.operateUrl(operateUrl)
.authentication(authentication)
.setup()
.build();
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
if (bean instanceof OperateClientConfigurationProperties operateProperties) {
String operateClientId = internalSecretProvider.getSecret(SECRET_NAME_CLIENT_ID);
String operateClientSecret = internalSecretProvider.getSecret(SECRET_NAME_SECRET);
operateProperties.setClientId(operateClientId);
operateProperties.setClientSecret(operateClientSecret);
return operateProperties;
}
return bean;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; 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 io.camunda.connector.runtime.saas;

import io.camunda.connector.api.secret.SecretProvider;
import io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties;
import java.util.Map;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;

@TestConfiguration
public class MockSaaSConfiguration {

public static final String OPERATE_CLIENT_URL =
"https://operate.cloud.dev.ultrawombat.com/myClusterId";
public static final String OPERATE_CLIENT_BASEURL = "operate.cloud.dev.ultrawombat.com";
public static final String OPERATE_CLIENT_AUTH_URL =
"https://login.cloud.dev.ultrawombat.com/oauth/token";
public static final String OPERATE_CLIENT_CLIENT_ID = "clientId";
public static final String OPERATE_CLIENT_SECRET = "secret";

private final Map<String, String> secrets =
Map.of(
SaaSOperateClientFactory.SECRET_NAME_CLIENT_ID, OPERATE_CLIENT_CLIENT_ID,
SaaSOperateClientFactory.SECRET_NAME_SECRET, OPERATE_CLIENT_SECRET);

@Bean
public SaaSConfiguration saaSConfiguration(ZeebeClientConfigurationProperties conf) {
return new SaaSConfiguration(conf) {
@Override
public SecretProvider getInternalSecretProvider() {
return secrets::get;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime;
package io.camunda.connector.runtime.saas;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
Expand All @@ -26,7 +26,6 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import io.camunda.connector.runtime.saas.SaaSConnectorRuntimeApplication;
import io.camunda.operate.CamundaOperateClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -46,13 +45,16 @@

@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
classes = {SaaSConnectorRuntimeApplication.class},
classes = {SaaSConnectorRuntimeApplication.class, MockSaaSConfiguration.class},
properties = {
"camunda.saas.secrets.projectId=42",
"zeebe.client.cloud.cluster-id=42",
"zeebe.client.security.plaintext=true",
"camunda.connector.auth.audience=connectors.dev.ultrawombat.com",
"camunda.connector.auth.issuer=https://weblogin.cloud.dev.ultrawombat.com/"
"camunda.connector.auth.issuer=https://weblogin.cloud.dev.ultrawombat.com/",
"camunda.operate.client.url=" + MockSaaSConfiguration.OPERATE_CLIENT_URL,
"camunda.operate.client.authUrl=" + MockSaaSConfiguration.OPERATE_CLIENT_AUTH_URL,
"camunda.operate.client.baseUrl=" + MockSaaSConfiguration.OPERATE_CLIENT_BASEURL
})
@DirtiesContext
@ActiveProfiles("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime;
package io.camunda.connector.runtime.saas;

import io.camunda.connector.runtime.saas.SaaSConnectorRuntimeApplication;
import static org.assertj.core.api.Assertions.assertThat;

import io.camunda.zeebe.spring.client.properties.OperateClientConfigurationProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest(
classes = SaaSConnectorRuntimeApplication.class,
classes = {SaaSConnectorRuntimeApplication.class, MockSaaSConfiguration.class},
properties = {
"camunda.saas.secrets.projectId=42",
"zeebe.client.cloud.cluster-id=42",
"zeebe.client.security.plaintext=true",
"camunda.connector.auth.audience=connectors.dev.ultrawombat.com",
"camunda.connector.auth.issuer=https://weblogin.cloud.dev.ultrawombat.com/"
"camunda.connector.auth.issuer=https://weblogin.cloud.dev.ultrawombat.com/",
"camunda.operate.client.url=" + MockSaaSConfiguration.OPERATE_CLIENT_URL,
"camunda.operate.client.authUrl=" + MockSaaSConfiguration.OPERATE_CLIENT_AUTH_URL,
"camunda.operate.client.baseUrl=" + MockSaaSConfiguration.OPERATE_CLIENT_BASEURL
})
@ActiveProfiles("test")
public class TestSpringContextStartup {

@Autowired private OperateClientConfigurationProperties operateProperties;

@Test
public void contextLoaded() {
// This test case just verifies that the runtime comes up without problems around
// conflicting class files in logging or other wired behavior that can be observed
// when the Spring context is initialized (e.g.
// https://github.com/camunda/team-connectors/issues/251)
}

@Test
public void operatePropertiesAreSet() {
assertThat(operateProperties.getUrl()).isEqualTo(MockSaaSConfiguration.OPERATE_CLIENT_URL);
assertThat(operateProperties.getAuthUrl())
.isEqualTo(MockSaaSConfiguration.OPERATE_CLIENT_AUTH_URL);
assertThat(operateProperties.getBaseUrl())
.isEqualTo(MockSaaSConfiguration.OPERATE_CLIENT_BASEURL);
assertThat(operateProperties.getClientId())
.isEqualTo(MockSaaSConfiguration.OPERATE_CLIENT_CLIENT_ID);
assertThat(operateProperties.getClientSecret())
.isEqualTo(MockSaaSConfiguration.OPERATE_CLIENT_SECRET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.camunda.connector.runtime.inbound.InboundConnectorRuntimeConfiguration;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.zeebe.spring.client.CamundaAutoConfiguration;
import io.camunda.zeebe.spring.client.configuration.OperateClientProdAutoConfiguration;
import io.camunda.zeebe.spring.client.configuration.OperateClientConfiguration;
import io.camunda.zeebe.spring.client.properties.OperateClientConfigurationProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -45,14 +45,13 @@ public class InboundConnectorsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public CamundaOperateClient myOperateClient(
OperateClientProdAutoConfiguration configuration,
OperateClientConfigurationProperties properties) {
OperateClientConfiguration configuration, OperateClientConfigurationProperties properties) {
return configuration.camundaOperateClient(properties);
}

@Bean
@ConditionalOnMissingBean
public OperateClientProdAutoConfiguration operateClientProdAutoConfiguration() {
return new OperateClientProdAutoConfiguration();
public OperateClientConfiguration operateClientProdAutoConfiguration() {
return new OperateClientConfiguration();
}
}
4 changes: 2 additions & 2 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ limitations under the License.</license.inlineheader>
<nexus.sonatype.url>https://s01.oss.sonatype.org</nexus.sonatype.url>

<!-- Camunda internal libraries -->
<version.zeebe>8.4.0-SNAPSHOT</version.zeebe>
<version.spring-zeebe>8.4.0-alpha2-rc3</version.spring-zeebe>
<version.zeebe>8.4.0-alpha2</version.zeebe>
<version.spring-zeebe>8.4.0-alpha2-rc4</version.spring-zeebe>
<version.feel-engine>1.17.3</version.feel-engine>

<!-- Third party dependencies -->
Expand Down

0 comments on commit cd1462b

Please sign in to comment.