Exemplo n.º 1
0
def delete_service(userId, servicename=None, hostid=None):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = {}

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    if not servicename or not hostid:
        raise Exception(
            "invalid input - must specify a servicename and hostid to delete")

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/system/services/" + servicename + "/" + hostid

    ret = http.anchy_delete(url,
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 2
0
def delete_registry(userId, registry=None):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = {}

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    if not registry:
        raise Exception("invalid input - must specify a registry to delete")

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/system/registries/" + registry

    ret = http.anchy_delete(url,
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 3
0
def delete_policy(userId, policyId=None, cleanup_evals=True):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = {}

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/policies?{}".format(
        urllib.urlencode({'cleanup_evals': str(cleanup_evals)}))

    payload = {}
    if policyId:
        payload["policyId"] = policyId

    ret = http.anchy_delete(url,
                            data=json.dumps(payload),
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 4
0
def delete_subscription(userId,
                        subscription_key=None,
                        subscription_type=None,
                        subscription_id=None):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = {}

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    if subscription_key and subscription_type:
        subscription_id = hashlib.md5('+'.join(
            [userId, subscription_key, subscription_type])).hexdigest()

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/subscriptions/" + subscription_id

    ret = http.anchy_delete(url,
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 5
0
def delete_image(userId, imageDigest, force=False):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = False

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/image/" + imageDigest

    if force:
        url = url + "?{}".format(urllib.urlencode({'force': True}))

    ret = http.anchy_delete(url,
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 6
0
def delete_events(userId, since=None, before=None):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = False

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    base_url = anchore_engine.clients.common.get_service_endpoint(
        userId, 'catalog')
    url = base_url + "/events"

    path_params = []

    if since:
        path_params.append('since={}'.format(since))

    if before:
        path_params.append('before={}'.format(before))

    if path_params:
        url = url + '?' + '&'.join(path_params)

    ret = http.anchy_delete(url,
                            auth=auth,
                            headers=headers,
                            verify=localconfig['internal_ssl_verify'])

    return (ret)
Exemplo n.º 7
0
def delete_policy(userId, policyId=None, cleanup_evals=True):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = {}

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)
    
    base_url = get_catalog_endpoint()
    url = base_url + "/policies?cleanup_evals="+str(cleanup_evals)

    payload = {}
    if policyId:
        payload["policyId"] = policyId

    ret = http.anchy_delete(url, data=json.dumps(payload), auth=auth, headers=headers, verify=localconfig['internal_ssl_verify'])

    #(httpcode, jsondata, rawdata) = http.fdelete(url, data=json.dumps(payload), auth=auth, headers=headers, verify=localconfig['internal_ssl_verify'])
    #if httpcode == 200 and jsondata != None:
    #    ret = jsondata
    #else:
    #    #raise Exception("failed delete: httpcode="+str(httpcode)+" rawdata="+str(rawdata))
    #    e = Exception("failed delete url="+str(url))
    #    e.__dict__.update({'httpcode':httpcode, 'anchore_error_raw':str(rawdata), 'anchore_error_json':jsondata})
    #    raise e

    return(ret)
Exemplo n.º 8
0
def delete_image(userId, imageDigest, force=False):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = False

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    base_url = get_catalog_endpoint()
    url = base_url + "/image/" + imageDigest

    if force:
        url = url+"?force=True"

    ret = http.anchy_delete(url, auth=auth, headers=headers, verify=localconfig['internal_ssl_verify'])

    #(httpcode, jsondata, rawdata) = http.fdelete(url, auth=auth, headers=headers, verify=localconfig['internal_ssl_verify'])
    #if httpcode == 200:
    #    ret = True
    #else:
    #    #raise Exception("failed delete: httpcode="+str(httpcode)+" rawdata="+str(rawdata))
    #    e = Exception("failed delete url="+str(url))
    #    e.__dict__.update({'httpcode':httpcode, 'anchore_error_raw':str(rawdata), 'anchore_error_json':jsondata})
    #    raise e

    return(ret)    
Exemplo n.º 9
0
def delete_event(userId, eventId):
    global localconfig, headers
    if localconfig == None:
        localconfig = anchore_engine.configuration.localconfig.get_config()

    ret = False

    if type(userId) == tuple:
        userId, pw = userId
    else:
        pw = ""
    auth = (userId, pw)

    base_url = anchore_engine.clients.common.get_service_endpoint(userId, 'catalog')
    url = base_url + "/events/" + eventId

    ret = http.anchy_delete(url, auth=auth, headers=headers, verify=localconfig['internal_ssl_verify'])

    return(ret)