Skip to content

Commit

Permalink
fix(appengine): Fixes app engine credentials repo (#5807)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmcintosh authored Nov 2, 2022
1 parent 0db8d55 commit dc54e38
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions clouddriver-appengine/clouddriver-appengine.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation "org.springframework.cloud:spring-cloud-context"
implementation "org.springframework.cloud:spring-cloud-config-server"

testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation "cglib:cglib-nodep"
testImplementation "org.objenesis:objenesis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@

package com.netflix.spinnaker.clouddriver.appengine.config;

import com.netflix.spinnaker.clouddriver.appengine.AppengineCloudProvider;
import com.netflix.spinnaker.clouddriver.appengine.AppengineJobExecutor;
import com.netflix.spinnaker.clouddriver.appengine.security.AppengineNamedAccountCredentials;
import com.netflix.spinnaker.clouddriver.security.CredentialsInitializerSynchronizable;
import com.netflix.spinnaker.credentials.CredentialsLifecycleHandler;
import com.netflix.spinnaker.credentials.CredentialsRepository;
import com.netflix.spinnaker.credentials.CredentialsTypeBaseConfiguration;
import com.netflix.spinnaker.credentials.CredentialsTypeProperties;
import com.netflix.spinnaker.credentials.MapBackedCredentialsRepository;
import com.netflix.spinnaker.credentials.definition.AbstractCredentialsLoader;
import com.netflix.spinnaker.credentials.poller.Poller;
import com.netflix.spinnaker.kork.configserver.ConfigFileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -36,6 +41,15 @@ public class AppengineCredentialsConfiguration {
private static final Logger log =
LoggerFactory.getLogger(AppengineCredentialsConfiguration.class);

@Bean
@ConditionalOnMissingBean(
value = AppengineNamedAccountCredentials.class,
parameterizedContainer = CredentialsRepository.class)
public CredentialsRepository<AppengineNamedAccountCredentials> appengineCredentialsRepository(
CredentialsLifecycleHandler<AppengineNamedAccountCredentials> eventHandler) {
return new MapBackedCredentialsRepository<>(AppengineCloudProvider.getID(), eventHandler);
}

@Bean
public CredentialsTypeBaseConfiguration<
AppengineNamedAccountCredentials, AppengineConfigurationProperties.ManagedAccount>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.netflix.spinnaker.clouddriver.appengine.config;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.clouddriver.appengine.AppengineJobExecutor;
import com.netflix.spinnaker.clouddriver.jobs.JobExecutor;
import com.netflix.spinnaker.clouddriver.names.NamerRegistry;
import com.netflix.spinnaker.credentials.CredentialsLifecycleHandler;
import com.netflix.spinnaker.credentials.CredentialsRepository;
import com.netflix.spinnaker.kork.configserver.ConfigFileService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.annotation.UserConfigurations;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;

public class AppEngineAccountCredentialsRepoTest {

private final ApplicationContextRunner runner =
new ApplicationContextRunner()
.withConfiguration(
UserConfigurations.of(
AppengineCredentialsConfiguration.class, TestConfiguration.class));

@Test
void testCredentialsRepositoryBeanIsPresent() {
runner.run(ctx -> assertThat(ctx).hasSingleBean(CredentialsRepository.class));
}

static class TestConfiguration {
@Bean
ObjectMapper getObjectMapper() {
return new ObjectMapper();
}

@Bean
CredentialsLifecycleHandler getCredentialsLifecycleHandler() {
return mock(CredentialsLifecycleHandler.class);
}

@Bean
NamerRegistry getNamerRegistry() {
return mock(NamerRegistry.class);
}

@Bean
AppengineConfigurationProperties getAppengineConfigurationProperties() {
return mock(AppengineConfigurationProperties.class);
}

@Bean
ConfigFileService getConfigFileService() {
return mock(ConfigFileService.class);
}

@Bean
AppengineJobExecutor getAppengineExecutor() {
return mock(AppengineJobExecutor.class);
}

@Bean
JobExecutor getJobExecutor() {
return mock(JobExecutor.class);
}

@Bean
Registry getRegistry() {
return mock(Registry.class);
}

@Bean
String getClouddriverUserAgentApplicationName() {
return "clouddriverUserAgentApplicationName";
}
}
}

0 comments on commit dc54e38

Please sign in to comment.