-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial account configuration + provider (#1)
Initial account configuration + provider
- Loading branch information
Travis Tomsu
authored
Jun 22, 2016
1 parent
1ed0af7
commit 6bd828d
Showing
14 changed files
with
292 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ build/ | |
*.iws | ||
out/ | ||
/.idea/ | ||
|
||
/.shelf/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} |
43 changes: 43 additions & 0 deletions
43
fiat-core/src/main/java/com/netflix/spinnaker/fiat/AccountProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/Authorization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
29 changes: 29 additions & 0 deletions
29
fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/CloudAccountProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} |
43 changes: 43 additions & 0 deletions
43
fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
fiat-core/src/main/java/com/netflix/spinnaker/fiat/model/resources/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
40 changes: 40 additions & 0 deletions
40
fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/AccountProviderSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
|
||
server: | ||
port: 7003 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/AccountConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.netflix.spinnaker.fiat.config; | ||
|
||
public class FiatConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lombok.nonNull.exceptionType = IllegalArgumentException | ||
lombok.accessors.chain = true |