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

fix(plugins): plugins should be able to reference their own config values #1444

Merged
merged 4 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -49,7 +49,8 @@ public Map<String, Object> getPluginConfigurations() {
plugins.stream()
.filter(p -> p.getEnabled())
.filter(p -> !p.getManifestLocation().isEmpty())
.collect(Collectors.toMap(p -> p.getName(), p -> p.getCombinedOptions()));
.collect(
Collectors.toMap(p -> p.generateManifest().getName(), p -> p.getCombinedOptions()));

fullyRenderedYaml.put("plugins", pluginMetadata);
return fullyRenderedYaml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
@Data
@EqualsAndHashCode(callSuper = true)
public class Plugin extends Node {
public String name;
public Boolean enabled;
public String manifestLocation;
public Map<String, Object> options = new HashMap<>();
private String name;
private Boolean enabled;
private String manifestLocation;
private Map<String, Object> options = new HashMap<>();

@Override
public String getNodeName() {
Expand Down Expand Up @@ -113,6 +113,6 @@ public static Map<String, Object> merge(
}

public Map<String, Object> getCombinedOptions() {
return Plugin.merge(generateManifest().getOptions(), options);
return Plugin.merge(generateManifest().getOptions(), getOptions());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2019 Armory, 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.halyard.config.model.v1.plugins

import com.netflix.spinnaker.halyard.config.model.v1.node.Plugins
import spock.lang.Specification

class PluginsSpec extends Specification {

void "getPluginConfigurations works correctly"() {
setup:
def plugins = new Plugins()
def plugin = Spy(Plugin)
def manifest = Stub(Manifest)
manifest.name >> 'namespace/name'
manifest.options >> [foo: 'bar']
plugin.manifestLocation >> 'manifest-location'
plugin.enabled >> true
plugin.options >> [cat: 'dog']
plugin.name >> 'should-not-be-present'
plugins.setPlugins([plugin])

plugin.generateManifest() >> manifest

when:
def subject = plugins.getPluginConfigurations()

then:
def expectedOptions = [
plugins: [
'namespace/name': [
foo: 'bar',
cat: 'dog'
]
]
]
subject == expectedOptions
}
}