Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider/cf): add provider skeleton with credentials management #2838

Merged
merged 2 commits into from Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions clouddriver-cloudfoundry/clouddriver-cloudfoundry.gradle
@@ -0,0 +1,16 @@
dependencies {
compile project(":clouddriver-artifacts")
compile project(":clouddriver-core")

compile spinnaker.dependency('frigga')
compile spinnaker.dependency('bootActuator')
compile spinnaker.dependency('bootWeb')

compile spinnaker.dependency('korkArtifacts')
compile spinnaker.dependency('lombok')

spinnaker.group('retrofitDefault')
spinnaker.group('test')

compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${spinnaker.version("jackson")}"
}
@@ -0,0 +1,40 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry;

import com.netflix.spinnaker.clouddriver.core.CloudProvider;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;

@Component
public class CloudFoundryCloudProvider implements CloudProvider {
@Override
public String getId() {
return "cloudfoundry";
}

@Override
public String getDisplayName() {
return "Cloud Foundry";
}

@Override
public Class<? extends Annotation> getOperationAnnotationType() {
return CloudFoundryOperation.class;
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry;

import com.netflix.spinnaker.cats.provider.ProviderSynchronizerTypeWrapper;
import com.netflix.spinnaker.clouddriver.cloudfoundry.config.CloudFoundryConfigurationProperties;
import com.netflix.spinnaker.clouddriver.cloudfoundry.security.CloudFoundryCredentialsInitializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableConfigurationProperties
@EnableScheduling
@ConditionalOnProperty("cloudfoundry.enabled")
@ComponentScan("com.netflix.spinnaker.clouddriver.cloudfoundry")
public class CloudFoundryConfiguration {

@Bean
CloudFoundryConfigurationProperties cloudFoundryConfigurationProperties() {
return new CloudFoundryConfigurationProperties();
}

@Bean
CloudFoundrySynchronizerTypeWrapper cloudFoundrySynchronizerTypeWrapper() {
return new CloudFoundrySynchronizerTypeWrapper();
}

@Bean
CloudFoundryCredentialsInitializer cloudFoundryCredentialsInitializer() {
return new CloudFoundryCredentialsInitializer();
}

public static class CloudFoundryProviderSynchronizer {
}

class CloudFoundrySynchronizerTypeWrapper implements ProviderSynchronizerTypeWrapper {
@Override
public Class getSynchronizerType() {
return CloudFoundryProviderSynchronizer.class;
}
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface CloudFoundryOperation {
String value();
}
@@ -0,0 +1,27 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry.client;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class CloudFoundryClient {
private final String account;
private final String apiHost;
private final String user;
private final String password;
}
@@ -0,0 +1,45 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry.config;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Data
@ConfigurationProperties("cloudfoundry")
public class CloudFoundryConfigurationProperties {
private List<ManagedAccount> accounts = new ArrayList<>();

@Getter
@Setter
@ToString(exclude = "password")
public static class ManagedAccount {
private String name;
private String api;
private String user;
private String password;
private String environment;
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry.provider;

import com.netflix.spinnaker.cats.agent.Agent;
import com.netflix.spinnaker.cats.agent.AgentSchedulerAware;
import com.netflix.spinnaker.clouddriver.cache.SearchableProvider;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

@RequiredArgsConstructor
@Getter
public class CloudFoundryProvider extends AgentSchedulerAware implements SearchableProvider {
// todo(jkschneider): add default caches
final Set<String> defaultCaches = Collections.emptySet();
final Map<String, String> urlMappingTemplates = Collections.emptyMap();
// todo(jkschneider): add search result hydrator
final Map<SearchableResource, SearchResultHydrator> searchResultHydrators = Collections.emptyMap();
private final String id = "cloudfoundry";
private final String providerName = CloudFoundryProvider.class.getName();
private final Collection<Agent> agents;

@Override
public Map<String, String> parseKey(String key) {
// todo(jkschneider): parse keys
return Collections.emptyMap();
}
}
@@ -0,0 +1,65 @@
/*
* Copyright 2018 Pivotal, 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.cloudfoundry.provider.agent;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.cats.agent.*;
import com.netflix.spinnaker.cats.provider.ProviderCache;
import com.netflix.spinnaker.clouddriver.cloudfoundry.provider.CloudFoundryProvider;
import com.netflix.spinnaker.clouddriver.cloudfoundry.security.CloudFoundryCredentials;
import com.netflix.spinnaker.clouddriver.core.provider.agent.Namespace;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

@RequiredArgsConstructor
@Getter
@Slf4j
public class CloudFoundryCachingAgent implements CachingAgent, AccountAware {
final String providerName = CloudFoundryProvider.class.getName();
final Collection<AgentDataType> providedDataTypes = Arrays.asList(
AgentDataType.Authority.AUTHORITATIVE.forType(Namespace.APPLICATIONS.ns),
AgentDataType.Authority.AUTHORITATIVE.forType(Namespace.CLUSTERS.ns),
AgentDataType.Authority.AUTHORITATIVE.forType(Namespace.SERVER_GROUPS.ns),
AgentDataType.Authority.AUTHORITATIVE.forType(Namespace.INSTANCES.ns),
AgentDataType.Authority.AUTHORITATIVE.forType(Namespace.LOAD_BALANCERS.ns)
);
private final CloudFoundryCredentials credentials;
private final ObjectMapper objectMapper;

@Override
public CacheResult loadData(ProviderCache providerCache) {
log.info("Caching all resources in Cloud Foundry account $accountName");

// todo(jkschneider): cache all Cloud Foundry resources
return new DefaultCacheResult(Collections.emptyMap());
}

@Override
public String getAccountName() {
return credentials.getName();
}

@Override
public String getAgentType() {
return getAccountName() + "/" + getClass().getSimpleName();
}
}