gerlowskija commented on code in PR #955:
URL: https://github.com/apache/solr/pull/955#discussion_r935970495


##########
solr/core/src/java/org/apache/solr/handler/configsets/CreateConfigSetAPI.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.solr.handler.configsets;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.solr.api.Command;
+import org.apache.solr.api.EndPoint;
+import org.apache.solr.api.PayloadObj;
+import org.apache.solr.client.solrj.request.beans.CreateConfigPayload;
+import org.apache.solr.cloud.ConfigSetCmds;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ConfigSetParams;
+import org.apache.solr.core.CoreContainer;
+
+import java.util.Map;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
+import static org.apache.solr.common.params.CommonParams.NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DISABLE_CREATE_AUTH_CHECKS;
+import static 
org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
+
+/**
+ * V2 API for creating a new configset as a copy of an existing one.
+ *
+ * <p>This API (POST /v2/cluster/configs {"create": {...}}) is analogous to
+ * the v1 /admin/configs?action=CREATE command.
+ *
+ */
+@EndPoint(method = POST, path = "/cluster/configs", permission = 
CONFIG_EDIT_PERM)
+public class CreateConfigSetAPI extends ConfigSetAPIBase {
+
+    public CreateConfigSetAPI(CoreContainer coreContainer) {
+        super(coreContainer);
+    }
+
+    @Command(name = "create")
+    @SuppressWarnings("unchecked")
+    public void create(PayloadObj<CreateConfigPayload> obj) throws Exception {
+        final CreateConfigPayload createConfigPayload = obj.get();
+        final String baseConfigSetName = (createConfigPayload.baseConfigSet != 
null) ? createConfigPayload.baseConfigSet : DEFAULT_CONFIGSET_NAME;
+        if (configSetService.checkConfigExists(createConfigPayload.name)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.BAD_REQUEST, "ConfigSet already 
exists: " + createConfigPayload.name);
+        }
+
+        // is there a base config that already exists
+        if (! configSetService.checkConfigExists(baseConfigSetName)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.BAD_REQUEST, "Base ConfigSet does 
not exist: " + baseConfigSetName);
+        }
+
+        if (!DISABLE_CREATE_AUTH_CHECKS
+                && !isTrusted(obj.getRequest().getUserPrincipal(), 
coreContainer.getAuthenticationPlugin())
+                && isCurrentlyTrusted(baseConfigSetName)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.UNAUTHORIZED,
+                    "Can't create a configset with an unauthenticated request 
from a trusted "
+                            + ConfigSetCmds.BASE_CONFIGSET);
+        }
+
+        final Map<String, Object> configsetCommandMsg = Maps.newHashMap();

Review Comment:
   I agree on both counts: (1) I'm not sure whether we really need the overseer 
to do this work, and (2) if we do it'd be awesome to send those messages as 
strongly typed objects.  No reason to keep dealing with everything as a map.
   
   I'm leery of getting into that with this PR or effort though - the v2 API 
effort is already daunting without stopping to fix or reimplement the guts of 
individual APIs, no matter how much they deserve it.  (And this one does for 
sure)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to