Skip to content

Commit

Permalink
PluginInfo V3 will now render plugin setting configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ketan committed Jul 3, 2017
1 parent f6e0459 commit 19b3e9c
Show file tree
Hide file tree
Showing 108 changed files with 2,257 additions and 570 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 ThoughtWorks, Inc.
* Copyright 2017 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,7 +106,7 @@ public void addConfigurations_shouldAddConfigurationsWithEncryptedValue() throws
@Test
public void addConfiguration_shouldEncryptASecureVariable() throws Exception {
PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))));
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null);
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null);

store.setPluginInfo(pluginInfo);
ElasticProfile profile = new ElasticProfile("id", "plugin_id");
Expand All @@ -118,7 +118,7 @@ public void addConfiguration_shouldEncryptASecureVariable() throws Exception {

@Test
public void addConfiguration_shouldIgnoreEncryptionInAbsenceOfCorrespondingConfigurationInStore() throws Exception {
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), new PluggableInstanceSettings(new ArrayList<>()), null);
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), new PluggableInstanceSettings(new ArrayList<>()), null, null);

store.setPluginInfo(pluginInfo);
ElasticProfile profile = new ElasticProfile("id", "plugin_id");
Expand All @@ -132,7 +132,7 @@ public void addConfiguration_shouldIgnoreEncryptionInAbsenceOfCorrespondingConfi
@Test
public void postConstruct_shouldEncryptSecureConfigurations() throws Exception {
PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))));
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null);
ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null);

store.setPluginInfo(pluginInfo);
ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017 ThoughtWorks, 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.thoughtworks.go.plugin.access.authentication;

