-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from tmobile/release/1.5
Release/1.5
- Loading branch information
Showing
296 changed files
with
25,586 additions
and
16,983 deletions.
There are no files selected for viewing
207 changes: 105 additions & 102 deletions
207
api/pacman-api-asset/src/main/java/com/tmobile/pacman/api/asset/AssetConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,105 @@ | ||
/******************************************************************************* | ||
* Copyright 2018 T Mobile, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed 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 com.tmobile.pacman.api.asset; | ||
|
||
/** | ||
* Constants class where the asset service constants are stored. | ||
*/ | ||
public final class AssetConstants { | ||
|
||
private AssetConstants() { | ||
|
||
} | ||
|
||
public static final String FILTER_EXEC_SPONSOR = "executiveSponsor"; | ||
public static final String FILTER_RES_TYPE = "resourceType"; | ||
public static final String FILTER_DIRECTOR = "director"; | ||
public static final String FILTER_APPLICATION = "application"; | ||
public static final String FILTER_ENVIRONMENT = "environment"; | ||
public static final String FILTER_PATCHED = "patched"; | ||
public static final String FILTER_TAGGED = "tagged"; | ||
public static final String FILTER_TAGNAME = "tagName"; | ||
public static final String FILTER_RULEID = "ruleId"; | ||
public static final String FILTER_COMPLIANT = "compliant"; | ||
public static final String FILTER_DOMAIN = "domain"; | ||
public static final String TAG_NOT_FOUND = "Not Found"; | ||
public static final String ERROR_FROM_NEGATIVE = "From should not be a negative number"; | ||
public static final String ERROR_FILTER_ACCEPTS = "Filter accepts only "; | ||
public static final String ASSET_COUNT = "assetcount"; | ||
public static final String ERROR_INSTANCEID = "Asset group/Instance Id is Mandatory"; | ||
public static final String ERROR_FROM_EXCEEDS = "From exceeds the size of list"; | ||
public static final String ERROR_QUALYS_NOT_ENABLED = "Qualys not enabled"; | ||
public static final String ASSETS = "Assets"; | ||
public static final int ZERO = 0; | ||
public static final int FIFTEEN = 15; | ||
public static final int TWENTY = 20; | ||
public static final int TWENTY_FIVE = 25; | ||
public static final int THIRTY = 30; | ||
public static final int FORTY = 40; | ||
public static final int FIFTY = 50; | ||
public static final int SIXTY = 60; | ||
public static final int EIGHT = 8; | ||
public static final int NINE = 9; | ||
public static final String UNDERSCORE_ENTITY = "_entity"; | ||
public static final String ALL = "all"; | ||
public static final String STOPPED = "stopped"; | ||
public static final String STOPPING = "stopping"; | ||
public static final String UNDERSCORE_TYPE = "_type"; | ||
public static final String UNDERSCORE_SOURCE = "_source"; | ||
public static final String RECENTLY_VIEWED_AG = "recentlyViewedAg"; | ||
public static final String UNDERSCORE_LOADDATE = "_loaddate"; | ||
public static final String CREATE_TIME = "createtime"; | ||
public static final String FIRST_DISCOVEREDON = "firstdiscoveredon"; | ||
public static final String UNDERSCORE_DISCOVERY_DATE = "_discoverydate"; | ||
public static final String DISCOVERY_DATE = "discoverydate"; | ||
public static final String CREATION_DATE = "creationdate"; | ||
public static final String UNDERSCORE_ENTITY_TYPE_KEYWORD = "_entitytype.keyword"; | ||
public static final String UNDERSCORE_ENTITY_TYPE = "_entitytype"; | ||
public static final String AWS_EC2 = "aws_ec2"; | ||
public static final String INSTANCEID_KEYWORD = "instanceid.keyword"; | ||
public static final String FALSE = "false"; | ||
public static final String ERROR_FETCHING_FIELDNAMES = "Error while fetching field names "; | ||
public static final String SERVICE_NAME = "serviceName"; | ||
public static final String QUERY = "query"; | ||
public static final String POLICY_VIOLATIONS = "Policy Violations"; | ||
public static final String VULNERABILITIES = "Vulnerabilities"; | ||
public static final String PUBLIC_IP_ADDRESS = "publicipaddress"; | ||
public static final String PRIVATE_IP_ADDRESS = "privateipaddress"; | ||
public static final String RELATED_ASSETS = "RELATED ASSETS"; | ||
public static final String CREATED_BY = "createdBy"; | ||
public static final String EMAIL = "email"; | ||
public static final String USERNAME = "username"; | ||
public static final String TOTAL_COST = "totalCost"; | ||
public static final String MANAGED_BY = "managedBy"; | ||
public static final String FIELDNAME = "fieldName"; | ||
public static final String ERROR_SEARCH = "Error in search "; | ||
public static final String ERROR_GETASSETSBYAG = "Error in getAssetsByAssetGroup "; | ||
public static final String ERROR_COUNT = "Error in count "; | ||
public static final String ERROR_EXEQUTEQUERY = "Error in executeQuery "; | ||
public static final String ERROR_BATCHUPDATE = "Error in batchUpdate "; | ||
public static final String ERROR_GETAPPSBYAG = "Error in getApplicationByAssetGroup "; | ||
public static final String DEBUG_RESPONSEJSON = "Response json is:"; | ||
public static final String ESQUERY_RANGE = ",{ \"range\": {\"date\": {"; | ||
public static final String ESQUERY_RANGE_CLOSE = "}}}]}}}"; | ||
public static final String ESQUERY_CLOSE = "\"}}]}}}"; | ||
public static final String ESQUERY_BULK = "/_bulk?refresh=true"; | ||
public static final String RESPONSE_ERROR = "\"errors\":true"; | ||
|
||
} | ||
|
||
/******************************************************************************* | ||
* Copyright 2018 T Mobile, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed 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 com.tmobile.pacman.api.asset; | ||
|
||
/** | ||
* Constants class where the asset service constants are stored. | ||
*/ | ||
public final class AssetConstants { | ||
|
||
private AssetConstants() { | ||
|
||
} | ||
|
||
public static final String FILTER_EXEC_SPONSOR = "executiveSponsor"; | ||
public static final String FILTER_RES_TYPE = "resourceType"; | ||
public static final String FILTER_DIRECTOR = "director"; | ||
public static final String FILTER_APPLICATION = "application"; | ||
public static final String FILTER_ENVIRONMENT = "environment"; | ||
public static final String FILTER_PATCHED = "patched"; | ||
public static final String FILTER_TAGGED = "tagged"; | ||
public static final String FILTER_TAGNAME = "tagName"; | ||
public static final String FILTER_RULEID = "ruleId"; | ||
public static final String FILTER_COMPLIANT = "compliant"; | ||
public static final String FILTER_DOMAIN = "domain"; | ||
public static final String TAG_NOT_FOUND = "Not Found"; | ||
public static final String ERROR_FROM_NEGATIVE = "From should not be a negative number"; | ||
public static final String ERROR_FILTER_ACCEPTS = "Filter accepts only "; | ||
public static final String ASSET_COUNT = "assetcount"; | ||
public static final String ERROR_INSTANCEID = "Asset group/Instance Id is Mandatory"; | ||
public static final String ERROR_FROM_EXCEEDS = "From exceeds the size of list"; | ||
public static final String ERROR_QUALYS_NOT_ENABLED = "Qualys not enabled"; | ||
public static final String ASSETS = "Assets"; | ||
public static final int ZERO = 0; | ||
public static final int FIFTEEN = 15; | ||
public static final int TWENTY = 20; | ||
public static final int TWENTY_FIVE = 25; | ||
public static final int THIRTY = 30; | ||
public static final int FORTY = 40; | ||
public static final int FIFTY = 50; | ||
public static final int SIXTY = 60; | ||
public static final int EIGHT = 8; | ||
public static final int NINE = 9; | ||
public static final String UNDERSCORE_ENTITY = "_entity"; | ||
public static final String ALL = "all"; | ||
public static final String STOPPED = "stopped"; | ||
public static final String STOPPING = "stopping"; | ||
public static final String UNDERSCORE_TYPE = "_type"; | ||
public static final String UNDERSCORE_SOURCE = "_source"; | ||
public static final String RECENTLY_VIEWED_AG = "recentlyViewedAg"; | ||
public static final String UNDERSCORE_LOADDATE = "_loaddate"; | ||
public static final String CREATE_TIME = "createtime"; | ||
public static final String FIRST_DISCOVEREDON = "firstdiscoveredon"; | ||
public static final String UNDERSCORE_DISCOVERY_DATE = "_discoverydate"; | ||
public static final String DISCOVERY_DATE = "discoverydate"; | ||
public static final String CREATION_DATE = "creationdate"; | ||
public static final String UNDERSCORE_ENTITY_TYPE_KEYWORD = "_entitytype.keyword"; | ||
public static final String UNDERSCORE_ENTITY_TYPE = "_entitytype"; | ||
public static final String AWS_EC2 = "aws_ec2"; | ||
public static final String INSTANCEID_KEYWORD = "instanceid.keyword"; | ||
public static final String FALSE = "false"; | ||
public static final String ERROR_FETCHING_FIELDNAMES = "Error while fetching field names "; | ||
public static final String SERVICE_NAME = "serviceName"; | ||
public static final String QUERY = "query"; | ||
public static final String POLICY_VIOLATIONS = "Policy Violations"; | ||
public static final String VULNERABILITIES = "Vulnerabilities"; | ||
public static final String PUBLIC_IP_ADDRESS = "publicipaddress"; | ||
public static final String PRIVATE_IP_ADDRESS = "privateipaddress"; | ||
public static final String RELATED_ASSETS = "RELATED ASSETS"; | ||
public static final String CREATED_BY = "createdBy"; | ||
public static final String EMAIL = "email"; | ||
public static final String USERNAME = "username"; | ||
public static final String TOTAL_COST = "totalCost"; | ||
public static final String MANAGED_BY = "managedBy"; | ||
public static final String FIELDNAME = "fieldName"; | ||
public static final String ERROR_SEARCH = "Error in search "; | ||
public static final String ERROR_GETASSETSBYAG = "Error in getAssetsByAssetGroup "; | ||
public static final String ERROR_COUNT = "Error in count "; | ||
public static final String ERROR_EXEQUTEQUERY = "Error in executeQuery "; | ||
public static final String ERROR_BATCHUPDATE = "Error in batchUpdate "; | ||
public static final String ERROR_GETAPPSBYAG = "Error in getApplicationByAssetGroup "; | ||
public static final String DEBUG_RESPONSEJSON = "Response json is:"; | ||
public static final String ESQUERY_RANGE = ",{ \"range\": {\"date\": {"; | ||
public static final String ESQUERY_RANGE_CLOSE = "}}}]}}}"; | ||
public static final String ESQUERY_CLOSE = "\"}}]}}}"; | ||
public static final String ESQUERY_BULK = "/_bulk?refresh=true"; | ||
public static final String RESPONSE_ERROR = "\"errors\":true"; | ||
public static final String FILTER_CATEGORY = "category"; | ||
public static final String FILTER_GENERAL = "general"; | ||
public static final String FILTER_RECOMMENDATION_ID = "recommendationId"; | ||
|
||
} | ||
|
186 changes: 186 additions & 0 deletions
186
...t/src/main/java/com/tmobile/pacman/api/asset/controller/CloudNotificationsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/** | ||
* | ||
*/ | ||
package com.tmobile.pacman.api.asset.controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.google.common.base.Strings; | ||
import com.tmobile.pacman.api.asset.AssetConstants; | ||
import com.tmobile.pacman.api.asset.domain.Request; | ||
import com.tmobile.pacman.api.asset.domain.ResponseWithCount; | ||
import com.tmobile.pacman.api.asset.service.CloudNotificationService; | ||
import com.tmobile.pacman.api.commons.Constants; | ||
import com.tmobile.pacman.api.commons.utils.CommonUtils; | ||
import com.tmobile.pacman.api.commons.utils.ResponseUtils; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
|
||
/** | ||
* The controller layer which has methods to return list of cloud notifications. | ||
* | ||
*/ | ||
@RestController | ||
@PreAuthorize("@securityService.hasPermission(authentication, 'ROLE_USER')") | ||
@CrossOrigin | ||
public class CloudNotificationsController { | ||
|
||
@Autowired | ||
CloudNotificationService cloudService; | ||
|
||
private static final Log LOGGER = LogFactory.getLog(AssetListController.class); | ||
|
||
/** | ||
* Fetches the Cloud Notifications for the rule id passed in the filter. | ||
* | ||
* @param request This request expects assetGroup and ruleId as mandatory | ||
* attributes. API returns all the CIS assets associated with the | ||
* assetGroup with matching filters. | ||
* | ||
* @return cloud Notifications by asset group. | ||
*/ | ||
|
||
@ApiOperation(httpMethod = "POST", value = "Get the list of Cloud Notifications by a asset Group. Mandatory Filter -'Global Notifications'") | ||
@PostMapping(value = "/v1/cloud/notifications") | ||
public ResponseEntity<Object> getlistOfCloudNotifications(@RequestBody(required = true) Request request, @RequestParam(name = "global", required = true) boolean globalNotifier ) { | ||
|
||
String assetGroup = request.getAg(); | ||
if (Strings.isNullOrEmpty(assetGroup)) { | ||
return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); | ||
} | ||
|
||
int from = request.getFrom(); | ||
int size = request.getSize(); | ||
if (from < 0) { | ||
return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE)); | ||
} | ||
|
||
String searchText = request.getSearchtext(); | ||
Map<String, String> filter = request.getFilter(); | ||
List<Map<String, Object>> masterList; | ||
|
||
try { | ||
masterList = cloudService.getNotifications(assetGroup, filter, globalNotifier, size, from); | ||
} catch (Exception e) { | ||
LOGGER.error("Error in getlistOfCloudNotifications ", e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
return formResponseWithCount(masterList, from, size, searchText); | ||
} | ||
|
||
/** | ||
* Method returns the list with count based on the from and size. | ||
* | ||
* @param masterList | ||
* @param from | ||
* @param size | ||
* @param searchText | ||
* | ||
* @return ResponseEntity | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
private ResponseEntity<Object> formResponseWithCount(List<Map<String, Object>> masterList, int from, int size, | ||
String searchText) { | ||
try { | ||
List<Map<String, Object>> masterDetailList = (List<Map<String, Object>>) CommonUtils | ||
.filterMatchingCollectionElements(masterList, searchText, true); | ||
if (masterDetailList.isEmpty()) { | ||
return ResponseUtils | ||
.buildSucessResponse(new ResponseWithCount(new ArrayList<Map<String, Object>>(), 0)); | ||
} | ||
|
||
if (from >= masterDetailList.size()) { | ||
return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_EXCEEDS)); | ||
} | ||
|
||
int endIndex = 0; | ||
|
||
if (size == 0) { | ||
size = masterDetailList.size(); | ||
} | ||
|
||
if ((from + size) > masterDetailList.size()) { | ||
endIndex = masterDetailList.size(); | ||
} else { | ||
endIndex = from + size; | ||
} | ||
|
||
List<Map<String, Object>> subDetailList = masterDetailList.subList(from, endIndex); | ||
return ResponseUtils.buildSucessResponse(new ResponseWithCount(subDetailList, masterDetailList.size())); | ||
} catch (Exception e) { | ||
LOGGER.error("Exception in formResponseWithCount ",e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
} | ||
|
||
@GetMapping(value = "/v1/cloud/notifications/summary") | ||
public ResponseEntity<Object> getCloudNotificationsSummary(@RequestParam(name = "ag", required = true) String assetGroup , | ||
@RequestParam(name = "global", required = true) boolean globalNotifier, | ||
@RequestParam(name = "resourceId", required = false) String resourceId, | ||
@RequestParam(name = "eventStatus", required = false) String eventStatus) { | ||
try { | ||
return ResponseUtils.buildSucessResponse(cloudService.getCloudNotificationsSummary(assetGroup, globalNotifier, resourceId, eventStatus)); | ||
} catch (Exception e) { | ||
LOGGER.error("Error in getCloudNotificationsSummary "+ e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
} | ||
|
||
@GetMapping(value = "/v1/cloud/notifications/detail") | ||
public ResponseEntity<Object> getCloudNotificationDetail(@RequestParam(name = "eventArn", required = true) String eventArn, | ||
@RequestParam(name = "global", required = true) boolean globalNotifier, | ||
@RequestParam(name = "ag", required = true) String assetGroup) { | ||
try { | ||
return ResponseUtils.buildSucessResponse(cloudService.getCloudNotificationDetail(eventArn,globalNotifier, assetGroup)); | ||
} catch (Exception e) { | ||
LOGGER.error("Error in getCloudNotificationDetail "+ e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
} | ||
|
||
@GetMapping(value = "/v1/cloud/notifications/info") | ||
public ResponseEntity<Object> getCloudNotificationInfo(@RequestParam(name = "eventArn", required = true) String eventArn, | ||
@RequestParam(name = "global", required = true) boolean globalNotifier, | ||
@RequestParam(name = "ag", required = true) String assetGroup) { | ||
try { | ||
return ResponseUtils.buildSucessResponse(cloudService.getCloudNotificationInfo(eventArn,globalNotifier, assetGroup)); | ||
} catch (Exception e) { | ||
LOGGER.error("Error in getCloudNotificationInfo "+ e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
} | ||
|
||
@ApiOperation(httpMethod = "POST", value = "Autofix plan details") | ||
@PostMapping(value = "/v1/autofix/notifications/detail") | ||
public ResponseEntity<Object> getAutofixProjectionDetail(@RequestBody(required = true) Request request) { | ||
try { | ||
String assetGroup = request.getAg(); | ||
Map<String, String> filter = request.getFilter(); | ||
if (Strings.isNullOrEmpty(assetGroup)) { | ||
return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY)); | ||
} | ||
if (filter.isEmpty()) { | ||
return ResponseUtils.buildFailureResponse(new Exception(Constants.FILTER_MANDATORY)); | ||
} | ||
return ResponseUtils.buildSucessResponse(cloudService.getAutofixProjectionDetail(assetGroup, filter)); | ||
} catch (Exception e) { | ||
LOGGER.error("Error in getAutofixProjectionDetail "+ e); | ||
return ResponseUtils.buildFailureResponse(e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.