Create a json schema for APTLY formula

Change-Id: I981882c44d1312fee16907f51938ab43192f926f
Related-Bug: PROD-20621 (PROD:20621)
Closes-Bug: PROD-23106 (PROD:23106)
diff --git a/.kitchen.yml b/.kitchen.yml
index 7a9fe1a..70fb513 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -36,8 +36,13 @@
 
 suites:
 
-  - name: default
+  - name: server
     provisioner:
       pillars-from-files:
-        aptly.sls: tests/pillar/default.sls
+        aptly.sls: tests/pillar/server.sls
+
+  - name: publisher
+    provisioner:
+      pillars-from-files:
+        aptly.sls: tests/pillar/publisher.sls
 # vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/.travis.yml b/.travis.yml
index 2e5d4b1..0633406 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,11 +20,12 @@
   - bundle install
 
 env:
-    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3 SUITE=default
-    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7 SUITE=default
-    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2018.3 SUITE=default
-#    - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2017.7 SUITE=default
-#    - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2018.3 SUITE=default
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3 SUITE=server
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7 SUITE=server
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2018.3 SUITE=server
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3 SUITE=publisher
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7 SUITE=publisher
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2018.3 SUITE=publisher
 
 before_script:
   - set -o pipefail
diff --git a/README.rst b/README.rst
index e099f11..8b9dd8e 100644
--- a/README.rst
+++ b/README.rst
@@ -70,7 +70,6 @@
                  component: main
                  architectures: amd64
                  comment: "Custom components"
-                 sources: false
                  publisher:
                    component: mycomponent
                    distributions:
diff --git a/aptly/map.jinja b/aptly/map.jinja
index 5538f99..a602b32 100644
--- a/aptly/map.jinja
+++ b/aptly/map.jinja
@@ -37,7 +37,7 @@
   'default': {
     'source': {
       'engine': 'pkg',
-      'pkgs': ['aptly-publisher'],
-    },
+      'pkgs': ['aptly'],
+    }
   },
 }, merge=salt['pillar.get']('aptly:publisher')) %}
diff --git a/aptly/meta/sphinx.yml b/aptly/meta/sphinx.yml
index 167efdf..9f613c9 100644
--- a/aptly/meta/sphinx.yml
+++ b/aptly/meta/sphinx.yml
@@ -43,7 +43,7 @@
             {%- endfor %}
         {%- endif %}
   {%- endif %}
-  {%- if pillar.aptly.server.api is defined %}
+  {%- if pillar.aptly.server is defined and pillar.aptly.server.api is defined %}
     api:
       name: api
       param: {}
@@ -55,8 +55,8 @@
       param:
         source:
           value:
-            engine: {{ server.source.engine }}
-            {%- if server.source.engine == 'docker' %}
-            image: {{ server.source.image|default('tcpcloud/aptly-publisher') }}
+            engine: {{ publisher.source.engine }}
+            {%- if publisher.source.engine == 'docker' %}
+            image: {{ publisher.source.image|default('tcpcloud/aptly-publisher') }}
             {%- endif %}
   {%- endif %}
