use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class AssetREST method createXResource.
@POST
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResource createXResource(VXResource vXResource) {
if (logger.isDebugEnabled()) {
logger.debug("==> AssetREST.createXResource(" + vXResource + ")");
}
RangerService service = serviceREST.getService(vXResource.getAssetId());
RangerPolicy policy = serviceUtil.toRangerPolicy(vXResource, service);
RangerPolicy createdPolicy = serviceREST.createPolicy(policy, null);
VXResource ret = serviceUtil.toVXResource(createdPolicy, service);
if (logger.isDebugEnabled()) {
logger.debug("<== AssetREST.createXResource(" + vXResource + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class PublicAPIs method getPolicy.
@GET
@Path("/api/policy/{id}")
@Produces({ "application/json", "application/xml" })
public VXPolicy getPolicy(@PathParam("id") Long id) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.getPolicy() " + id);
}
RangerPolicy policy = null;
RangerService service = null;
policy = serviceREST.getPolicy(id);
if (policy != null) {
service = serviceREST.getServiceByName(policy.getService());
}
VXPolicy ret = serviceUtil.toVXPolicy(policy, service);
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.getPolicy()" + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class PublicAPIs method createPolicy.
@POST
@Path("/api/policy")
@Produces({ "application/json", "application/xml" })
public VXPolicy createPolicy(VXPolicy vXPolicy) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.createPolicy()");
}
RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName());
RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy, service);
VXPolicy ret = null;
if (policy != null) {
if (logger.isDebugEnabled()) {
logger.debug("RANGERPOLICY: " + policy.toString());
}
RangerPolicy createdPolicy = serviceREST.createPolicy(policy, null);
ret = serviceUtil.toVXPolicy(createdPolicy, service);
}
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.createPolicy(" + policy + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class PublicAPIs method updatePolicy.
@PUT
@Path("/api/policy/{id}")
@Produces({ "application/json", "application/xml" })
public VXPolicy updatePolicy(VXPolicy vXPolicy, @PathParam("id") Long id) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.updatePolicy(): " + vXPolicy);
}
XXPolicy existing = daoMgr.getXXPolicy().getById(id);
if (existing == null) {
throw restErrorUtil.createRESTException("Policy not found for Id: " + id, MessageEnums.DATA_NOT_FOUND);
}
vXPolicy.setId(id);
RangerService service = serviceREST.getServiceByName(vXPolicy.getRepositoryName());
RangerPolicy policy = serviceUtil.toRangerPolicy(vXPolicy, service);
VXPolicy ret = null;
if (policy != null) {
policy.setVersion(existing.getVersion());
RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy);
ret = serviceUtil.toVXPolicy(updatedPolicy, service);
}
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.updatePolicy(" + policy + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy in project ranger by apache.
the class PublicAPIs method searchPolicies.
@GET
@Path("/api/policy")
@Produces({ "application/json", "application/xml" })
public VXPolicyList searchPolicies(@Context HttpServletRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.searchPolicies(): ");
}
SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields);
// get all policies from the store; pick the page to return after applying filter
int savedStartIndex = filter.getStartIndex();
int savedMaxRows = filter.getMaxRows();
filter.setStartIndex(0);
filter.setMaxRows(Integer.MAX_VALUE);
List<RangerPolicy> rangerPolicyList = serviceREST.getPolicies(filter);
filter.setStartIndex(savedStartIndex);
filter.setMaxRows(savedMaxRows);
VXPolicyList vXPolicyList = null;
if (rangerPolicyList != null) {
vXPolicyList = serviceUtil.rangerPolicyListToPublic(rangerPolicyList, filter);
}
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.searchPolicies(): " + vXPolicyList);
}
return vXPolicyList;
}
Aggregations