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(codebuild): Add an API to list all AWS CodeBuild accounts #1023

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2020 Amazon.com, 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.gate.controllers;

import com.netflix.spinnaker.gate.services.internal.IgorService;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.*;

@ConditionalOnProperty("services.igor.enabled")
@RestController
@RequestMapping("/codebuild")
@RequiredArgsConstructor
public class AwsCodeBuildController {

private final IgorService igorService;

@ApiOperation(value = "Retrieve the list of AWS CodeBuild accounts", response = List.class)
@GetMapping(value = "/accounts")
List<String> getAccounts() {
return igorService.getAwsCodeBuildAccounts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ interface IgorService {
@GET('/gcb/triggers/{account}')
List<GoogleCloudBuildTrigger> getGoogleCloudBuildTriggers(@Path("account") String account);

@GET('/codebuild/accounts')
List<String> getAwsCodeBuildAccounts();

@GET('/artifacts/{provider}/{packageName}')
List<String> getArtifactVersions(@Path("provider") String provider,
@Path("packageName") String packageName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2020 Amazon.com, 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.gate.controllers

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.gate.services.internal.IgorService
import com.squareup.okhttp.mockwebserver.MockWebServer
import org.springframework.http.MediaType
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import spock.lang.Shared
import spock.lang.Specification

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get

class AwsCodeBuildControllerSpec extends Specification {

MockMvc mockMvc
IgorService igorService

def server = new MockWebServer()

@Shared def objectMapper = new ObjectMapper()
@Shared def ACCOUNT = 'myAccount'

void cleanup() {
server.shutdown()
}

void setup() {
igorService = Mock(IgorService)
server.start()
mockMvc = MockMvcBuilders.standaloneSetup(
new AwsCodeBuildController(igorService)).build()
}

void 'should get a list of accounts'() {
given:
def accounts = ["account1", "account2"]
1 * igorService.getAwsCodeBuildAccounts() >> accounts

when:
MockHttpServletResponse response = mockMvc.perform(get("/codebuild/accounts")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
response.status == 200
response.contentAsString == objectMapper.writeValueAsString(accounts)
}

void 'should get an empty list when no accounts found'() {
given:
1 * igorService.getAwsCodeBuildAccounts() >> []

when:
MockHttpServletResponse response = mockMvc.perform(get("/codebuild/accounts")
.accept(MediaType.APPLICATION_JSON)).andReturn().response

then:
response.status == 200
response.contentAsString == '[]'
}
}