Skip to content

Commit

Permalink
feat(provider/cf) add provider skeleton with credentials management
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Schneider committed Aug 6, 2018
1 parent d1baa68 commit e833e31
Show file tree
Hide file tree
Showing 14 changed files with 535 additions and 2 deletions.
19 changes: 19 additions & 0 deletions clouddriver-cloudfoundry/clouddriver-cloudfoundry.gradle
@@ -0,0 +1,19 @@
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 'io.micrometer:micrometer-registry-prometheus:latest.release'
compile 'io.micrometer:micrometer-spring-legacy:latest.release'

compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${spinnaker.version("jackson")}"
}
@@ -0,0 +1,30 @@
/*
* 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
class CloudFoundryCloudProvider implements CloudProvider {
static final String ID = 'cloudfoundry'
final String id = ID
final String displayName = "Cloud Foundry"
final Class<Annotation> operationAnnotationType = CloudFoundryOperation
}
@@ -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 com.netflix.spinnaker.clouddriver.helpers.OperationPoller
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'])
class CloudFoundryConfiguration {

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

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

class CloudFoundrySynchronizerTypeWrapper implements ProviderSynchronizerTypeWrapper {
@Override
Class getSynchronizerType() {
CloudFoundryProviderSynchronizer
}
}

class CloudFoundryProviderSynchronizer {}

@Bean
CloudFoundryCredentialsInitializer cloudFoundryCredentialsInitializer() {
new CloudFoundryCredentialsInitializer()
}
}
@@ -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,30 @@
/*
* 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

class CloudFoundryClient {
private final String account
private final String apiHost
private final String user
private final String password

CloudFoundryClient(String account, String apiHost, String user, String password) {
this.account = account
this.apiHost = apiHost
this.user = user
this.password = password
}
}
@@ -0,0 +1,35 @@
/*
* 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 groovy.transform.ToString
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component

@Component
@ToString(includeNames = true)
@ConfigurationProperties('cloudfoundry')
class CloudFoundryConfigurationProperties {
List<ManagedAccount> accounts = []

@ToString(includeNames = true, excludes = "password")
static class ManagedAccount {
String name
String api
String user
String password
}
}
@@ -0,0 +1,59 @@
/*
* 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

class CloudFoundryProvider extends AgentSchedulerAware implements SearchableProvider {

public static final String ID = "cloudfoundry"
final String id = ID

static final String PROVIDER_NAME = CloudFoundryProvider.name

private final Collection<Agent> agents

CloudFoundryProvider(Collection<Agent> agents) {
this.agents = agents
}

@Override
String getProviderName() {
return PROVIDER_NAME
}

@Override
Collection<Agent> getAgents() {
agents
}

// todo(jkschneider): add default caches
final Set<String> defaultCaches = [].asImmutable()

final Map<String, String> urlMappingTemplates = [:].asImmutable()

// todo(jkschneider): add search result hydrator
final Map<SearchableResource, SearchResultHydrator> searchResultHydrators = [:].asImmutable()

@Override
Map<String, String> parseKey(String key) {
// todo(jkschneider): parse keys
return [:]
}
}
@@ -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.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 groovy.util.logging.Slf4j

@Slf4j
class CloudFoundryCachingAgent implements CachingAgent, AccountAware {
private final ObjectMapper objectMapper
private final CloudFoundryCredentials credentials

final String accountName
final String providerName = CloudFoundryProvider.name

final Collection<AgentDataType> providedDataTypes = [
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)
].asImmutable()

CloudFoundryCachingAgent(CloudFoundryCredentials credentials, ObjectMapper objectMapper) {
this.objectMapper = objectMapper
this.credentials = credentials
this.accountName = credentials.name
}

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

// todo(jkschneider): cache all Cloud Foundry resources
return new DefaultCacheResult([:])
}

@Override
String getAgentType() {
"${accountName}/${this.class.simpleName}"
}
}

0 comments on commit e833e31

Please sign in to comment.