peacewong commented on code in PR #3257: URL: https://github.com/apache/incubator-linkis/pull/3257#discussion_r973841197
########## linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/TenantData.scala: ########## @@ -0,0 +1,98 @@ +/* + * 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.linkis.entrance.interceptor.impl + +import org.apache.linkis.common.conf.Configuration +import org.apache.linkis.common.log.LogUtils +import org.apache.linkis.common.utils.Logging +import org.apache.linkis.entrance.exception.EntranceErrorCode +import org.apache.linkis.entrance.interceptor.exception.SetTenantLabelException +import org.apache.linkis.governance.common.entity.job.JobRequest +import org.apache.linkis.governance.common.protocol.conf.{TenantRequest, TenantResponse} +import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext +import org.apache.linkis.manager.label.constant.LabelKeyConstant +import org.apache.linkis.manager.label.entity.TenantLabel +import org.apache.linkis.manager.label.utils.LabelUtil +import org.apache.linkis.rpc.Sender + +import org.apache.commons.lang3.StringUtils + +import java.{lang, util} +import java.util.concurrent.TimeUnit + +import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache} + +object TenantData extends Logging { + + private val configCache: LoadingCache[String, String] = CacheBuilder + .newBuilder() + .maximumSize(1000) + .expireAfterAccess(1, TimeUnit.MINUTES) Review Comment: access replace to expireAfterWrite, using conf ########## linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/TenantConfigrationRestfulApi.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.linkis.configuration.restful.api; + +import io.swagger.annotations.Api; +import org.apache.linkis.common.conf.Configuration; +import org.apache.linkis.configuration.entity.TenantVo; +import org.apache.linkis.configuration.service.TenantConfigService; +import org.apache.linkis.server.Message; +import org.apache.linkis.server.utils.ModuleUserUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@Api(tags = "tenant label configuration") +@RestController +@RequestMapping(path = "/configuration/tenantConfig") +public class TenantConfigrationRestfulApi { + + private static final Logger logger = LoggerFactory.getLogger(TenantConfigrationRestfulApi.class); + + @Autowired + private TenantConfigService tenantConfigService; + + @RequestMapping(path = "/createTenant", method = RequestMethod.POST) + public Message createTenant(HttpServletRequest req, @RequestBody TenantVo tenantVo) { + String userName = ModuleUserUtils.getOperationUser(req, "createTenant"); + if (!Configuration.isAdmin(userName)) { + return Message.error("Only administrators can configure "); + } + return tenantConfigService.createTenant(tenantVo); + } + + @RequestMapping(path = "/updateTenant", method = RequestMethod.POST) + public Message updateTenant(HttpServletRequest req, @RequestBody TenantVo tenantVo) { + String userName = ModuleUserUtils.getOperationUser(req, "updateTenant"); + if (!Configuration.isAdmin(userName)) { + return Message.error("Only administrators can configure "); Review Comment: These exceptions need to be modified ########## linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserIpData.scala: ########## @@ -0,0 +1,92 @@ +/* + * 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.linkis.entrance.interceptor.impl + +import org.apache.linkis.common.conf.Configuration +import org.apache.linkis.common.utils.Logging +import org.apache.linkis.entrance.conf.EntranceConfiguration +import org.apache.linkis.entrance.exception.EntranceErrorCode +import org.apache.linkis.entrance.interceptor.exception.UserCreatorIPCheckException +import org.apache.linkis.governance.common.entity.job.JobRequest +import org.apache.linkis.governance.common.protocol.conf.{UserIpRequest, UserIpResponse} +import org.apache.linkis.manager.label.utils.LabelUtil +import org.apache.linkis.protocol.constants.TaskConstant +import org.apache.linkis.rpc.Sender + +import org.apache.commons.lang3.StringUtils + +import java.lang +import java.util.concurrent.TimeUnit + +import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache} + +object UserIpData extends Logging { + + private val configCache: LoadingCache[String, String] = CacheBuilder + .newBuilder() + .maximumSize(1000) + .expireAfterAccess(1, TimeUnit.MINUTES) Review Comment: access replace to expireAfterWrite, using conf ########## linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserIpData.scala: ########## @@ -0,0 +1,92 @@ +/* + * 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.linkis.entrance.interceptor.impl + +import org.apache.linkis.common.conf.Configuration +import org.apache.linkis.common.utils.Logging +import org.apache.linkis.entrance.conf.EntranceConfiguration +import org.apache.linkis.entrance.exception.EntranceErrorCode +import org.apache.linkis.entrance.interceptor.exception.UserCreatorIPCheckException +import org.apache.linkis.governance.common.entity.job.JobRequest +import org.apache.linkis.governance.common.protocol.conf.{UserIpRequest, UserIpResponse} +import org.apache.linkis.manager.label.utils.LabelUtil +import org.apache.linkis.protocol.constants.TaskConstant +import org.apache.linkis.rpc.Sender + +import org.apache.commons.lang3.StringUtils + +import java.lang +import java.util.concurrent.TimeUnit + +import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache} + +object UserIpData extends Logging { Review Comment: Rename toUserCreatorIPCheckUtils ########## linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.linkis.configuration.service.impl; + +import org.apache.linkis.configuration.dao.TenantMapper; +import org.apache.linkis.configuration.entity.TenantVo; +import org.apache.linkis.configuration.exception.ConfigurationException; +import org.apache.linkis.configuration.service.TenantConfigService; +import org.apache.linkis.configuration.util.HttpsUtil; +import org.apache.linkis.server.Message; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Service +public class TenantConfigServiceImpl implements TenantConfigService { + + private static final Logger logger = LoggerFactory.getLogger(TenantConfigServiceImpl.class); + + @Autowired private TenantMapper tenantMapper; + + /** + * * 查询tenant配置表 + * + * @return List<TenantVo> + * @param user + * @param creator + * @param tenant + */ + @Override + public List<TenantVo> queryTenantList(String user, String creator, String tenant) { + if (StringUtils.isBlank(user)) user = null; + if (StringUtils.isBlank(creator)) creator = null; + if (StringUtils.isBlank(tenant)) tenant = null; + return tenantMapper.queryTenantList(user, creator, tenant); + } + + /** + * 根据id删除tenant + * + * @param id + */ + @Override + public void deleteTenant(Integer id) { + tenantMapper.deleteTenant(id); + } + + /** + * * 更新tenant + * + * @param tenantVo + */ + @Override + public Message updateTenant(TenantVo tenantVo) { + try { Review Comment: need add log ########## linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.linkis.configuration.service.impl; + +import org.apache.linkis.configuration.dao.TenantMapper; +import org.apache.linkis.configuration.entity.TenantVo; +import org.apache.linkis.configuration.exception.ConfigurationException; +import org.apache.linkis.configuration.service.TenantConfigService; +import org.apache.linkis.configuration.util.HttpsUtil; +import org.apache.linkis.server.Message; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Service +public class TenantConfigServiceImpl implements TenantConfigService { + + private static final Logger logger = LoggerFactory.getLogger(TenantConfigServiceImpl.class); + + @Autowired private TenantMapper tenantMapper; + + /** + * * 查询tenant配置表 + * + * @return List<TenantVo> + * @param user + * @param creator + * @param tenant + */ + @Override + public List<TenantVo> queryTenantList(String user, String creator, String tenant) { + if (StringUtils.isBlank(user)) user = null; + if (StringUtils.isBlank(creator)) creator = null; + if (StringUtils.isBlank(tenant)) tenant = null; + return tenantMapper.queryTenantList(user, creator, tenant); Review Comment: If all parameters are empty, throw an exception ########## linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.linkis.configuration.service.impl; + +import org.apache.linkis.configuration.dao.TenantMapper; +import org.apache.linkis.configuration.entity.TenantVo; +import org.apache.linkis.configuration.exception.ConfigurationException; +import org.apache.linkis.configuration.service.TenantConfigService; +import org.apache.linkis.configuration.util.HttpsUtil; +import org.apache.linkis.server.Message; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.StringUtils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Service +public class TenantConfigServiceImpl implements TenantConfigService { + + private static final Logger logger = LoggerFactory.getLogger(TenantConfigServiceImpl.class); + + @Autowired private TenantMapper tenantMapper; + + /** + * * 查询tenant配置表 + * + * @return List<TenantVo> + * @param user + * @param creator + * @param tenant + */ + @Override + public List<TenantVo> queryTenantList(String user, String creator, String tenant) { + if (StringUtils.isBlank(user)) user = null; + if (StringUtils.isBlank(creator)) creator = null; + if (StringUtils.isBlank(tenant)) tenant = null; + return tenantMapper.queryTenantList(user, creator, tenant); + } + + /** + * 根据id删除tenant + * + * @param id + */ + @Override + public void deleteTenant(Integer id) { + tenantMapper.deleteTenant(id); Review Comment: need add log ########## linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java: ########## @@ -30,6 +29,12 @@ public class ConfigurationConfiguration { public static final String COPYKEYTOKEN = CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token", "e8724-e").getValue(); + public static final String IPCHECK = + CommonVars$.MODULE$ + .apply( + "wds.linkis.configuration.ipcheck.pattern", Review Comment: wds can remove -- 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: notifications-unsubscr...@linkis.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@linkis.apache.org For additional commands, e-mail: notifications-h...@linkis.apache.org