Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an internal upstream pipelines listing API
* This API is required on the pipeline config SPA to provide auto suggestions for upstream pipelines while fetching artifacts
- Loading branch information
1 parent
52cb509
commit bb97610
Showing
8 changed files
with
220 additions
and
0 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
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,27 @@ | ||
/* | ||
* Copyright 2020 ThoughtWorks, 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. | ||
*/ | ||
|
||
apply plugin: 'jacoco' | ||
apply plugin: 'groovy' | ||
|
||
dependencies { | ||
compile project(':api:api-base') | ||
|
||
testCompile project(path: ':api:api-base', configuration: 'testOutput') | ||
|
||
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: project.versions.junit5 | ||
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: project.versions.junit5 | ||
} |
87 changes: 87 additions & 0 deletions
87
...htworks/go/apiv1/internaldependencypipelines/InternalDependencyPipelinesControllerV1.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,87 @@ | ||
/* | ||
* Copyright 2020 ThoughtWorks, 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.thoughtworks.go.apiv1.internaldependencypipelines; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.thoughtworks.go.api.ApiController; | ||
import com.thoughtworks.go.api.ApiVersion; | ||
import com.thoughtworks.go.api.spring.ApiAuthenticationHelper; | ||
import com.thoughtworks.go.config.CaseInsensitiveString; | ||
import com.thoughtworks.go.config.CruiseConfig; | ||
import com.thoughtworks.go.server.presentation.FetchArtifactViewHelper; | ||
import com.thoughtworks.go.server.service.GoConfigService; | ||
import com.thoughtworks.go.spark.Routes; | ||
import com.thoughtworks.go.spark.spring.SparkSpringController; | ||
import com.thoughtworks.go.util.SystemEnvironment; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import spark.Request; | ||
import spark.Response; | ||
|
||
import static spark.Spark.*; | ||
|
||
@Component | ||
public class InternalDependencyPipelinesControllerV1 extends ApiController implements SparkSpringController { | ||
|
||
private final ApiAuthenticationHelper apiAuthenticationHelper; | ||
private SystemEnvironment systemEnvironment; | ||
private GoConfigService goConfigService; | ||
private Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); | ||
|
||
@Autowired | ||
public InternalDependencyPipelinesControllerV1(ApiAuthenticationHelper apiAuthenticationHelper, | ||
SystemEnvironment systemEnvironment, | ||
GoConfigService goConfigService) { | ||
super(ApiVersion.v1); | ||
this.apiAuthenticationHelper = apiAuthenticationHelper; | ||
this.systemEnvironment = systemEnvironment; | ||
this.goConfigService = goConfigService; | ||
} | ||
|
||
@Override | ||
public String controllerBasePath() { | ||
return Routes.InternalDependencyPipelines.BASE; | ||
} | ||
|
||
@Override | ||
public void setupRoutes() { | ||
path(controllerBasePath(), () -> { | ||
before("", mimeType, this::setContentType); | ||
before("/*", mimeType, this::setContentType); | ||
|
||
before("", mimeType, this::verifyContentType); | ||
before("/*", mimeType, this::verifyContentType); | ||
|
||
before("", mimeType, apiAuthenticationHelper::checkUserAnd403); | ||
|
||
get("", mimeType, this::index); | ||
}); | ||
} | ||
|
||
public String index(Request request, Response response) { | ||
String pipelineName = request.params("pipeline_name"); | ||
String stageName = request.params("stage_name"); | ||
|
||
CruiseConfig config = goConfigService.getMergedConfigForEditing(); | ||
FetchArtifactViewHelper helper = new FetchArtifactViewHelper(systemEnvironment, config, new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(stageName), false); | ||
|
||
response.type("application/json"); | ||
return gson.toJson(helper.autosuggestMap()); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...s/go/apiv1/internaldependencypipelines/InternalDependencyPipelinesControllerV1Test.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,90 @@ | ||
/* | ||
* Copyright 2020 ThoughtWorks, 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.thoughtworks.go.apiv1.internaldependencypipelines | ||
|
||
import com.thoughtworks.go.api.SecurityTestTrait | ||
import com.thoughtworks.go.api.spring.ApiAuthenticationHelper | ||
import com.thoughtworks.go.config.BasicCruiseConfig | ||
import com.thoughtworks.go.helper.PipelineConfigMother | ||
import com.thoughtworks.go.server.service.GoConfigService | ||
import com.thoughtworks.go.spark.ControllerTrait | ||
import com.thoughtworks.go.spark.NormalUserSecurity | ||
import com.thoughtworks.go.spark.SecurityServiceTrait | ||
import com.thoughtworks.go.util.SystemEnvironment | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mock | ||
|
||
import static org.mockito.Mockito.when | ||
import static org.mockito.MockitoAnnotations.initMocks | ||
|
||
class InternalDependencyPipelinesControllerV1Test implements SecurityServiceTrait, ControllerTrait<InternalDependencyPipelinesControllerV1> { | ||
@Mock | ||
GoConfigService goConfigService | ||
|
||
@BeforeEach | ||
void setUp() { | ||
initMocks(this) | ||
} | ||
|
||
@Override | ||
InternalDependencyPipelinesControllerV1 createControllerInstance() { | ||
new InternalDependencyPipelinesControllerV1(new ApiAuthenticationHelper(securityService, goConfigService), new SystemEnvironment(), goConfigService) | ||
} | ||
|
||
@Nested | ||
class Index { | ||
@Nested | ||
class Security implements SecurityTestTrait, NormalUserSecurity { | ||
|
||
@Override | ||
String getControllerMethodUnderTest() { | ||
return "index" | ||
} | ||
|
||
@Override | ||
void makeHttpCall() { | ||
getWithApiHeader(path('pipeline', 'stage')) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
void 'should return pipeline auto suggestions'() { | ||
def config = new BasicCruiseConfig() | ||
config.addPipeline("first", PipelineConfigMother.pipelineConfig("pipeline1")) | ||
when(goConfigService.getMergedConfigForEditing()).thenReturn(config) | ||
|
||
getWithApiHeader(path('pipeline1', 'stage')) | ||
|
||
assertThatResponse() | ||
.isOk() | ||
.hasJsonBody('{' + | ||
' "pipeline1": {' + | ||
' "mingle": {}' + | ||
' },' + | ||
' "": {' + | ||
' "mingle": {}' + | ||
' }' + | ||
'}') | ||
} | ||
|
||
String path(String name, String stageName) { | ||
return controller.controllerBasePath().replaceAll(":pipeline_name", name).replaceAll(':stage_name', stageName) | ||
} | ||
} |
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
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