Search in sources :

Example 21 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class ServiceController method list.

/**
 * List all service names.
 *
 * @param request http request
 * @return all service names
 * @throws Exception exception
 */
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public ObjectNode list(HttpServletRequest request) throws Exception {
    final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
    final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
    String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
    String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
    String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    Collection<String> serviceNameList = getServiceOperator().listService(namespaceId, groupName, selectorString);
    result.put("count", serviceNameList.size());
    result.replace("doms", JacksonUtils.transferToJsonNode(ServiceUtil.pageServiceName(pageNo, pageSize, serviceNameList)));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 22 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class ServiceControllerV2 method update.

/**
 * Update service.
 *
 * @param namespaceId      namespace id
 * @param serviceName      service name
 * @param protectThreshold protect threshold
 * @param metadata         service metadata
 * @param selector         selector
 * @return 'ok' if success
 * @throws Exception exception
 */
@PutMapping(value = "/{serviceName}")
@Secured(action = ActionTypes.WRITE)
public RestResult<String> update(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
    ServiceMetadata serviceMetadata = new ServiceMetadata();
    serviceMetadata.setProtectThreshold(protectThreshold);
    serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
    serviceMetadata.setSelector(parseSelector(selector));
    Service service = Service.newService(namespaceId, groupName, serviceName);
    serviceOperatorV2.update(service, serviceMetadata);
    return RestResultUtils.success("ok");
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) Secured(com.alibaba.nacos.auth.annotation.Secured) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 23 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class ServiceControllerV2 method create.

/**
 * Create a new service. This API will create a persistence service.
 *
 * @param namespaceId      namespace id
 * @param serviceName      service name
 * @param protectThreshold protect threshold
 * @param metadata         service metadata
 * @param selector         selector
 * @return 'ok' if success
 * @throws Exception exception
 */
@PostMapping(value = "/{serviceName}")
@Secured(action = ActionTypes.WRITE)
public RestResult<String> create(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @PathVariable String serviceName, @RequestParam(defaultValue = Constants.DEFAULT_GROUP) String groupName, @RequestParam(required = false, defaultValue = "false") boolean ephemeral, @RequestParam(required = false, defaultValue = "0.0F") float protectThreshold, @RequestParam(defaultValue = StringUtils.EMPTY) String metadata, @RequestParam(defaultValue = StringUtils.EMPTY) String selector) throws Exception {
    ServiceMetadata serviceMetadata = new ServiceMetadata();
    serviceMetadata.setProtectThreshold(protectThreshold);
    serviceMetadata.setSelector(parseSelector(selector));
    serviceMetadata.setExtendData(UtilsAndCommons.parseMetadata(metadata));
    serviceMetadata.setEphemeral(ephemeral);
    serviceOperatorV2.create(Service.newService(namespaceId, groupName, serviceName, ephemeral), serviceMetadata);
    return RestResultUtils.success("ok");
}
Also used : ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) PostMapping(org.springframework.web.bind.annotation.PostMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 24 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class UpgradeOpsController method deregisterInstance.

/**
 * Deregister instances.
 *
 * @param request http request
 * @return 'ok' if success
 * @throws Exception any error during deregister
 */
@CanDistro
@DeleteMapping("/instance")
@Secured(action = ActionTypes.WRITE)
public String deregisterInstance(@RequestParam(defaultValue = "v2", required = false) String ver, HttpServletRequest request) throws Exception {
    Instance instance = HttpRequestInstanceBuilder.newBuilder().setDefaultInstanceEphemeral(switchDomain.isDefaultInstanceEphemeral()).setRequest(request).build();
    String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
    String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
    NamingUtils.checkServiceNameFormat(serviceName);
    getInstanceOperator(ver).removeInstance(namespaceId, serviceName, instance);
    return "ok";
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Secured(com.alibaba.nacos.auth.annotation.Secured) CanDistro(com.alibaba.nacos.naming.web.CanDistro)

Example 25 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class UpgradeOpsController method listService.

/**
 * List all service names.
 *
 * @param request http request
 * @return all service names
 * @throws Exception exception
 */
@GetMapping("/service/list")
@Secured(action = ActionTypes.READ)
public ObjectNode listService(@RequestParam(defaultValue = "v2", required = false) String ver, HttpServletRequest request) throws Exception {
    final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
    final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
    String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
    String groupName = WebUtils.optional(request, CommonParams.GROUP_NAME, Constants.DEFAULT_GROUP);
    String selectorString = WebUtils.optional(request, "selector", StringUtils.EMPTY);
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    Collection<String> serviceNameList = getServiceOperator(ver).listService(namespaceId, groupName, selectorString);
    result.put("count", serviceNameList.size());
    result.replace("doms", JacksonUtils.transferToJsonNode(ServiceUtil.pageServiceName(pageNo, pageSize, serviceNameList)));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Aggregations

Secured (com.alibaba.nacos.auth.annotation.Secured)104 Resource (com.alibaba.nacos.plugin.auth.api.Resource)34 Test (org.junit.Test)32 GetMapping (org.springframework.web.bind.annotation.GetMapping)20 CanDistro (com.alibaba.nacos.naming.web.CanDistro)17 Instance (com.alibaba.nacos.api.naming.pojo.Instance)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 PostMapping (org.springframework.web.bind.annotation.PostMapping)13 PutMapping (org.springframework.web.bind.annotation.PutMapping)13 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)12 ConfigDataChangeEvent (com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent)10 Timestamp (java.sql.Timestamp)10 NacosException (com.alibaba.nacos.api.exception.NacosException)8 AbstractNamingRequest (com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest)8 Request (com.alibaba.nacos.api.remote.request.Request)8 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)8 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)7 ConfigBatchListenRequest (com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest)6 HashMap (java.util.HashMap)6 ConfigAllInfo (com.alibaba.nacos.config.server.model.ConfigAllInfo)5