# (C) Copyright 2014 Riverbed Technology, Inc.
# All rights reserved.

name: cmc.web-proxy
version: "2.0"
title: Web proxy service
description: REST API for Web proxy service.
$schema: 'http://support.riverbed.com/apis/service_def/2.2'
id: 'http://support.riverbed.com/apis/cmc.web-proxy/2.0'
provider: 'riverbed'

types:
    identifier:
        type: integer
        minimum: 1
        readOnly: true

    unrestricted_name:
        type: string
        pattern: '^[a-zA-Z0-9-][a-zA-Z0-9_-]*$|^[a-zA-Z0-9_-][a-zA-Z0-9 _-]+[a-zA-Z0-9_-]$'
        minLength: 1
        maxLength: 30 
    
    hostname:
        type: string
        pattern: '^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))?$'
        maxLength: 255
    
    remote_address:
        description: 'Remote address/IP'
        type: string
        pattern: '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
        minLength: 3
        maxLength: 253

    remote_port:
        description: 'Remote port'
        type : integer
        minimum: 0
        maximum: 65535

    domain_name:
        type: string
        pattern: '^(\*\.)?[0-9A-Za-z](([0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(\.[0-9A-Za-z](([0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$'
        minLength: 3
        maxLength: 253

    domain_state:
        type: string
        description: 'Optimization state of the domain'
        enum: ['white', 'black', 'grey']

    chaining_mode:
        type: string
        enum: ['off', 'automatic', 'manual']

    server_mode:
        type: string
        enum: ['http', 'https']

    proxy_exception_set:
        type: object
        properties:
            row_id:
                $ref: '#/types/identifier'
            domain_name:
                $ref: '#/types/hostname'
        required: [row_id, domain_name] 

    ssl_domain_set:
        type: object
        properties:
            row_id:
                $ref: '#/types/identifier'
            domain_name:
                $ref: '#/types/domain_name'
        required: [row_id, domain_name] 

    create_empty:
        type: object
        properties:
            profile_name:
                $ref: '#/types/unrestricted_name'
            site_info:
                type: object
                properties:
                    site_id:
                       type: array
                       items:
                           $ref: '#/types/identifier'
                    site_type_id:
                       type: array
                       items: 
                           $ref: '#/types/identifier'
                oneOf:
                    - type: object
                      required: [site_id]
                    - type: object
                      required: [site_type_id]
        required : [ profile_name, site_info ]

    clone:
        type: object
        properties:
            source_profile:
                $ref: '#/types/unrestricted_name'
            profile_name:
                $ref: '#/types/unrestricted_name'
            site_info:
                type: object
                properties:
                    site_id:
                       type: array
                       items:
                           $ref: '#/types/identifier'
                    site_type_id:
                       type: array
                       items: 
                           $ref: '#/types/identifier'
                oneOf:
                    - type: object
                      required: [site_id]
                    - type: object
                      required: [site_type_id]
        required : [ source_profile, profile_name, site_info ]


    poller_response:
        type: object
        properties:
            poll_req_id:
                type: integer
                description: Request ID registered with poller
            serial:
                type: string
                description: Appliance from which response is received.
            poll_time:
                type: integer
                description: Time when resource was polled, in seconds since the UNIX epoch.
            resp_data:
                type: string
                description: Response from the polled request.

