from anchore_engine.apis.authorization import ( ActionBoundPermission, RequestingAccountValue, ) authorizer = get_authorizer() IMPORT_BUCKET = "image_content_imports" MAX_UPLOAD_SIZE = 100 * 1024 * 1024 # 100 MB OPERATION_EXPIRATION_DELTA = datetime.timedelta(hours=24) @authorizer.requires([ActionBoundPermission(domain=RequestingAccountValue())]) def create_operation(): """ POST /imports/images :return: """ try: client = internal_client_for( CatalogClient, userId=ApiRequestContextProxy.namespace() ) resp = client.create_image_import() return resp, 200 except api_exceptions.AnchoreApiError as ex: return ( make_response_error(ex, in_httpcode=ex.__response_code__),
except Exception as err: return_object = anchore_engine.common.helpers.make_response_error( err, in_httpcode=httpcode) httpcode = return_object['httpcode'] except: service_detail = {} return_object = service_detail except Exception as err: return_object = str(err) return return_object, httpcode @authorizer.requires([ActionBoundPermission(domain=GLOBAL_RESOURCE_DOMAIN)]) def list_services(): """ GET /system/services :param request_inputs: :return: """ request_inputs = anchore_engine.apis.do_request_prep(request, default_params={}) user_auth = request_inputs['auth'] params = request_inputs['params'] return_object = [] httpcode = 500 try:
raise AccountNotFoundError(accountname) if accnt["type"] == AccountTypes.service: raise Exception("Bad Request") return accnt def verify_user(username, accountname, mgr): usr = mgr.get_user(username) if not usr or usr["account_name"] != accountname: raise UserNotFoundError(username) if usr["account"]["type"] == AccountTypes.service: raise Exception("Bad Request") return usr @authorizer.requires([ActionBoundPermission(domain=RequestingAccountValue())]) def get_users_account(): """ GET /account :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) account = mgr.get_account(ApiRequestContextProxy.namespace()) return account_db_to_msg(account), 200 except Exception as ex: logger.exception("API Error") return make_response_error(errmsg=str(ex)), 500
GET /account :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) account = mgr.get_account(ApiRequestContextProxy.namespace()) return account_db_to_msg(account), 200 except Exception as ex: logger.exception('API Error') return make_response_error(errmsg=str(ex)), 500 @authorizer.requires([ActionBoundPermission(domain=GLOBAL_RESOURCE_DOMAIN)]) def list_accounts(state=None): """ GET /accounts :param active: :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) if state is not None: try: state = AccountStates(state) except:
except Exception as err: return_object = anchore_engine.common.helpers.make_response_error( err, in_httpcode=httpcode) httpcode = return_object['httpcode'] except: service_detail = {} return_object = service_detail except Exception as err: return_object = str(err) return (return_object, httpcode) @authorizer.requires([ActionBoundPermission(domain=SYSTEM_ACCOUNT_NAME)]) def list_services(): """ GET /system/services :param request_inputs: :return: """ request_inputs = anchore_engine.apis.do_request_prep(request, default_params={}) user_auth = request_inputs['auth'] params = request_inputs['params'] return_object = [] httpcode = 500 try:
GET /account :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) account = mgr.get_account(ApiRequestContextProxy.namespace()) return account_db_to_msg(account), 200 except Exception as ex: logger.exception('API Error') return make_response_error(errmsg=str(ex)), 500 @authorizer.requires([ActionBoundPermission(domain=SYSTEM_ACCOUNT_NAME)]) def list_accounts(is_active=None): """ GET /accounts :param active: :return: """ try: with session_scope() as session: mgr = manager_factory.for_session(session) if is_active is not None: response = filter(lambda x: x['is_active'] == is_active, mgr.list_accounts()) else: