com.netflix.spinnaker.echo.pipelinetriggers.eventhandlers.ArtifactoryEventHandler Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2019 Pivotal, 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.echo.pipelinetriggers.eventhandlers;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.echo.model.Trigger;
import com.netflix.spinnaker.echo.model.trigger.ArtifactoryEvent;
import com.netflix.spinnaker.fiat.shared.FiatPermissionEvaluator;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import org.springframework.stereotype.Component;
/**
* Implementation of TriggerEventHandler for events of type {@link ArtifactoryEvent}, which occur
* when an artifact is added/modified in an Artifactory repository.
*/
@Component
public class ArtifactoryEventHandler extends BaseTriggerEventHandler {
private static final String ARTIFACTORY_TRIGGER_TYPE = "artifactory";
private static final List supportedTriggerTypes =
Collections.singletonList(ARTIFACTORY_TRIGGER_TYPE);
public ArtifactoryEventHandler(
Registry registry,
ObjectMapper objectMapper,
FiatPermissionEvaluator fiatPermissionEvaluator) {
super(registry, objectMapper, fiatPermissionEvaluator);
}
@Override
public List supportedTriggerTypes() {
return supportedTriggerTypes;
}
@Override
public boolean handleEventType(String eventType) {
return eventType.equalsIgnoreCase(ArtifactoryEvent.TYPE);
}
@Override
protected Class getEventType() {
return ArtifactoryEvent.class;
}
@Override
protected boolean isValidTrigger(Trigger trigger) {
return trigger.isEnabled()
&& ARTIFACTORY_TRIGGER_TYPE.equals(trigger.getType())
&& trigger.getArtifactorySearchName() != null;
}
@Override
public boolean isSuccessfulTriggerEvent(ArtifactoryEvent event) {
return event != null;
}
@Override
protected Predicate matchTriggerFor(ArtifactoryEvent artifactoryEvent) {
String artifactorySearchName = artifactoryEvent.getContent().getName();
return trigger ->
trigger.getType().equals(ARTIFACTORY_TRIGGER_TYPE)
&& trigger.getArtifactorySearchName().equals(artifactorySearchName);
}
@Override
protected List getArtifactsFromEvent(
ArtifactoryEvent artifactoryEvent, Trigger trigger) {
return artifactoryEvent.getContent() != null
&& artifactoryEvent.getContent().getArtifact() != null
? Collections.singletonList(artifactoryEvent.getContent().getArtifact())
: new ArrayList<>();
}
@Override
protected Function buildTrigger(ArtifactoryEvent event) {
return trigger ->
trigger.atArtifactorySearchName(event.getContent().getName()).atEventId(event.getEventId());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy