Skip to content

Commit

Permalink
Initial account configuration + provider (#1)
Browse files Browse the repository at this point in the history
Initial account configuration + provider
  • Loading branch information
Travis Tomsu authored Jun 22, 2016
1 parent 1ed0af7 commit 6bd828d
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ build/
*.iws
out/
/.idea/

/.shelf/
11 changes: 11 additions & 0 deletions fiat-core/fiat-core.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies {
spinnaker.group("retrofitDefault")

// TODO(cfieber): Setup a configuration scope for it so this doesn't
// become a transitive dependency
compile spinnaker.dependency('lombok')
compile spinnaker.dependency('springContext')
compile spinnaker.dependency('guava')

testCompile spinnaker.dependency('spockSpring')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2016 Google, 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.fiat;

import com.netflix.spinnaker.fiat.model.CloudAccountProvider;
import com.netflix.spinnaker.fiat.model.resources.Account;
import lombok.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class AccountProvider {

@Autowired
@Setter
private List<CloudAccountProvider> accountProviders;

public List<Account> getAccounts() {
return accountProviders
.stream()
.map(CloudAccountProvider::getAccounts)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2016 Google, 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.fiat.model;

public enum Authorization {
READ,
WRITE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016 Google, 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.fiat.model;

import com.netflix.spinnaker.fiat.model.resources.Account;
import lombok.Data;

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

@Data
public class CloudAccountProvider {
private final String cloudProvider;
private List<Account> accounts = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2016 Google, 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.fiat.model.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableSet;
import com.netflix.spinnaker.fiat.model.Authorization;
import lombok.Data;

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

@Data
public class Account {
private String name;
private List<String> requiredGroupMembership = new ArrayList<>();

@JsonIgnore
public View getView() {
return new View();
}

public class View {
String name = Account.this.name;
Set<Authorization> authorizations = ImmutableSet.of(Authorization.READ,
Authorization.WRITE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2016 Google, 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.fiat.model.resources;

import com.netflix.spinnaker.fiat.model.Authorization;
import lombok.Data;

import java.util.Set;

@Data
public class Application {
private final String name;
private final Set<Authorization> authorizations;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2016 Google, 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.fiat

import com.netflix.spinnaker.fiat.model.CloudAccountProvider
import com.netflix.spinnaker.fiat.model.resources.Account
import spock.lang.Specification

class AccountProviderSpec extends Specification {

def "should get all configured accounts"() {
setup:
AccountProvider provider = new AccountProvider().setAccountProviders(
[
new CloudAccountProvider("A").setAccounts([new Account().setName("account1")]),
new CloudAccountProvider("B").setAccounts([new Account().setName("account2")])
]);

when:
def result = provider.getAccounts()

then:
result.size() == 2
result*.name == ["account1", "account2"]
}
}
3 changes: 2 additions & 1 deletion fiat-web/config/fiat.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

server:
port: 7003
1 change: 1 addition & 0 deletions fiat-web/fiat-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ dependencies {
compile project(':fiat-core')
}

applicationName = 'fiat'
tasks.bootRepackage.enabled = project.repackage

9 changes: 4 additions & 5 deletions fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.security.Security;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;

@Configuration
@ComponentScan({
"com.netflix.spinnaker.config",
"com.netflix.spinnaker.fiat",
"com.netflix.spinnaker.config",
})
@EnableAutoConfiguration
class Main extends SpringBootServletInitializer {
public class Main extends SpringBootServletInitializer {

private static final Map<String, Object> DEFAULT_PROPS = buildDefaults();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2016 Google, 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.fiat.config;

import com.netflix.spinnaker.fiat.model.CloudAccountProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AccountConfiguration {

@Bean
@ConfigurationProperties("aws")
@ConditionalOnProperty("providers.aws.enabled")
public CloudAccountProvider awsAccounts() {
return new CloudAccountProvider("aws");
}

@Bean
@ConfigurationProperties("azure")
@ConditionalOnProperty("providers.azure.enabled")
public CloudAccountProvider azureAccounts() {
return new CloudAccountProvider("azure");
}

@Bean
@ConfigurationProperties("cf")
@ConditionalOnProperty("providers.cf.enabled")
public CloudAccountProvider cfAccounts() {
return new CloudAccountProvider("cf");
}

@Bean
@ConfigurationProperties("google")
@ConditionalOnProperty("providers.google.enabled")
public CloudAccountProvider googleAccounts() {
return new CloudAccountProvider("google");
}

@Bean
@ConfigurationProperties("kubernetes")
@ConditionalOnProperty("providers.kubernetes.enabled")
public CloudAccountProvider kubernetesAccounts() {
return new CloudAccountProvider("kubernetes");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.netflix.spinnaker.fiat.config;

public class FiatConfig {
}
2 changes: 2 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lombok.nonNull.exceptionType = IllegalArgumentException
lombok.accessors.chain = true

0 comments on commit 6bd828d

Please sign in to comment.