getJobs
    • PDF

    getJobs

    • PDF

    Article Summary

    개요

    • getJobs API 는 "Web Security Checker" 에서 제공하는 기능으로 네이버 클라우드 플랫폼 콘솔에서 사용자가 등록한 진단 리스트를 조회하여 결과를 출력하는 API입니다.

    요청

    MethodRequest URI
    GEThttps://wsc.apigw.ntruss.com/api/v1/jobs

    요청 헤더

    IAM 인증을 위한 요청 헤더입니다.

    헤더명설명
    x-ncp-apigw-timestamp1970년 1월 1일 00:00:00 협정 세계시(UTC)부터의 경과 시간을 밀리초(Millisecond)로 나타낸 것
    API Gateway 서버와 시간 차가 5분 이상 나는 경우 유효하지 않은 요청으로 간주
    x-ncp-iam-access-key네이버 클라우드 플랫폼에서 IAM 에서 발급받은 AccessKey
    x-ncp-apigw-signature-v2요청 경로 및 헤더를 AccessKey와 맵핑되는 SecretKey로 암호화한 서명으로
    HMAC 암호화 알고리즘은 HmacSHA256 을 사용

    요청 파라미터

    파라미터명필수 여부타입설명
    limitYesinteger리스트의 한 페이지 당 출력 항목 수
    pageYesinteger리스트의 페이지 번호

    응답

    응답 바디

    필드명필수 여부타입설명
    total_cntYesinteger총 작업 레코드 수
    total_page_cntYesinteger마지막 페이지(page)
    current_start_pageYesintegerPagination 노출 시 시작 페이지 번호 (10개 단위)
    current_end_pageYesintegerPagination 노출 시 마지막 페이지 번호 (10개 단위)
    record_dataYesarray진단 리스트
    record_data[].instanceNoYesinteger작업(Job)의 식별 번호
    record_data[].start_dateYesdate진단 작업(Job) 시작 시간
    record_data[].end_dateYesdate진단 작업(Job) 종료 시간
    record_data[].statusYesstring작업 상태(Job Status)
    record_data[].start_urlYesstring진단 작업 대상 URL
    record_data[].crawl_cntYesinteger크롤링 URL 수집 카운트
    record_data[].scan_cntYesinteger취약점 카운트
    record_data[].memoYesstring작업(Job) 메모(memo)
    record_data[].result_buttonYesstring작업 리포트 출력 가능 여부 및 작업 취소 여부 등의 작업 상태를 표기

    report : 리포트 출력 가능 상태
    cancel : 작업 취소 상태
    terminate : 작업 중지 상태
    expired : 기간 만료
    cause : 작업 진행 중 오류 발생
    record_data[].result_descYesstring작업 결과 상세 설명 (작업 오류일 경우 상세 출력)
    record_data[].rescan_buttonYesstring재진단 가능 상태를 표시

    possible: 재진단 가능
    expired : 기간 만료로 재진단 불가
    null : 재진단 불가
    record_data[].slave_dataYesArray

    예시

    요청 예시

        curl -X GET "https://wsc.apigw.ntruss.com/api/v1/jobs?limit=10&page=1"
           -H "accept: application/json"
           -H "x-ncp-iam-access-key: {x-ncp-iam-access-key}"
           -H "x-ncp-apigw-timestamp: {x-ncp-apigw-timestamp}"
           -H "x-ncp-apigw-signature-v2: {x-ncp-apigw-signature-v2}"
    

    응답 예시 1

    {
        "resources": {
            "total_cnt": 1,
            "total_page_cnt": "1",
            "current_start_page": "1",
            "current_end_page": "10",
            "record_data": [
                {
                    "instanceNo": "1234567890",
                    "start_date": "2020-05-21 12:00:00",
                    "end_date": null,
                    "status": "예약",
                    "start_url": "http://your-domain.com",
                    "crawl_cnt": null,
                    "scan_cnt": null,
                    "memo": "샘플",
                    "result_button": "cancel",
                    "result_desc": null,
                    "rescan_button": null,
                    "slave_data": null
                }
            ]
        }
    }
    

    응답 예시 2

    {
        "resources": {
            "total_cnt": 0,
            "total_page_cnt": "1",
            "current_start_page": "1",
            "current_end_page": "1",
            "record_data": null
        }
    }
    

    샘플 코드

    make_signature 함수로 시그니처를 생성하여 요청 헤드를 생성한 후 입력한 요청 파라미터에 따라 진단 리스트를 조회하여 응답 코드가 200인 경우 결과를 출력하는 샘플 코드는 다음과 같습니다.

    import sys
    import os
    import hashlib
    import hmac
    import base64
    import requests
    import time
    
    def make_signature(method, uri, timestamp):
    
        access_key = "{accessKey}"  # access key id (from portal or sub account)
        secret_key = "{secretKey}"  # secret key (from portal or sub account)
        secret_key = bytes(secret_key, 'UTF-8')
    
        method = method
        uri = uri
    
        message = method + " " + uri + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey
    
    timestamp = str(int(time.time() * 1000))
    
    method = 'GET'
    uri = '/api/v1/jobs?pages=1&limit=10'
    
    signature = make_signature(method, uri, timestamp)
    
    headers = {
        'x-ncp-apigw-signature-v2': signature.decode('utf-8'),
        'x-ncp-apigw-timestamp': timestamp,
        'x-ncp-iam-access-key': '{accessKey}' # access key id (from portal or sub account)
    }
    
    response = requests.request(
        method,
        f"https://wsc.apigw.ntruss.com{uri}",
        headers=headers
    )
    
    if respones.status_code == 200:
        print(response.text)
    
    참고

    샘플 코드는 Python3를 기반으로 작성했습니다. Java, Node.js 등 다른 언어로 작성한 샘플 코드는 API Gateway 사용 가이드의 API 호출을 참고해 주십시오.


    이 문서가 도움이 되었습니까?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.