def get_service_inputs(app_ns: str): ''' Returns the required inputs for the recommendation service given the application namespace used to identify the appropriate cloud resources. Returns ---------- A tuple containing the latest SecurityRecommendationSet and Portfolio objects. If a portfolio does not exist, it will create a new one. ''' log.info("Loading latest recommendations") recommendation_set = SecurityRecommendationSet.from_s3(app_ns) if not recommendation_set.is_current(datetime.now()): raise ValidationError("Current recommendation set is not valid", None) try: log.info("Loading current portfolio") pfolio = Portfolio.from_s3(app_ns) except AWSError as e: if e.resource_not_found(): pfolio = None else: raise e return (pfolio, recommendation_set)
def get_service_inputs(app_ns: str): ''' Returns the required inputs for the recommendation service given the application namespace used to identify the appropriate cloud resources. Returns ---------- A tuple containing the latest SecurityRecommendationSet and Portfolio objects. If a portfolio does not exist, it will create a new one. ''' log.info("Loading latest recommendations") recommendation_set = SecurityRecommendationSet.from_s3( app_ns, constants.S3_PRICE_DISPERSION_RECOMMENDATION_SET_OBJECT_NAME) business_date = util.get_business_date( constants.BUSINESS_DATE_DAYS_LOOKBACK, constants.BUSINESS_DATE_CUTOVER_TIME) if not recommendation_set.is_current(business_date): raise ValidationError("Current recommendation set is not valid", None) try: log.info("Loading current portfolio") pfolio = Portfolio.from_s3(app_ns, constants.S3_PORTFOLIO_OBJECT_NAME) except AWSError as e: if e.resource_not_found(): pfolio = None else: raise e return (pfolio, recommendation_set)