diff --git a/.gitignore b/.gitignore index fc9b303cc..7d113e7ac 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ build/ *.iws out/ /.idea/ - +/.shelf/ diff --git a/fiat-core/fiat-core.gradle b/fiat-core/fiat-core.gradle index e69de29bb..56e6264e3 100644 --- a/fiat-core/fiat-core.gradle +++ b/fiat-core/fiat-core.gradle @@ -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') +} diff --git a/fiat-core/src/main/java/com/netflix/spinnaker/fiat/AccountProvider.java b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/AccountProvider.java new file mode 100644 index 000000000..750a6cb00 --- /dev/null +++ b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/AccountProvider.java @@ -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 accountProviders; + + public List getAccounts() { + return accountProviders + .stream() + .map(CloudAccountProvider::getAccounts) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } +} diff --git a/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/Authorization.java b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/Authorization.java new file mode 100644 index 000000000..487314da0 --- /dev/null +++ b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/Authorization.java @@ -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 +} diff --git a/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/CloudAccountProvider.java b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/CloudAccountProvider.java new file mode 100644 index 000000000..a9ab66bb6 --- /dev/null +++ b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/CloudAccountProvider.java @@ -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 accounts = new ArrayList<>(); +} diff --git a/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java new file mode 100644 index 000000000..97b5356a1 --- /dev/null +++ b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java @@ -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 requiredGroupMembership = new ArrayList<>(); + + @JsonIgnore + public View getView() { + return new View(); + } + + public class View { + String name = Account.this.name; + Set authorizations = ImmutableSet.of(Authorization.READ, + Authorization.WRITE); + } +} diff --git a/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java new file mode 100644 index 000000000..ed997342f --- /dev/null +++ b/fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java @@ -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 authorizations; +} diff --git a/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/AccountProviderSpec.groovy b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/AccountProviderSpec.groovy new file mode 100644 index 000000000..bdc3a7e83 --- /dev/null +++ b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/AccountProviderSpec.groovy @@ -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"] + } +} diff --git a/fiat-web/config/fiat.yml b/fiat-web/config/fiat.yml index 8b1378917..ac68b447e 100644 --- a/fiat-web/config/fiat.yml +++ b/fiat-web/config/fiat.yml @@ -1 +1,2 @@ - +server: + port: 7003 diff --git a/fiat-web/fiat-web.gradle b/fiat-web/fiat-web.gradle index 09683c12a..24f0a7eb0 100644 --- a/fiat-web/fiat-web.gradle +++ b/fiat-web/fiat-web.gradle @@ -21,5 +21,6 @@ dependencies { compile project(':fiat-core') } +applicationName = 'fiat' tasks.bootRepackage.enabled = project.repackage diff --git a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java index 743ca342a..440e291cf 100644 --- a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java +++ b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java @@ -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 DEFAULT_PROPS = buildDefaults(); diff --git a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/AccountConfiguration.java b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/AccountConfiguration.java new file mode 100644 index 000000000..ea10a1229 --- /dev/null +++ b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/AccountConfiguration.java @@ -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"); + } +} diff --git a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java new file mode 100644 index 000000000..c744b97bb --- /dev/null +++ b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java @@ -0,0 +1,4 @@ +package com.netflix.spinnaker.fiat.config; + +public class FiatConfig { +} diff --git a/lombok.config b/lombok.config new file mode 100644 index 000000000..b139174f6 --- /dev/null +++ b/lombok.config @@ -0,0 +1,2 @@ +lombok.nonNull.exceptionType = IllegalArgumentException +lombok.accessors.chain = true