import com.thoughtworks.go.plugin.access.common.MetadataLoader;
import com.thoughtworks.go.plugin.domain.authentication.AuthenticationPluginInfo;
import com.thoughtworks.go.plugin.infra.PluginManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Deprecated
@Component
public class AuthenticationMetadataLoader extends MetadataLoader<AuthenticationPluginInfo> {
@Autowired
public AuthenticationMetadataLoader(PluginManager pluginManager, AuthenticationPluginInfoBuilder builder, AuthenticationExtension extension) {
this(pluginManager, AuthenticationMetadataStore.instance(), builder, extension);
}

protected AuthenticationMetadataLoader(PluginManager pluginManager, AuthenticationMetadataStore metadataStore, AuthenticationPluginInfoBuilder builder, AuthenticationExtension extension) {
super(pluginManager, builder, metadataStore, extension);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2017 ThoughtWorks, 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.thoughtworks.go.plugin.access.authentication;

import com.thoughtworks.go.plugin.access.authentication.models.AuthenticationPluginConfiguration;
import com.thoughtworks.go.plugin.access.common.PluginInfoBuilder;
import com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration;
import com.thoughtworks.go.plugin.domain.authentication.AuthenticationPluginInfo;
import com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings;
import com.thoughtworks.go.plugin.domain.common.PluginView;
import com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Deprecated
@Component
public class AuthenticationPluginInfoBuilder implements PluginInfoBuilder<AuthenticationPluginInfo> {

private AuthenticationExtension extension;

@Autowired
public AuthenticationPluginInfoBuilder(AuthenticationExtension extension) {
this.extension = extension;
}

public AuthenticationPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
PluginSettingsConfiguration pluginSettingsConfiguration = extension.getPluginSettingsConfiguration(descriptor.id());
String pluginSettingsView = extension.getPluginSettingsView(descriptor.id());
AuthenticationPluginConfiguration pluginConfiguration = extension.getPluginConfiguration(descriptor.id());

PluggableInstanceSettings pluggableInstanceSettings = new PluggableInstanceSettings(configurations(pluginSettingsConfiguration), new PluginView(pluginSettingsView));
return new AuthenticationPluginInfo(descriptor,
pluginConfiguration.getDisplayName(),
pluginConfiguration.getDisplayImageURL(),
pluginConfiguration.supportsPasswordBasedAuthentication(),
pluginConfiguration.supportsWebBasedAuthentication(),
pluggableInstanceSettings);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse;
import com.thoughtworks.go.plugin.access.authorization.models.Capabilities;
import com.thoughtworks.go.plugin.access.common.handler.JSONResultMessageHandler;
import com.thoughtworks.go.plugin.access.common.models.Image;
import com.thoughtworks.go.plugin.access.common.models.ImageDeserializer;
import com.thoughtworks.go.plugin.access.common.models.PluginProfileMetadataKeys;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
import com.thoughtworks.go.plugin.domain.common.PluginConfiguration;
Expand All @@ -46,7 +46,7 @@ public com.thoughtworks.go.plugin.domain.authorization.Capabilities getCapabilit

@Override
public com.thoughtworks.go.plugin.domain.common.Image getImageResponseFromBody(String responseBody) {
return Image.fromJSON(responseBody).toDomainImage();
return new ImageDeserializer().fromJSON(responseBody);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
import com.thoughtworks.go.plugin.domain.authorization.Capabilities;
import com.thoughtworks.go.plugin.domain.common.Image;
import com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings;
import com.thoughtworks.go.plugin.domain.common.PluginConfiguration;
import com.thoughtworks.go.plugin.domain.common.PluginView;
import com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AuthorizationPluginInfoBuilder implements PluginInfoBuilder<AuthorizationPluginInfo> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@

package com.thoughtworks.go.plugin.access.common;

import com.thoughtworks.go.plugin.api.config.Configuration;
import com.thoughtworks.go.plugin.api.config.Property;
import com.thoughtworks.go.plugin.domain.common.Metadata;
import com.thoughtworks.go.plugin.domain.common.PluginConfiguration;
import com.thoughtworks.go.plugin.domain.common.PluginInfo;
import com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor;

import java.util.ArrayList;
import java.util.List;

public interface PluginInfoBuilder<T extends PluginInfo> {
T pluginInfoFor(GoPluginDescriptor descriptor);

default List<PluginConfiguration> configurations(Configuration config) {
ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();

for (Property property : config.list()) {
Metadata metadata = new Metadata(property.getOption(Property.REQUIRED), property.getOption(Property.SECURE));
pluginConfigurations.add(new PluginConfiguration(property.getKey(), metadata));
}
return pluginConfigurations;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 ThoughtWorks, Inc.
* Copyright 2017 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@

import java.util.Base64;

@Deprecated
public class Image {
private static final Gson GSON = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

Expand Down Expand Up @@ -79,10 +80,6 @@ public static Image fromJSON(String responseData) {
return GSON.fromJson(responseData, Image.class);
}

public com.thoughtworks.go.plugin.domain.common.Image toDomainImage() {
return new com.thoughtworks.go.plugin.domain.common.Image(this.contentType, this.data, getHash());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2017 ThoughtWorks, 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.thoughtworks.go.plugin.access.common.models;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.Map;

import static org.apache.commons.codec.digest.DigestUtils.sha256Hex;

public class ImageDeserializer {

public com.thoughtworks.go.plugin.domain.common.Image fromJSON(String jsonString) {
Map<String, String> json = new Gson().fromJson(jsonString, new TypeToken<Map<String, String>>() {
}.getType());
String contentType = json.get("content_type");
String data = json.get("data");
return new com.thoughtworks.go.plugin.domain.common.Image(contentType, data, hash(contentType, data));
}

private String hash(String contentType, String data) {
return sha256Hex("data:" + contentType + ";base64," + data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017 ThoughtWorks, 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.thoughtworks.go.plugin.access.configrepo;

import com.thoughtworks.go.plugin.access.common.MetadataLoader;
import com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo;
import com.thoughtworks.go.plugin.infra.PluginManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ConfigRepoMetadataLoader extends MetadataLoader<ConfigRepoPluginInfo> {
@Autowired
public ConfigRepoMetadataLoader(PluginManager pluginManager, ConfigRepoPluginInfoBuilder builder, ConfigRepoExtension extension) {
this(pluginManager, ConfigRepoMetadataStore.instance(), builder, extension);
}

protected ConfigRepoMetadataLoader(PluginManager pluginManager, ConfigRepoMetadataStore metadataStore, ConfigRepoPluginInfoBuilder builder, ConfigRepoExtension extension) {
super(pluginManager, builder, metadataStore, extension);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2017 ThoughtWorks, 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.thoughtworks.go.plugin.access.configrepo;

import com.thoughtworks.go.plugin.access.common.PluginInfoBuilder;
import com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration;
import com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings;
import com.thoughtworks.go.plugin.domain.common.PluginView;
import com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo;
import com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ConfigRepoPluginInfoBuilder implements PluginInfoBuilder<ConfigRepoPluginInfo> {

private ConfigRepoExtension extension;

@Autowired
public ConfigRepoPluginInfoBuilder(ConfigRepoExtension extension) {
this.extension = extension;
}

public ConfigRepoPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
PluginSettingsConfiguration pluginSettingsConfiguration = extension.getPluginSettingsConfiguration(descriptor.id());
String pluginSettingsView = extension.getPluginSettingsView(descriptor.id());
PluggableInstanceSettings pluginSettings = new PluggableInstanceSettings(configurations(pluginSettingsConfiguration), new PluginView(pluginSettingsView));

return new ConfigRepoPluginInfo(descriptor, pluginSettings);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.thoughtworks.go.plugin.access.common.handler.JSONResultMessageHandler;
import com.thoughtworks.go.plugin.access.common.models.Image;
import com.thoughtworks.go.plugin.access.common.models.ImageDeserializer;
import com.thoughtworks.go.plugin.access.common.models.PluginProfileMetadataKeys;
import com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
Expand All @@ -33,12 +33,12 @@
import java.util.Map;

public class ElasticAgentExtensionConverterV1 implements ElasticAgentMessageConverter {
private static final Gson GSON = new Gson();

public static final String VERSION = "1.0";

@Override
public String createAgentRequestBody(String autoRegisterKey, String environment, Map<String, String> configuration) {
Gson gson = new Gson();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("auto_register_key", autoRegisterKey);
JsonObject properties = new JsonObject();
Expand All @@ -47,12 +47,11 @@ public String createAgentRequestBody(String autoRegisterKey, String environment,
}
jsonObject.add("properties", properties);
jsonObject.addProperty("environment", environment);
return gson.toJson(jsonObject);
return GSON.toJson(jsonObject);
}

@Override
public String shouldAssignWorkRequestBody(AgentMetadata elasticAgent, String environment, Map<String, String> configuration) {
Gson gson = new Gson();
JsonObject jsonObject = new JsonObject();
JsonObject properties = new JsonObject();
for (Map.Entry<String, String> entry : configuration.entrySet()) {
Expand All @@ -61,7 +60,7 @@ public String shouldAssignWorkRequestBody(AgentMetadata elasticAgent, String env
jsonObject.add("properties", properties);
jsonObject.addProperty("environment", environment);
jsonObject.add("agent", elasticAgent.toJSON());
return gson.toJson(jsonObject);
return GSON.toJson(jsonObject);
}

@Override
Expand Down Expand Up @@ -98,7 +97,7 @@ public String getProfileViewResponseFromBody(String responseBody) {

@Override
public com.thoughtworks.go.plugin.domain.common.Image getImageResponseFromBody(String responseBody) {
return Image.fromJSON(responseBody).toDomainImage();
return new ImageDeserializer().fromJSON(responseBody);
}

@Override
Expand Down

0 comments on commit 19b3e9c

Please sign in to comment.