use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class AssetREST method updateXAsset.
@PUT
@Path("/assets/{id}")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE_X_ASSET + "\")")
public VXAsset updateXAsset(VXAsset vXAsset) {
if (logger.isDebugEnabled()) {
logger.debug("==> AssetREST.updateXAsset(" + vXAsset + ")");
}
RangerService service = serviceUtil.toRangerService(vXAsset);
RangerService updatedService = serviceREST.updateService(service, null);
VXAsset ret = serviceUtil.toVXAsset(updatedService);
if (logger.isDebugEnabled()) {
logger.debug("<== AssetREST.updateXAsset(" + vXAsset + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class AssetREST method getResourceJSON.
@GET
@Path("/policyList/{repository}")
@Encoded
public String getResourceJSON(@Context HttpServletRequest request, @PathParam("repository") String repository) {
String epoch = request.getParameter("epoch");
X509Certificate[] certchain = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
String ipAddress = request.getHeader("X-FORWARDED-FOR");
boolean isSecure = request.isSecure();
String policyCount = request.getParameter("policyCount");
String agentId = request.getParameter("agentId");
Long lastKnowPolicyVersion = Long.valueOf(-1);
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
boolean httpEnabled = PropertiesUtil.getBooleanProperty("ranger.service.http.enabled", true);
ServicePolicies servicePolicies = null;
try {
servicePolicies = serviceREST.getServicePoliciesIfUpdated(repository, lastKnowPolicyVersion, 0L, agentId, "", request);
} catch (Exception excp) {
logger.error("failed to retrieve policies for repository " + repository, excp);
}
RangerService service = serviceUtil.getServiceByName(repository);
List<RangerPolicy> policies = servicePolicies != null ? servicePolicies.getPolicies() : null;
long policyUpdTime = (servicePolicies != null && servicePolicies.getPolicyUpdateTime() != null) ? servicePolicies.getPolicyUpdateTime().getTime() : 0l;
VXAsset vAsset = serviceUtil.toVXAsset(service);
List<VXResource> vResourceList = new ArrayList<VXResource>();
if (policies != null) {
for (RangerPolicy policy : policies) {
vResourceList.add(serviceUtil.toVXResource(policy, service));
}
}
String file = assetMgr.getLatestRepoPolicy(vAsset, vResourceList, policyUpdTime, certchain, httpEnabled, epoch, ipAddress, isSecure, policyCount, agentId);
return file;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class AssetREST method updateXResource.
@PUT
@Path("/resources/{id}")
@Produces({ "application/xml", "application/json" })
public VXResource updateXResource(VXResource vXResource) {
if (logger.isDebugEnabled()) {
logger.debug("==> AssetREST.updateXResource(" + vXResource + ")");
}
RangerService service = serviceREST.getService(vXResource.getAssetId());
RangerPolicy policy = serviceUtil.toRangerPolicy(vXResource, service);
RangerPolicy updatedPolicy = serviceREST.updatePolicy(policy);
VXResource ret = serviceUtil.toVXResource(updatedPolicy, service);
if (logger.isDebugEnabled()) {
logger.debug("<== AssetREST.updateXResource(" + vXResource + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class AssetREST method searchXAssets.
@GET
@Path("/assets")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_X_ASSETS + "\")")
public VXAssetList searchXAssets(@Context HttpServletRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("==> AssetREST.searchXAssets()");
}
VXAssetList ret = new VXAssetList();
SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequestForRepositorySearch(request, xAssetService.sortFields);
List<RangerService> services = serviceREST.getServices(filter);
if (services != null) {
List<VXAsset> assets = new ArrayList<VXAsset>();
for (RangerService service : services) {
VXAsset asset = serviceUtil.toVXAsset(service);
if (asset != null) {
assets.add(asset);
}
}
ret.setVXAssets(assets);
}
if (logger.isDebugEnabled()) {
logger.debug("<== AssetREST.searchXAssets(): count=" + ret.getListSize());
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.
the class PublicAPIs method updateRepository.
@PUT
@Path("/api/repository/{id}")
@Produces({ "application/json", "application/xml" })
public VXRepository updateRepository(VXRepository vXRepository, @PathParam("id") Long id) {
if (logger.isDebugEnabled()) {
logger.debug("==> PublicAPIs.updateRepository(" + id + ")");
}
XXService existing = daoMgr.getXXService().getById(id);
if (existing == null) {
throw restErrorUtil.createRESTException("Repository not found for Id: " + id, MessageEnums.DATA_NOT_FOUND);
}
vXRepository.setId(id);
VXAsset vXAsset = serviceUtil.publicObjecttoVXAsset(vXRepository);
RangerService service = serviceUtil.toRangerService(vXAsset);
service.setVersion(existing.getVersion());
RangerService updatedService = serviceREST.updateService(service, null);
VXAsset retvXAsset = serviceUtil.toVXAsset(updatedService);
VXRepository ret = serviceUtil.vXAssetToPublicObject(retvXAsset);
if (logger.isDebugEnabled()) {
logger.debug("<== PublicAPIs.updateRepository(" + ret + ")");
}
return ret;
}
Aggregations