resources:
    profile:
        description: "Site specific profile configuration for Web Proxy"
        type: object
        additionalProperties: False
        properties:
            profile_id:
                $ref: '#/types/identifier'
            profile_name:
                $ref: '#/types/unrestricted_name'
            enabled:
                type: boolean
                description: "Enable Web proxy."
            https_enabled:
                type: boolean
                description: "Enable HTTPS optimization for Web proxy."
            audit_log:
                description: 'Audit log (syslog) settings'
                type: object
                additionalProperties: false
                required: [audit_log_enabled]
                properties:
                    audit_log_enabled:
                        description: 'Enable/disable remote logging for the HTTP/S traffic.'
                        type: boolean
                        default: False
                    format:
                        description: 'The log format for HTTP/S traffic'
                        type: string
                        enum: ["CLF"]
                    remote_address:
                        $ref: '#/types/hostname'
                    remote_port:
                        description: 'Remote port'
                        type: integer
                        minimum: 0
                        maximum: 65535
                        default: 514
            site_info:
                type: object
                properties:
                    site_id:
                       type: array
                       items:
                           type: integer
                    site_type_id:
                       type: array
                       items: 
                           type: integer
                oneOf:
                    - type: object
                      required: [site_id]
                    - type: object
                      required: [site_type_id]

        relations:
            instances:
                resource: '#/resources/profiles'
            
        links:
            self:
                path: "$/profiles/items/{id}"
            get:
                method: GET
                response:
                    $ref: '#/resources/profile'
            set:
                method: PUT
                request:
                    $ref: '#/resources/profile'
                response:
                    $ref: '#/resources/profile'
            delete:
                method: DELETE


    profiles:
        description: "List of all profiles"
        type: array
        items:
            $merge:
                source: { $ref: '#/resources/profile'}
                with:
                    relations:
                        full:
                            resource: '#/resources/profile'
                            vars: {id: "0/id"}
        links:
            self:
                path: "$/profiles"
            get:
                method: GET
                response:
                    $ref: '#/resources/profiles'
            create:
                method: POST
                request:
                    $ref: '#/types/create_empty'
                response:
                    $ref: '#/resources/profile'
            clone:
                method: POST
                path: "$/profiles/clone"
                request:
                    $ref: '#/types/clone'
                response:
                   $ref: '#/resources/profile'

    profile_ssl_domain:
        description: "SSL Domains associated with profile."
        type: object
        additionalProperties: false
        properties:
            id:
              $ref: '#/types/identifier'
            profile_id:
              $ref: '#/types/identifier'
            domain_name:
              $ref: '#/types/domain_name'
            state:
              $ref: '#/types/domain_state' 
        
        links:
            self:
                path: "$/profile_ssl_domains/items/{id}"
            get:
                method: GET
                response:
                    $ref: '#/resources/profile_ssl_domain'
            set:
                method: PUT
                request:
                    $ref: '#/resources/profile_ssl_domain'
                response:
                    $ref: '#/resources/profile_ssl_domain'
            delete:
                method: DELETE
            

    profile_ssl_domains:
        description: "SSL Domains Plurals"
        type: array
        items:
            $merge:
                source: { $ref: '#/resources/profile_ssl_domain'}
                with:
                    relations:
                        full:
                            resource: '#/resources/profile_ssl_domain'
                            vars: {id: "0/id"}
        links:
            self:
                path: "$/profile_ssl_domains"  
                params:
                    # Filter based on the profile_id
                    profile_id:
                        $ref: '#/types/identifier'
            get:
                method: GET
                response:
                    $ref: '#/resources/profile_ssl_domains'
            create:
                method: POST
                request:
                    $ref: '#/resources/profile_ssl_domain'  
                response: 
                    $ref: '#/resources/profile_ssl_domain'


    parent_proxy_exclude_domain:
        description: 'Settings for domains that need to bypass the parent proxy'
        type: object
        additionalProperties: false
        properties:
            id:
              $ref: '#/types/identifier'
            profile_id:
              $ref: '#/types/identifier'
            domain_name:
              $ref: '#/types/hostname'

        relations:
            instances:
                resource: '#/resources/parent_proxy_exclude_domains'
        
        links:
            self:
                path: "$/parent_proxy_exclude_domains/items/{id}"
            get:
                method: GET
                response:
                    $ref: '#/resources/parent_proxy_exclude_domain'
            set:
                method: PUT
                request:
                    $ref: '#/resources/parent_proxy_exclude_domain'
                response:
                    $ref: '#/resources/parent_proxy_exclude_domain'
            delete:
                method: DELETE

    parent_proxy_exclude_domains:
        description: "List of all profiles"
        type: array
        items:
            $merge:
                source: { $ref: '#/resources/parent_proxy_exclude_domain'}
                with:
                    relations:
                        full:
                            resource: '#/resources/parent_proxy_exclude_domain'
                            vars: {id: "0/id"}
        links:
            self:
                path: "$/parent_proxy_exclude_domains"
                params:
                    # Filter based on the profile_id
                    profile_id:
                        $ref: '#/types/identifier'
            get:
                method: GET
                response:
                    $ref: '#/resources/parent_proxy_exclude_domains'
            create:
                method: POST
                response: 
                    $ref: '#/resources/parent_proxy_exclude_domain'
                request:
                    $ref: '#/resources/parent_proxy_exclude_domain'

    proxy_chain:
        description: "Profile specific list of Proxy servers"
        type: object
        additionalProperties: false
        properties:
            profile_id:
                $ref: '#/types/identifier'
            http:
                type: array
                description: "List of HTTP servers"
                items:
                    type: object
                    additionalProperties : false
                    properties:
                        address:
                            $ref: '#/types/remote_address'
                        port:
                            $ref: '#/types/remote_port'
                    required: [address, port]
            https:
                type: array
                items:
                    type: object
                    additionalProperties : false
                    properties:
                        address:
                            $ref: '#/types/remote_address'
                        port:
                            $ref: '#/types/remote_port'
                    required: [address, port]
            chaining_mode:
                $ref: '#/types/chaining_mode'
        links:
            self:
                path: "$/proxy_chain"
                params:
                    # Filter based on the profile_id
                    profile_id:
                        $ref: '#/types/identifier'
            get:
                method: GET
                response:
                    $ref: '#/resources/proxy_chain'
            create:
                method: POST
                request:
                    $ref: '#/resources/proxy_chain'
                response:
                    $ref: '#/resources/proxy_chain'

    poller:
        type: object
        description: Temporary callback for statistics poll requests.
        required: [ poll_req_id, serial, poll_time, resp_data ]

        links:
            self:
                path: "$/poller_callback"

            callback:
                method: POST
                description: Callback to get polled response.
                request:
                    $ref: '#/types/poller_response'
