-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): Add new plugin trigger type (#884)
- Loading branch information
1 parent
46127ea
commit 669a9f3
Showing
3 changed files
with
143 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
echo-model/src/main/java/com/netflix/spinnaker/echo/model/trigger/PluginEvent.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 2020 Netflix, 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.model.trigger; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class PluginEvent extends TriggerEvent { | ||
public static final String TYPE = "plugin"; | ||
|
||
private Content content; | ||
|
||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static class Content { | ||
private String pluginId; | ||
private String version; | ||
private String releaseDate; | ||
private List<Map<String, String>> requires; | ||
private String binaryUrl; | ||
private boolean preferred; | ||
private String lastModified; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...in/java/com/netflix/spinnaker/echo/pipelinetriggers/eventhandlers/PluginEventHandler.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,90 @@ | ||
/* | ||
* Copyright 2020 Netflix, 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.PluginEvent; | ||
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; | ||
|
||
@Component | ||
public class PluginEventHandler extends BaseTriggerEventHandler<PluginEvent> { | ||
|
||
private static final String PLUGIN_TRIGGER_TYPE = "plugin"; | ||
private static final List<String> SUPPORTED_TYPES = | ||
Collections.singletonList(PLUGIN_TRIGGER_TYPE); | ||
|
||
public PluginEventHandler( | ||
Registry registry, | ||
ObjectMapper objectMapper, | ||
FiatPermissionEvaluator fiatPermissionEvaluator) { | ||
super(registry, objectMapper, fiatPermissionEvaluator); | ||
} | ||
|
||
@Override | ||
protected Predicate<Trigger> matchTriggerFor(PluginEvent event) { | ||
return trigger -> trigger.getType().equals(PLUGIN_TRIGGER_TYPE); | ||
} | ||
|
||
@Override | ||
protected Function<Trigger, Trigger> buildTrigger(PluginEvent event) { | ||
return trigger -> | ||
trigger | ||
.toBuilder() | ||
.pluginId(event.getContent().getPluginId()) | ||
.version(event.getContent().getVersion()) | ||
.releaseDate(event.getContent().getReleaseDate()) | ||
.requires(event.getContent().getRequires()) | ||
.binaryUrl(event.getContent().getBinaryUrl()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected boolean isValidTrigger(Trigger trigger) { | ||
return trigger.isEnabled() | ||
&& trigger.getType().equals(PLUGIN_TRIGGER_TYPE) | ||
&& trigger.isPreferred(); | ||
} | ||
|
||
@Override | ||
protected Class<PluginEvent> getEventType() { | ||
return PluginEvent.class; | ||
} | ||
|
||
@Override | ||
protected List<Artifact> getArtifactsFromEvent(PluginEvent event, Trigger trigger) { | ||
// TODO(rz): Add artifact support someday | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public List<String> supportedTriggerTypes() { | ||
return SUPPORTED_TYPES; | ||
} | ||
|
||
@Override | ||
public boolean handleEventType(String eventType) { | ||
return eventType.equalsIgnoreCase(PluginEvent.TYPE); | ||
} | ||
} |