Skip to content

Commit

Permalink
fix(google): Fix for the missing CredentialsRepository issue (#5793) (#…
Browse files Browse the repository at this point in the history
…5799)

* fix(google): Fix for the missing CredentialsRepository issue

* fix(google): Fix for the missing CredentialsRepository issue. Added test.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit b33f23a)

Co-authored-by: Kiran Godishala <[email protected]>
  • Loading branch information
mergify[bot] and kirangodishala authored Oct 21, 2022
1 parent e799bab commit 67ce8c8
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions clouddriver-google/clouddriver-google.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ dependencies {
testImplementation "org.spockframework:spock-core"
testImplementation "org.spockframework:spock-spring"
testImplementation "org.springframework:spring-test"
testImplementation "org.springframework.boot:spring-boot-test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
package com.netflix.spinnaker.clouddriver.google.config;

import com.netflix.spinnaker.clouddriver.google.ComputeVersion;
import com.netflix.spinnaker.clouddriver.google.GoogleCloudProvider;
import com.netflix.spinnaker.clouddriver.google.GoogleExecutor;
import com.netflix.spinnaker.clouddriver.google.security.GoogleNamedAccountCredentials;
import com.netflix.spinnaker.clouddriver.names.NamerRegistry;
import com.netflix.spinnaker.clouddriver.security.CredentialsInitializerSynchronizable;
import com.netflix.spinnaker.config.GoogleConfiguration;
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.beans.factory.annotation.Autowired;
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 Down Expand Up @@ -111,4 +116,13 @@ public void synchronize() {
}
};
}

@Bean
@ConditionalOnMissingBean(
value = GoogleNamedAccountCredentials.class,
parameterizedContainer = CredentialsRepository.class)
public CredentialsRepository<GoogleNamedAccountCredentials> googleCredentialsRepository(
CredentialsLifecycleHandler<GoogleNamedAccountCredentials> eventHandler) {
return new MapBackedCredentialsRepository<>(GoogleCloudProvider.getID(), eventHandler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2022 OpsMx, Inc.
*
* 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.
*/

package com.netflix.spinnaker.clouddriver.google.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.google.GoogleExecutor;
import com.netflix.spinnaker.clouddriver.google.deploy.converters.AbandonAndDecrementGoogleServerGroupAtomicOperationConverter;
import com.netflix.spinnaker.clouddriver.names.NamerRegistry;
import com.netflix.spinnaker.config.GoogleConfiguration;
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 GoogleCredentialsConfigurationTest {

private final ApplicationContextRunner runner =
new ApplicationContextRunner()
.withConfiguration(
UserConfigurations.of(
GoogleCredentialsConfiguration.class,
AbandonAndDecrementGoogleServerGroupAtomicOperationConverter.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
GoogleConfigurationProperties getGoogleConfigurationProperties() {
return mock(GoogleConfigurationProperties.class);
}

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

@Bean
GoogleConfiguration.DeployDefaults getGoogleConfigurationDeployDefaults() {
return mock(GoogleConfiguration.DeployDefaults.class);
}

@Bean
GoogleExecutor getGoogleExecutor() {
return mock(GoogleExecutor.class);
}

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

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

0 comments on commit 67ce8c8

Please sign in to comment.