Skip to content

Commit

Permalink
fix(plugins): fix plugins-manifest.json (spinnaker#1564)
Browse files Browse the repository at this point in the history
* fix(plugins): changing plugin-manifest.js to .json file type

* fix(plugins): remove comments from json file, handle multiple plugins
  • Loading branch information
link108 authored and cmuraru committed Jun 23, 2020
1 parent 7f5b8bc commit d1a70ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,48 @@
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.StringBackedProfileFactory;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PluginManifestProfileFactory extends StringBackedProfileFactory {
@Autowired PluginService pluginService;

private static String PLUGIN_ENTRY = "{id: \"%s\", version: \"%s\", url: \"%s\"}";
private static String PLUGIN_ENTRY = "{\"id\": \"%s\", \"version\": \"%s\", \"url\": \"%s\"}";

@Override
protected boolean showEditWarning() {
return false;
}

@Override
protected void setProfile(
Profile profile,
DeploymentConfiguration deploymentConfiguration,
SpinnakerRuntimeSettings endpoints) {
profile.appendContents("plugins = [");
profile.appendContents("[");

Map<String, Plugin> plugins = pluginService.getPlugins(deploymentConfiguration.getName());
plugins.entrySet().stream()
.filter(
v -> {
Plugin p = v.getValue();
return p.getEnabled()
&& p.getUiResourceLocation() != null
&& p.getUiResourceLocation() != "";
})
.forEach(
v -> {
Plugin p = v.getValue();
profile.appendContents(
String.format(
PLUGIN_ENTRY, p.getId(), p.getVersion(), p.getUiResourceLocation()));
});
List<String> contents =
plugins.entrySet().stream()
.filter(
v -> {
Plugin p = v.getValue();
return p.getEnabled()
&& p.getUiResourceLocation() != null
&& p.getUiResourceLocation() != "";
})
.map(
v -> {
Plugin p = v.getValue();
return String.format(
PLUGIN_ENTRY, p.getId(), p.getVersion(), p.getUiResourceLocation());
})
.collect(Collectors.toList());
profile.appendContents(String.join(",", contents));
profile.appendContents("]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<Profile> getProfiles(
result.add(
deckDockerProfileFactory.getProfile(settingsJs, path, deploymentConfiguration, endpoints));

String filename = "plugin-manifest.js";
String filename = "plugin-manifest.json";
path = Paths.get(settingsPath, filename).toString();
result.add(
pluginManifestProfileFactory.getProfile(
Expand Down

0 comments on commit d1a70ab

Please sign in to comment.