Skip to content

Commit

Permalink
fix(plugins): allow only enabled preconfigured jobs for configuration…
Browse files Browse the repository at this point in the history
… in pipelines (#3564)
  • Loading branch information
srekapalli committed Apr 2, 2020
1 parent b91f25d commit ccddb75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,17 @@ class OperationsController {
if (!jobService) {
return []
}
return jobService?.getPreconfiguredStages().collect{
[ label: it.label,
description: it.description,
type: it.type,
waitForCompletion: it.waitForCompletion,
noUserConfigurableFields: true,
parameters: it.parameters,
producesArtifacts: it.producesArtifacts,
uiType: it.uiType
]
// Only allow enabled jobs for configuration in pipelines.
return jobService.getPreconfiguredStages().findAll { it.enabled } .collect {
[label : it.label,
description : it.description,
type : it.type,
waitForCompletion : it.waitForCompletion,
noUserConfigurableFields: true,
parameters : it.parameters,
producesArtifacts : it.producesArtifacts,
uiType : it.uiType
]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.netflix.spinnaker.fiat.model.resources.Role
import com.netflix.spinnaker.fiat.shared.FiatService
import com.netflix.spinnaker.fiat.shared.FiatStatus
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType
import com.netflix.spinnaker.orca.api.preconfigured.jobs.TitusPreconfiguredJobProperties
import com.netflix.spinnaker.orca.clouddriver.service.JobService
import com.netflix.spinnaker.orca.front50.Front50Service

import javax.servlet.http.HttpServletResponse
Expand Down Expand Up @@ -75,6 +77,7 @@ class OperationsControllerSpec extends Specification {
_ * isEnabled() >> { return false }
}
def front50Service = Mock(Front50Service)
def jobService = Mock(JobService)

@Subject
controller = new OperationsController(
Expand All @@ -88,7 +91,8 @@ class OperationsControllerSpec extends Specification {
artifactUtils: artifactUtils,
fiatService: fiatService,
fiatStatus: fiatStatus,
front50Service: front50Service
front50Service: front50Service,
jobService: jobService
)

@Unroll
Expand Down Expand Up @@ -765,6 +769,22 @@ class OperationsControllerSpec extends Specification {
startedPipeline.trigger.parameters.key1 == 'value1'
}

def "should return only jobs that are enabled"() {
given:
TitusPreconfiguredJobProperties jobProps1 = new TitusPreconfiguredJobProperties(enabled: true, label: 'job1')
TitusPreconfiguredJobProperties jobProps2 = new TitusPreconfiguredJobProperties(enabled: false, label: 'job2')
TitusPreconfiguredJobProperties jobProps3 = new TitusPreconfiguredJobProperties(label: 'job3')

when:
def preconfiguredWebhooks = controller.preconfiguredJob()

then:
1* jobService.getPreconfiguredStages() >> [jobProps1, jobProps2, jobProps3]
preconfiguredWebhooks.size() == 2
preconfiguredWebhooks.find { it.label == 'job1' }
preconfiguredWebhooks.find { it.label == 'job3' }
}

static WebhookProperties.PreconfiguredWebhook createPreconfiguredWebhook(
def label, def description, def type, def permissions) {
def customHeaders = new HttpHeaders()
Expand Down

0 comments on commit ccddb75

Please sign in to comment.