<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
- Licensed Materials - Property of IBM Corp.
- IBM UrbanCode Deploy
- (c) Copyright IBM Corporation 2011, 2017. All Rights Reserved.
-
- U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by
- GSA ADP Schedule Contract with IBM Corp.
-->
<plugin xmlns="http://www.urbancode.com/PluginXMLSchema_v1" xmlns:server="http://www.urbancode.com/PluginServerXMLSchema_v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>
    <identifier id="com.urbancode.air.plugin.source.docker" name="Docker" version="32"/>
    <description>
      This Docker source plugin detects Docker registry image tags and creates associated component versions for the tag.
    </description>
    <tag>Source and Repositories/Docker Import Tag</tag>
    <server:plugin-type>Source</server:plugin-type>
    <server:required-server-version>6.1.1.0</server:required-server-version>
  </header>

    <step-type name="Import Version">
      <description>Creates a new component version for a tag</description>
      <properties>
      </properties>
      <post-processing><![CDATA[
        if (properties.get("exitCode") != 0) {
            properties.put(new java.lang.String("Status"), new java.lang.String("Failure"));
        }
        else {
            properties.put("Status", "Success");
        }
     ]]></post-processing>

      <command program="${GROOVY_HOME}/bin/groovy">
        <arg value="-cp"/>
        <arg path="classes:lib/CommonsUtil.jar:lib/HttpComponents-Util.jar:lib/fluent-hc.jar:lib/httpclient-cache.jar:lib/httpclient.jar:lib/httpcore.jar:lib/httpmime.jar:lib/log4j.jar:lib/commons-codec.jar:lib/jettison-1.1.jar:lib/uDeployRestClient.jar:lib/securedata.jar"/>
        <arg file="importVersions.groovy"/>
        <arg file="${PLUGIN_INPUT_PROPS}"/>
        <arg file="${PLUGIN_OUTPUT_PROPS}"/>
      </command>
        </step-type>

    <!-- ==================================== -->
    <!--   Properties                         -->
    <!-- ==================================== -->
    <server:property-group name="DockerTagImport" type="Component">
      <server:description/>
      <server:property name="dockerImageName" required="true">
        <server:property-ui
            default-value="${p:component.name}"
            description="The [namespace/]repository of the image in the Docker registry.  For Amazon, namespace not needed."
            label="Image Name"
            type="textBox"/>
      </server:property>
      <server:property name="regexForTag" required="false">
        <server:property-ui
            default-value=""
            description="Provide regular expression to select tags to create component versions for."
            label="Regular Expression for Tag Selection"
            type="textBox"/>
      </server:property>
      <server:property name="dockerRegistryName" required="false">
          <server:property-ui
            description="If image is host:5000/namespace/repository:tag use host:5000. Leave blank for Docker Hub. If Artifactory, supply the server's hostname or reverse proxy."
            label="Registry"
            type="textBox"/>
      </server:property>
      <server:property name="registryType" required="true">
          <server:property-ui
            description="Specify which API to connect with the Docker Registry. When using IBM Containers, provide IBM Cloud Credentials.
                    For Amazon ECR, use AWS access key as username and secret key as password"
            label="Registry Type"
            type="selectBox"/>
            <server:value label="Docker">false</server:value>
            <server:value label="IBM Containers">true</server:value>
            <server:value label="Artifactory">artifactory</server:value>
            <server:value label="Amazon ECR">amazon</server:value>
      </server:property>
      <server:property name="api" required="false">
        <server:property-ui type="textBox" label="IBM Cloud API Endpoint" description="For example, https://api.ng.bluemix.net."/>
    </server:property>
    <server:property name="space" required="false">
        <server:property-ui type="textBox" label="IBM Cloud Space" description="For use with IBM Cloud's container registry. The space to log into.
             If left blank, the space will not be reset."/>
    </server:property>
    <server:property name="org" required="false">
        <server:property-ui type="textBox" label="IBM Cloud Organization" description="For use with IBM Cloud's container registry. The organization to log into.
             If left blank, the api will not be reset."/>
    </server:property>
    <server:property name="dockerHome" required="false">
        <server:property-ui type="textBox" label="Bluemix Home" description="For use with IBM Cloud's container registry. Specify the directory containing your Bluemix config.json file (for example, /root/.bluemix)"/>
    </server:property>
    <server:property name="dockerRegistryUsername" required="false">
        <server:property-ui
            default-value="${p?:dockerUsername}"
            description="The username used to login to the Docker registry.  For Amazon ECR, use access key"
            label="Registry Username"
            type="textBox"/>
      </server:property>
      <server:property name="dockerRegistryPassword" required="false">
      <server:property-ui
            default-value="${p?:dockerPassword}"
            description="The password used to login to the Docker registry. Default value is ${p?:dockerPassword}.  For Amazon ECR, use secret key"
            label="Registry Password"
            type="secureBox"/>
      </server:property>
      <server:property name="dockerRegistryAPIKey" required="false">
      <server:property-ui
            default-value=""
            description="API key to be used when logging in to the registry. May be a string or location of a key file. Use in place of a username and password."
            label="Registry API Key"
            type="secureBox"/>
      </server:property>
      <server:property name="allowInsecure" required="true">
        <server:property-ui
            description="Select this option to allow insecure connections to the Docker registry"
            label="Allow Insecure Registry Connection"
            type="checkBox"
            default-value="false"/>
      </server:property>
      <server:property name="namingConvention">
        <server:property-ui type="selectBox"
            label="Naming Convention"
            default-value="hyphenated"
            description="The naming convention for component versions. Docker tags can be changed. If component versions need to be immutable, select a naming convention that includes the ID."/>
        <server:value label="Tag - ID">hyphenated</server:value>
        <server:value label="Tag ID">space</server:value>
        <server:value label="Tag">tag_only</server:value>
      </server:property>
      <server:property name="region" required="false">
          <server:property-ui
              placeholder="us-east-1"
              description="Region to use when importing images from Amazon ECR."
              label="AWS Region"
              type="textBox"/>
      </server:property>
      <server:property name="awsCli" required="false">
          <server:property-ui
              placeholder="aws"
              description="Complete path of the AWS command line runtime file. Default: 'aws'"
              label="AWS Command Line File"
              type="textBox" />
      </server:property>
    </server:property-group>
</plugin>