diff --git a/aptly/schemas/publisher.yaml b/aptly/schemas/publisher.yaml
new file mode 100644
index 0000000..6f5b55f
--- /dev/null
+++ b/aptly/schemas/publisher.yaml
@@ -0,0 +1,33 @@
+title: APTLY publisher role
+description: APTLY publisher role
+type: object
+additionalProperties: false
+
+required:
+  - enabled
+
+properties:
+  enabled:
+    description: Enables APTLY publisher service
+    type: boolean
+  source:
+    description: Installation source parameters of APTLY publisher
+    type: object
+    additionalProperties: false
+    required: [engine]
+    properties:
+      engine:
+        description: Installation source for APTLY publisher
+        type: string
+        enum: ['pkg', 'pip', 'docker']
+      pkgs:
+        description: List of packages to be installed. Set if 'source' is 'pkg'
+        type: array
+        items:
+          type: string
+      image:
+        description: Publisher full image name. Set if installation from docker is chosen
+        type: string
+      registry:
+        description: Docker regirsty host for publisher image. Set if installation from docker is chosen
+        type: string
\ No newline at end of file
diff --git a/aptly/schemas/server.yaml b/aptly/schemas/server.yaml
new file mode 100644
index 0000000..73eb923
--- /dev/null
+++ b/aptly/schemas/server.yaml
@@ -0,0 +1,231 @@
+title: APTLY server role
+description: |
+  APTLY server role
+type: object
+additionalProperties: false
+
+required:
+  - enabled
+
+properties:
+  enabled:
+    description: Enables APTLY server.
+    type: boolean
+  secure:
+    description: Enable secure APTLY server.
+    type: boolean
+  source:
+    description: Installation source parameters for APTLY server.
+    type: object
+    additionalProperties: false
+    required: [engine]
+    properties:
+      engine:
+        description: Installation source for APTLY publisher. Can be one of ['pkg', 'docker']
+        type: string
+        enum: ['pkg', 'docker']
+      pkgs:
+        description: List of packages to be installed. Set if 'source' is 'pkg'
+        type: array
+        items:
+          description: APTLY package names
+          type: string
+      image:
+        description: Publisher full image name. Set if 'source' is 'docker'
+        type: string
+      registry:
+        description: Regirsty host for publisher image. Set if 'source' is 'docker'
+        type: string
+  no_config:
+    description: Start service without config
+    type: boolean
+  home_dir:
+    description: Home directory for APTLY system user
+    type: string
+  root_dir:
+    description: Root directory
+    type: string
+  user:
+    description: APTLY System user information.
+    type: object
+    additionalProperties: false
+    properties:
+      name:
+        description: User name for APLTY
+        type: string
+      group:
+        description: Group name for APTLY
+        type: string
+      uid:
+        description: User id for APTLY user
+        type: integer
+      gid:
+        description: Groupd id for APTLY user
+        type: integer
+  gpg_keypair_id:
+    description: GPG keypair id
+    type: string
+  gpg_passphrase:
+    description: Password phrase for GPG key
+    type: string
+  gpg_public_key:
+    description: Public key to PGP repository
+    type: string
+  gpg_private_key:
+    description: GPG Private key
+    type: string
+  gpg:
+    description: GPG parameters map
+    type: object
+    additionalProperties: false
+    required: [private_key, public_key, passphrase]
+    properties:
+      private_key:
+        description: GPG Private key
+        type: string
+      public_key:
+        description: Public key to PGP repository
+        type: string
+      homedir:
+        description: GPG home directory
+        type: string
+      keyserver:
+        description: GPG key server
+        type: string
+      keypair_id:
+        description: GPG keypair id
+        type: string
+      passphrase:
+        description: Password phrase for GPG key
+        type: string
+      keyring:
+        description: Keyring for GPG
+        type: string
+  api:
+    description: Parameters map for for APTLY API services
+    type: object
+    additionalProperties: false
+    required: [enabled]
+    properties:
+      enabled:
+        description: Enables APTLY API service
+        type: boolean
+      bind:
+        description: Bind parameters for APTLY API service
+        type: object
+        additionalProperties: false
+        properties:
+          host:
+            description: Host to bind APTLY API service
+            type: string
+          port:
+            description: Port to bind APTLY API service
+            type: [string, integer]
+  mirror_update:
+    description: Parameters map for for apt mirror
+    type: object
+    additionalProperties: false
+    required: [enabled]
+    properties:
+      enabled:
+        description: Enables APTLY mirror
+        type: boolean
+      http_proxy:
+        description: HTTP Proxy for apt mirror access
+        type: string
+      https_proxy:
+        description: HTTPS Proxy for apt mirror access
+        type: string
+      hour:
+        description: Hour parameter in cron job for aptly mirror update
+        type: [string, integer]
+      minute:
+        description: Minute parameter in cron job for aptly mirror update
+        type: [string, integer]
+  mirror:
+    description: |
+      Mirror map where key is mirror name and value is a list of mirror properties: source, distribution, gpgkeys and etc
+    type: array
+    items:
+      type: object
+      $ref: "#/definitions/_aptly_mirror_object"
+  repo:
+    description: Repo map where key is repo name and value is a list of repo properties
+    type: object
+    patternProperties:
+      "^[A-Za-z0-9]*$":
+        $ref: "#/definitions/_aptly_repo_object"
+
+definitions:
+  _aptly_mirror_object:
+    description: Parameters map of apt mirror
+    type: object
+    properties:
+      source:
+        description: Source url for apt mirror
+        type: string
+        example: http://example.com/debian
+      distribution:
+        description: OS distribution
+        type: string
+        example: xenial
+      components:
+        description: Component's types
+        type: string
+        example: main
+      architectures:
+        $ref: "#/definitions/_architectures"
+      gpgkeys:
+        description: GPG keys for apt mirror
+        type: string
+      filter:
+        description: Filter for packages in mirror
+        type: string
+        example: "!(Name (% *-dbg))"
+      filter_with_deps:
+        description: When filtering, include dependencies of matching packages as well
+        type: string
+      publisher:
+        description: Parameters of publish mirror
+        type: object
+        $ref: "#/definitions/_aptly_mirror|repo_publisher_object"
+      sources:
+        description: Download source packages in addition to binary packages
+        type: boolean
+      udebs:
+        description: Download .udeb packages
+        type: boolean
+  _aptly_mirror|repo_publisher_object:
+    description: Parameters of publish mirror|repo
+    type: object
+    properties:
+      component:
+        description: Publisher's component
+        type: string
+      distributions:
+        description: List of distributions for publisher
+        type: array
+        items:
+          type: string
+  _aptly_repo_object:
+    type: object
+    properties:
+      distribution:
+        description: OS distribution
+        type: string
+        example: xenial
+      component:
+        description: Component type
+        type: string
+        example: main
+      architectures:
+        $ref: "#/definitions/_architectures"
+      comment:
+        description: Comment for repo description
+        type: string
+      publisher:
+        $ref: "#/definitions/_aptly_mirror|repo_publisher_object"
+  _architectures:
+    description: Packages architecture
+    type: string
+    example: amd64
\ No newline at end of file
diff --git a/tests/pillar/publisher.sls b/tests/pillar/publisher.sls
new file mode 100644
index 0000000..6e0c3ea
--- /dev/null
+++ b/tests/pillar/publisher.sls
@@ -0,0 +1,3 @@
+aptly:
+  publisher:
+    enabled: true
diff --git a/tests/pillar/default.sls b/tests/pillar/server.sls
similarity index 99%
rename from tests/pillar/default.sls
rename to tests/pillar/server.sls
index 35431e3..3711a7a 100644
--- a/tests/pillar/default.sls
+++ b/tests/pillar/server.sls
@@ -7,7 +7,6 @@
         component: main
         architectures: amd64
         comment: "Custom components"
-        sources: false
         publisher:
           component: mycomponent
           distributions: