From 764816a76ff0ce2418473feb7be4e43d9087987a Mon Sep 17 00:00:00 2001
From: Aki Sasaki <aki@mozilla.com>
Date: Mon, 4 May 2020 09:25:54 -0700
Subject: [PATCH] bug 1594621 - add cot_product_type map (#454)

* fix cot verify for adhoc

* cot_product_type

* add coverage

* 34.1.0
---
 HISTORY.rst                    | 18 ++++++++++++++++++
 src/scriptworker/constants.py  | 16 ++++++++++++++++
 src/scriptworker/cot/verify.py | 12 ++++++++----
 src/scriptworker/version.py    |  2 +-
 tests/test_cot_verify.py       |  3 +++
 version.json                   |  4 ++--
 6 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/HISTORY.rst b/HISTORY.rst
index f2622d55..e8278c91 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,24 @@ Change Log
 All notable changes to this project will be documented in this file.
 This project adheres to `Semantic Versioning <http://semver.org/>`__.
 
+[34.1.0] - 2020-05-04
+---------------------
+
+Added
+~~~~~
+- added ``cot_product_type``
+
+Changed
+~~~~~~~
+- ``populate_jsone_context`` now checks ``cot_product_type`` instead of allowlisting a set of ``cot_products`` as github
+
+Changed
+~~~~~~~
+- ``check_interactive_docker_worker`` now raises ``CoTError`` on errors, rather
+    than returning the list of error messages
+- ``check_interactive_docker_worker`` now also runs against the chain task, if it's
+    docker-worker
+
 [34.0.0] - 2020-04-17
 ---------------------
 
diff --git a/src/scriptworker/constants.py b/src/scriptworker/constants.py
index 1fd6f3b3..781884b9 100644
--- a/src/scriptworker/constants.py
+++ b/src/scriptworker/constants.py
@@ -111,6 +111,22 @@
         "scriptworker_provisioners": ("scriptworker-prov-v1", "scriptworker-k8s"),
         # valid hash algorithms for chain of trust artifacts
         "valid_hash_algorithms": ("sha256", "sha512"),
+        "cot_product_type": immutabledict(
+            {
+                "by-cot-product": immutabledict(
+                    {
+                        "firefox": "hg",
+                        "thunderbird": "hg",
+                        "mobile": "github",
+                        "mpd001": "github",
+                        "application-services": "github",
+                        "xpi": "github",
+                        "adhoc": "github",
+                        "scriptworker": "github",
+                    },
+                ),
+            },
+        ),
         # decision task cot
         "valid_decision_worker_pools": immutabledict(
             {
diff --git a/src/scriptworker/cot/verify.py b/src/scriptworker/cot/verify.py
index 30c61d2b..ec8acd58 100644
--- a/src/scriptworker/cot/verify.py
+++ b/src/scriptworker/cot/verify.py
@@ -1239,7 +1239,7 @@ async def populate_jsone_context(chain, parent_link, decision_link, tasks_for):
         "taskId": None,
     }
 
-    if chain.context.config["cot_product"] in ("mobile", "mpd001", "application-services", "xpi"):
+    if chain.context.config["cot_product_type"] == "github":
         if tasks_for == "github-release":
             jsone_context.update(await _get_additional_github_releases_jsone_context(decision_link))
         elif tasks_for == "cron":
@@ -1251,8 +1251,8 @@ async def populate_jsone_context(chain, parent_link, decision_link, tasks_for):
         elif tasks_for == "github-push":
             jsone_context.update(await _get_additional_github_push_jsone_context(decision_link))
         else:
-            raise CoTError('Unknown tasks_for "{}" for cot_product "{}"!'.format(tasks_for, chain.context.config["cot_product"]))
-    else:
+            raise CoTError('Unknown tasks_for "{}" for github cot_product "{}"!'.format(tasks_for, chain.context.config["cot_product"]))
+    elif chain.context.config["cot_product_type"] == "hg":
         source_url = get_source_url(decision_link)
         project = await get_project(chain.context, source_url)
         jsone_context["repository"] = {
@@ -1268,7 +1268,11 @@ async def populate_jsone_context(chain, parent_link, decision_link, tasks_for):
         elif tasks_for == "cron":
             jsone_context.update(await _get_additional_hg_cron_jsone_context(parent_link, decision_link))
         else:
-            raise CoTError("Unknown tasks_for {}!".format(tasks_for))
+            raise CoTError('Unknown tasks_for "{}" for hg cot_product "{}"!'.format(tasks_for, chain.context.config["cot_product"]))
+    else:
+        raise CoTError(
+            'Unknown cot_product_type "{}" for cot_product "{}"!'.format(chain.context.config["cot_product_type"], chain.context.config["cot_product"])
+        )
 
     log.debug("{} json-e context:".format(parent_link.name))
     # format_json() breaks on lambda values; use pprint.pformat here.
diff --git a/src/scriptworker/version.py b/src/scriptworker/version.py
index 787b75c8..8a97d8f2 100755
--- a/src/scriptworker/version.py
+++ b/src/scriptworker/version.py
@@ -54,7 +54,7 @@ def get_version_string(version: Union[ShortVerType, LongVerType]) -> str:
 
 # 1}}}
 # Semantic versioning 2.0.0  http://semver.org/
-__version__ = (34, 0, 0)
+__version__ = (34, 1, 0)
 __version_string__ = get_version_string(__version__)
 
 
diff --git a/tests/test_cot_verify.py b/tests/test_cot_verify.py
index 12186761..2aac5748 100644
--- a/tests/test_cot_verify.py
+++ b/tests/test_cot_verify.py
@@ -1270,6 +1270,9 @@ async def get_pull_request_mock(pull_request_number, *args, **kwargs):
 async def test_populate_jsone_context_fail(mobile_chain, mobile_github_release_link):
     with pytest.raises(CoTError):
         await cotverify.populate_jsone_context(mobile_chain, mobile_github_release_link, mobile_github_release_link, tasks_for="bad-tasks-for")
+    mobile_chain.context.config["cot_product_type"] = "bad-cot-product-type"
+    with pytest.raises(CoTError):
+        await cotverify.populate_jsone_context(mobile_chain, mobile_github_release_link, mobile_github_release_link, tasks_for="github-push")
 
 
 @pytest.mark.asyncio
diff --git a/version.json b/version.json
index c9b81034..3da46ca0 100644
--- a/version.json
+++ b/version.json
@@ -1,8 +1,8 @@
 {
     "version":[
         34,
-        0,
+        1,
         0
     ],
-    "version_string":"34.0.0"
+    "version_string":"34.1.0"
 }