|
|
|
@ -8,7 +8,7 @@
|
|
|
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
|
|
|
|
<title>pylorax.api.v0 — Lorax 28.16 documentation</title>
|
|
|
|
|
<title>pylorax.api.v0 — Lorax 28.17 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -57,7 +57,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="version">
|
|
|
|
|
28.16
|
|
|
|
|
28.17
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -884,14 +884,14 @@
|
|
|
|
|
<span class="sd"> "id": "45502a6d-06e8-48a5-a215-2b4174b3614b",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "glusterfs",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "WAITING",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517362647.4570868,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517362647.4570868,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
|
|
|
<span class="sd"> },</span>
|
|
|
|
|
<span class="sd"> {</span>
|
|
|
|
|
<span class="sd"> "id": "6d292bd0-bec7-4825-8d7d-41ef9c3e4b73",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "kubernetes",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "WAITING",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517362659.0034983,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517362659.0034983,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.1"</span>
|
|
|
|
|
<span class="sd"> }</span>
|
|
|
|
|
<span class="sd"> ],</span>
|
|
|
|
@ -900,7 +900,8 @@
|
|
|
|
|
<span class="sd"> "id": "745712b2-96db-44c0-8014-fe925c35e795",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "glusterfs",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "RUNNING",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517362633.7965999,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517362633.7965999,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517362633.8001345,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
|
|
|
<span class="sd"> }</span>
|
|
|
|
|
<span class="sd"> ]</span>
|
|
|
|
@ -919,14 +920,18 @@
|
|
|
|
|
<span class="sd"> "id": "70b84195-9817-4b8a-af92-45e380f39894",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "glusterfs",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517351003.8210032,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517351003.8210032,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517351003.8230415,</span>
|
|
|
|
|
<span class="sd"> "job_finished": 1517359234.1003145,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
|
|
|
<span class="sd"> },</span>
|
|
|
|
|
<span class="sd"> {</span>
|
|
|
|
|
<span class="sd"> "id": "e695affd-397f-4af9-9022-add2636e7459",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "glusterfs",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517362289.7193348,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517362289.7193348,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517362289.9751132,</span>
|
|
|
|
|
<span class="sd"> "job_finished": 1517363500.1234567,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
|
|
|
<span class="sd"> }</span>
|
|
|
|
|
<span class="sd"> ]</span>
|
|
|
|
@ -945,7 +950,9 @@
|
|
|
|
|
<span class="sd"> "id": "8c8435ef-d6bd-4c68-9bf1-a2ef832e6b1a",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "http-server",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "FAILED",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517523249.9301329,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517523249.9301329,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517523249.9314211,</span>
|
|
|
|
|
<span class="sd"> "job_finished": 1517523255.5623411,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.2"</span>
|
|
|
|
|
<span class="sd"> }</span>
|
|
|
|
|
<span class="sd"> ]</span>
|
|
|
|
@ -964,14 +971,18 @@
|
|
|
|
|
<span class="sd"> "id": "8c8435ef-d6bd-4c68-9bf1-a2ef832e6b1a",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "http-server",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517523644.2384307,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517523644.2384307,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517523644.2551234,</span>
|
|
|
|
|
<span class="sd"> "job_finished": 1517523689.9864314,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.2"</span>
|
|
|
|
|
<span class="sd"> },</span>
|
|
|
|
|
<span class="sd"> {</span>
|
|
|
|
|
<span class="sd"> "id": "45502a6d-06e8-48a5-a215-2b4174b3614b",</span>
|
|
|
|
|
<span class="sd"> "blueprint": "glusterfs",</span>
|
|
|
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
|
|
|
<span class="sd"> "timestamp": 1517363442.188399,</span>
|
|
|
|
|
<span class="sd"> "job_created": 1517363442.188399,</span>
|
|
|
|
|
<span class="sd"> "job_started": 1517363442.325324,</span>
|
|
|
|
|
<span class="sd"> "job_finished": 1517363451.653621,</span>
|
|
|
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
|
|
|
<span class="sd"> }</span>
|
|
|
|
|
<span class="sd"> ]</span>
|
|
|
|
@ -1126,16 +1137,19 @@
|
|
|
|
|
<span class="kn">import</span> <span class="nn">pytoml</span> <span class="k">as</span> <span class="nn">toml</span>
|
|
|
|
|
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="k">import</span> <span class="n">joinpaths</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.checkparams</span> <span class="k">import</span> <span class="n">checkparams</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.compose</span> <span class="k">import</span> <span class="n">start_build</span><span class="p">,</span> <span class="n">compose_types</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.crossdomain</span> <span class="k">import</span> <span class="n">crossdomain</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.errors</span> <span class="k">import</span> <span class="o">*</span> <span class="c1"># pylint: disable=wildcard-import</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.projects</span> <span class="k">import</span> <span class="n">projects_list</span><span class="p">,</span> <span class="n">projects_info</span><span class="p">,</span> <span class="n">projects_depsolve</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.projects</span> <span class="k">import</span> <span class="n">modules_list</span><span class="p">,</span> <span class="n">modules_info</span><span class="p">,</span> <span class="n">ProjectsError</span><span class="p">,</span> <span class="n">repo_to_source</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.projects</span> <span class="k">import</span> <span class="n">get_repo_sources</span><span class="p">,</span> <span class="n">delete_repo_source</span><span class="p">,</span> <span class="n">source_to_repo</span><span class="p">,</span> <span class="n">dnf_repo_to_file_repo</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.queue</span> <span class="k">import</span> <span class="n">queue_status</span><span class="p">,</span> <span class="n">build_status</span><span class="p">,</span> <span class="n">uuid_delete</span><span class="p">,</span> <span class="n">uuid_status</span><span class="p">,</span> <span class="n">uuid_info</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.queue</span> <span class="k">import</span> <span class="n">uuid_tar</span><span class="p">,</span> <span class="n">uuid_image</span><span class="p">,</span> <span class="n">uuid_cancel</span><span class="p">,</span> <span class="n">uuid_log</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="k">import</span> <span class="n">list_branch_files</span><span class="p">,</span> <span class="n">read_recipe_commit</span><span class="p">,</span> <span class="n">recipe_filename</span><span class="p">,</span> <span class="n">list_commits</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="k">import</span> <span class="n">RecipeError</span><span class="p">,</span> <span class="n">list_branch_files</span><span class="p">,</span> <span class="n">read_recipe_commit</span><span class="p">,</span> <span class="n">recipe_filename</span><span class="p">,</span> <span class="n">list_commits</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="k">import</span> <span class="n">recipe_from_dict</span><span class="p">,</span> <span class="n">recipe_from_toml</span><span class="p">,</span> <span class="n">commit_recipe</span><span class="p">,</span> <span class="n">delete_recipe</span><span class="p">,</span> <span class="n">revert_recipe</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="k">import</span> <span class="n">tag_recipe_commit</span><span class="p">,</span> <span class="n">recipe_diff</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.regexes</span> <span class="k">import</span> <span class="n">VALID_API_STRING</span>
|
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.workspace</span> <span class="k">import</span> <span class="n">workspace_read</span><span class="p">,</span> <span class="n">workspace_write</span><span class="p">,</span> <span class="n">workspace_delete</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># The API functions don't actually get called by any code here</span>
|
|
|
|
@ -1154,6 +1168,15 @@
|
|
|
|
|
<span class="sd"> """</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">iterable</span><span class="p">[</span><span class="n">offset</span><span class="p">:][:</span><span class="n">limit</span><span class="p">]</span></div>
|
|
|
|
|
|
|
|
|
|
<div class="viewcode-block" id="blueprint_exists"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v0.blueprint_exists">[docs]</a><span class="k">def</span> <span class="nf">blueprint_exists</span><span class="p">(</span><span class="n">api</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">):</span>
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="kc">True</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">RecipeError</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="kc">False</span></div>
|
|
|
|
|
|
|
|
|
|
<div class="viewcode-block" id="v0_api"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v0.v0_api">[docs]</a><span class="k">def</span> <span class="nf">v0_api</span><span class="p">(</span><span class="n">api</span><span class="p">):</span>
|
|
|
|
|
<span class="c1"># Note that Sphinx will not generate documentations for any of these.</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/list"</span><span class="p">)</span>
|
|
|
|
@ -1161,22 +1184,36 @@
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_list</span><span class="p">():</span>
|
|
|
|
|
<span class="sd">"""List the available blueprints on a branch."""</span>
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"limit"</span><span class="p">,</span> <span class="s2">"20"</span><span class="p">))</span>
|
|
|
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"offset"</span><span class="p">,</span> <span class="s2">"0"</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_LIMIT_OR_OFFSET</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">([</span><span class="n">f</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">list_branch_files</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">)],</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">blueprints</span><span class="o">=</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">blueprints</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/info"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/info/<blueprint_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_info</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the contents of the blueprint, or a list of blueprints"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">out_fmt</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"format"</span><span class="p">,</span> <span class="s2">"json"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">out_fmt</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in format argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">changes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
@ -1202,7 +1239,7 @@
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">ws_blueprint</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">git_blueprint</span><span class="p">:</span>
|
|
|
|
|
<span class="c1"># Neither blueprint, return an error</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="s2">", "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">exceptions</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_BLUEPRINT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="s2">", "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">exceptions</span><span class="p">))})</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">ws_blueprint</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">git_blueprint</span><span class="p">:</span>
|
|
|
|
|
<span class="c1"># No git blueprint, return the workspace blueprint</span>
|
|
|
|
|
<span class="n">changes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"name"</span><span class="p">:</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="s2">"changed"</span><span class="p">:</span><span class="kc">True</span><span class="p">})</span>
|
|
|
|
@ -1219,7 +1256,6 @@
|
|
|
|
|
<span class="c1"># Sort all the results by case-insensitive blueprint name</span>
|
|
|
|
|
<span class="n">changes</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">changes</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="n">c</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="n">r</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">errors</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">out_fmt</span> <span class="o">==</span> <span class="s2">"toml"</span><span class="p">:</span>
|
|
|
|
|
<span class="c1"># With TOML output we just want to dump the raw blueprint, skipping the rest.</span>
|
|
|
|
@ -1227,32 +1263,44 @@
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">changes</span><span class="o">=</span><span class="n">changes</span><span class="p">,</span> <span class="n">blueprints</span><span class="o">=</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/changes"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/changes/<blueprint_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_changes</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the changes to a blueprint or list of blueprints"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"limit"</span><span class="p">,</span> <span class="s2">"20"</span><span class="p">))</span>
|
|
|
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"offset"</span><span class="p">,</span> <span class="s2">"0"</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_LIMIT_OR_OFFSET</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">blueprint_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">blueprint_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)]:</span>
|
|
|
|
|
<span class="n">filename</span> <span class="o">=</span> <span class="n">recipe_filename</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">blueprint_exists</span><span class="p">(</span><span class="n">api</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">):</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_BLUEPRINT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Unknown blueprint name: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">blueprint_name</span><span class="p">})</span>
|
|
|
|
|
<span class="k">continue</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">commits</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">list_commits</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_changes) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprints</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"name"</span><span class="p">:</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="s2">"changes"</span><span class="p">:</span><span class="n">commits</span><span class="p">,</span> <span class="s2">"total"</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">commits</span><span class="p">)})</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="n">r</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">errors</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">blueprints</span><span class="o">=</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1261,12 +1309,18 @@
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_new</span><span class="p">():</span>
|
|
|
|
|
<span class="sd">"""Commit a new blueprint"""</span>
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">'Content-Type'</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"text/x-toml"</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">recipe_from_toml</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">recipe_from_dict</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">get_json</span><span class="p">(</span><span class="n">cache</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">"name"</span><span class="p">])</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">commit_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1275,21 +1329,29 @@
|
|
|
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_new) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/delete"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/delete/<blueprint_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint name given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_delete</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Delete a blueprint from git"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">delete_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_delete) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1298,39 +1360,63 @@
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_workspace</span><span class="p">():</span>
|
|
|
|
|
<span class="sd">"""Write a blueprint to the workspace"""</span>
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">'Content-Type'</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"text/x-toml"</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">recipe_from_toml</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">recipe_from_dict</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">get_json</span><span class="p">(</span><span class="n">cache</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">"name"</span><span class="p">])</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_workspace) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/workspace"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/workspace/<blueprint_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint name given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_delete_workspace</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Delete a blueprint from the workspace"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">workspace_delete</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_delete_workspace) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/undo"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span> <span class="s1">'commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"POST"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/undo/<blueprint_name>"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"POST"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/undo/<blueprint_name>/<commit>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"POST"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint name given"</span><span class="p">),</span>
|
|
|
|
|
<span class="p">(</span><span class="s2">"commit"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no commit ID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_undo</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Undo changes to a blueprint by reverting to a previous commit."""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">revert_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">)</span>
|
|
|
|
@ -1340,29 +1426,50 @@
|
|
|
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_undo) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_COMMIT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/tag"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"POST"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/tag/<blueprint_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"POST"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint name given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_tag</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Tag a blueprint's latest blueprint commit as a 'revision'"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">tag_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_tag) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/diff"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span> <span class="s1">'from_commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span> <span class="s1">'to_commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/diff/<blueprint_name>"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'from_commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">,</span> <span class="s1">'to_commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/diff/<blueprint_name>/<from_commit>"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'to_commit'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/diff/<blueprint_name>/<from_commit>/<to_commit>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint name given"</span><span class="p">),</span>
|
|
|
|
|
<span class="p">(</span><span class="s2">"from_commit"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no from commit ID given"</span><span class="p">),</span>
|
|
|
|
|
<span class="p">(</span><span class="s2">"to_commit"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no to commit ID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_diff</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="n">from_commit</span><span class="p">,</span> <span class="n">to_commit</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the differences between two commits of a blueprint"""</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="p">[</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="n">from_commit</span><span class="p">,</span> <span class="n">to_commit</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">from_commit</span> <span class="o">==</span> <span class="s2">"NEWEST"</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
@ -1372,7 +1479,7 @@
|
|
|
|
|
<span class="n">old_blueprint</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">,</span> <span class="n">from_commit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_diff) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_COMMIT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">to_commit</span> <span class="o">==</span> <span class="s2">"WORKSPACE"</span><span class="p">:</span>
|
|
|
|
@ -1390,17 +1497,28 @@
|
|
|
|
|
<span class="n">new_blueprint</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">,</span> <span class="n">to_commit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_diff) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_COMMIT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">diff</span> <span class="o">=</span> <span class="n">recipe_diff</span><span class="p">(</span><span class="n">old_blueprint</span><span class="p">,</span> <span class="n">new_blueprint</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">diff</span><span class="o">=</span><span class="n">diff</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/freeze"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/freeze/<blueprint_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_freeze</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the blueprint with the exact modules and packages selected by depsolve"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">out_fmt</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"format"</span><span class="p">,</span> <span class="s2">"json"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">out_fmt</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in format argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">blueprint_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">blueprint_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())]:</span>
|
|
|
|
@ -1419,12 +1537,12 @@
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_freeze) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># No blueprint found, skip it.</span>
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">blueprint</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: blueprint_not_found"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_BLUEPRINT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: blueprint_not_found"</span> <span class="o">%</span> <span class="n">blueprint_name</span><span class="p">})</span>
|
|
|
|
|
<span class="k">continue</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Combine modules and packages and depsolve the list</span>
|
|
|
|
@ -1437,7 +1555,7 @@
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">blueprint</span><span class="o">.</span><span class="n">group_names</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_freeze) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"blueprint"</span><span class="p">:</span> <span class="n">blueprint</span><span class="o">.</span><span class="n">freeze</span><span class="p">(</span><span class="n">deps</span><span class="p">)})</span>
|
|
|
|
@ -1448,11 +1566,19 @@
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">blueprints</span><span class="o">=</span><span class="n">blueprints</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/depsolve"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'blueprint_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/blueprints/depsolve/<blueprint_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"blueprint_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no blueprint names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_blueprints_depsolve</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the dependencies for a blueprint"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"branch"</span><span class="p">,</span> <span class="s2">"master"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">branch</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in branch argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">blueprints</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">blueprint_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">blueprint_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())]:</span>
|
|
|
|
@ -1471,12 +1597,12 @@
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_depsolve) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># No blueprint found, skip it.</span>
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">blueprint</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: blueprint not found"</span> <span class="o">%</span> <span class="n">blueprint_name</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_BLUEPRINT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: blueprint not found"</span> <span class="o">%</span> <span class="n">blueprint_name</span><span class="p">})</span>
|
|
|
|
|
<span class="k">continue</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Combine modules and packages and depsolve the list</span>
|
|
|
|
@ -1489,7 +1615,7 @@
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">blueprint</span><span class="o">.</span><span class="n">group_names</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BLUEPRINTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint_name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_blueprints_depsolve) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Get the NEVRA's of the modules and projects, add as "modules"</span>
|
|
|
|
@ -1511,41 +1637,61 @@
|
|
|
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"limit"</span><span class="p">,</span> <span class="s2">"20"</span><span class="p">))</span>
|
|
|
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"offset"</span><span class="p">,</span> <span class="s2">"0"</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_LIMIT_OR_OFFSET</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">available</span> <span class="o">=</span> <span class="n">projects_list</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_list) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">PROJECTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">available</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">projects</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">available</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/info"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'project_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/info/<project_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"project_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no project names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_projects_info</span><span class="p">(</span><span class="n">project_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return detailed information about the listed projects"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">project_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="n">projects_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="n">project_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_info) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">PROJECTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">projects</span><span class="p">:</span>
|
|
|
|
|
<span class="n">msg</span> <span class="o">=</span> <span class="s2">"one of the requested projects does not exist: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">project_names</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_info) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_PROJECT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="n">msg</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">projects</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/depsolve"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'project_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/depsolve/<project_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"project_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no project names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_projects_depsolve</span><span class="p">(</span><span class="n">project_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return detailed information about the listed projects"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">project_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="p">[(</span><span class="n">n</span><span class="p">,</span> <span class="s2">"*"</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">project_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)],</span> <span class="p">[])</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_depsolve) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">PROJECTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">deps</span><span class="p">:</span>
|
|
|
|
|
<span class="n">msg</span> <span class="o">=</span> <span class="s2">"one of the requested projects does not exist: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">project_names</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_depsolve) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_PROJECT</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="n">msg</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">deps</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1558,11 +1704,18 @@
|
|
|
|
|
<span class="n">sources</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">r</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">repos</span><span class="p">])</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">sources</span><span class="o">=</span><span class="n">sources</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/source/info"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'source_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/source/info/<source_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"source_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no source names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_projects_source_info</span><span class="p">(</span><span class="n">source_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return detailed info about the list of sources"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">source_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">out_fmt</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"format"</span><span class="p">,</span> <span class="s2">"json"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">out_fmt</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in format argument"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Return info on all of the sources</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">source_names</span> <span class="o">==</span> <span class="s2">"*"</span><span class="p">:</span>
|
|
|
|
@ -1576,7 +1729,7 @@
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">repo</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">repo</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid source"</span> <span class="o">%</span> <span class="n">source</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_SOURCE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid source"</span> <span class="o">%</span> <span class="n">source</span><span class="p">})</span>
|
|
|
|
|
<span class="k">continue</span>
|
|
|
|
|
<span class="n">sources</span><span class="p">[</span><span class="n">repo</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">repo_to_source</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">repo</span><span class="o">.</span><span class="n">id</span> <span class="ow">in</span> <span class="n">system_sources</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1600,7 +1753,7 @@
|
|
|
|
|
|
|
|
|
|
<span class="n">system_sources</span> <span class="o">=</span> <span class="n">get_repo_sources</span><span class="p">(</span><span class="s2">"/etc/yum.repos.d/*.repo"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">source</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]</span> <span class="ow">in</span> <span class="n">system_sources</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is a system source, it cannot be changed."</span> <span class="o">%</span> <span class="n">source</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">SYSTEM_SOURCE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is a system source, it cannot be changed."</span> <span class="o">%</span> <span class="n">source</span><span class="p">[</span><span class="s2">"name"</span><span class="p">]}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="c1"># Remove it from the RepoDict (NOTE that this isn't explicitly supported by the DNF API)</span>
|
|
|
|
@ -1645,17 +1798,22 @@
|
|
|
|
|
<span class="n">dbo</span><span class="o">.</span><span class="n">fill_sack</span><span class="p">(</span><span class="n">load_system_repo</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
|
|
|
|
<span class="n">dbo</span><span class="o">.</span><span class="n">read_comps</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">PROJECTS_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/source/delete"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'source_name'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/projects/source/delete/<source_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"source_name"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no source name given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_projects_source_delete</span><span class="p">(</span><span class="n">source_name</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Delete the named source and return a status response"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">source_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">system_sources</span> <span class="o">=</span> <span class="n">get_repo_sources</span><span class="p">(</span><span class="s2">"/etc/yum.repos.d/*.repo"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">source_name</span> <span class="ow">in</span> <span class="n">system_sources</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is a system source, it cannot be deleted."</span> <span class="o">%</span> <span class="n">source_name</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">SYSTEM_SOURCE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is a system source, it cannot be deleted."</span> <span class="o">%</span> <span class="n">source_name</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="n">share_dir</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"composer"</span><span class="p">,</span> <span class="s2">"repo_dir"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="c1"># Remove the file entry for the source</span>
|
|
|
|
@ -1671,7 +1829,7 @@
|
|
|
|
|
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_projects_source_delete) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_SOURCE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1680,11 +1838,14 @@
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_modules_list</span><span class="p">(</span><span class="n">module_names</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""List available modules, filtering by module_names"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">module_names</span> <span class="ow">and</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">module_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"limit"</span><span class="p">,</span> <span class="s2">"20"</span><span class="p">))</span>
|
|
|
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"offset"</span><span class="p">,</span> <span class="s2">"0"</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_LIMIT_OR_OFFSET</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">module_names</span><span class="p">:</span>
|
|
|
|
|
<span class="n">module_names</span> <span class="o">=</span> <span class="n">module_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span>
|
|
|
|
@ -1694,21 +1855,35 @@
|
|
|
|
|
<span class="n">available</span> <span class="o">=</span> <span class="n">modules_list</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="n">module_names</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_modules_list) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">MODULES_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">module_names</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">available</span><span class="p">:</span>
|
|
|
|
|
<span class="n">msg</span> <span class="o">=</span> <span class="s2">"one of the requested modules does not exist: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">module_names</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_modules_list) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_MODULE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="n">msg</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">available</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">modules</span><span class="o">=</span><span class="n">modules</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">available</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/modules/info"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'module_names'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/modules/info/<module_names>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"module_names"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no module names given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_modules_info</span><span class="p">(</span><span class="n">module_names</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return detailed information about the listed modules"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">module_names</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
|
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="n">modules_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">dbo</span><span class="p">,</span> <span class="n">module_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_modules_info) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">MODULES_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">modules</span><span class="p">:</span>
|
|
|
|
|
<span class="n">msg</span> <span class="o">=</span> <span class="s2">"one of the requested modules does not exist: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">module_names</span>
|
|
|
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"(v0_modules_info) </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_MODULE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="n">msg</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">modules</span><span class="o">=</span><span class="n">modules</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1733,10 +1908,10 @@
|
|
|
|
|
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">compose</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Missing POST body"</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">MISSING_POST</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Missing POST body"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="s2">"blueprint_name"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">compose</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"No 'blueprint_name' in the JSON request"</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_BLUEPRINT</span><span class="p">,</span><span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"No 'blueprint_name' in the JSON request"</span><span class="p">})</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">blueprint_name</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s2">"blueprint_name"</span><span class="p">]</span>
|
|
|
|
|
|
|
|
|
@ -1746,10 +1921,13 @@
|
|
|
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s2">"branch"</span><span class="p">]</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="s2">"compose_type"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">compose</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"No 'compose_type' in the JSON request"</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_COMPOSE_TYPE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"No 'compose_type' in the JSON request"</span><span class="p">})</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">compose_type</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s2">"compose_type"</span><span class="p">]</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">})</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">errors</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
@ -1757,7 +1935,10 @@
|
|
|
|
|
<span class="n">build_id</span> <span class="o">=</span> <span class="n">start_build</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"DNFLOCK"</span><span class="p">],</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"GITLOCK"</span><span class="p">],</span>
|
|
|
|
|
<span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">,</span> <span class="n">compose_type</span><span class="p">,</span> <span class="n">test_mode</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">if</span> <span class="s2">"Invalid compose type"</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">):</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BAD_COMPOSE_TYPE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_FAILED</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">build_id</span><span class="o">=</span><span class="n">build_id</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
@ -1789,152 +1970,203 @@
|
|
|
|
|
<span class="sd">"""Return the list of failed composes"""</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">failed</span><span class="o">=</span><span class="n">build_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="s2">"FAILED"</span><span class="p">))</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/status"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuids'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/status/<uuids>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuids"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUIDs given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_status</span><span class="p">(</span><span class="n">uuids</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the status of the listed uuids"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuids</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">uuid</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">uuids</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)]:</span>
|
|
|
|
|
<span class="n">details</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">details</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">details</span><span class="p">)</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">})</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">uuids</span><span class="o">=</span><span class="n">results</span><span class="p">)</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">uuids</span><span class="o">=</span><span class="n">results</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/cancel"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/cancel/<uuid>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_cancel</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Cancel a running compose and delete its results directory"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"WAITING"</span><span class="p">,</span> <span class="s2">"RUNNING"</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is not in WAITING or RUNNING."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">])</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is not in WAITING or RUNNING."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}])</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">uuid_cancel</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">COMPOSE_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))}]),</span><span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/delete"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuids'</span><span class="p">:</span> <span class="s2">""</span><span class="p">},</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/delete/<uuids>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s2">"DELETE"</span><span class="p">])</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuids"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUIDs given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_delete</span><span class="p">(</span><span class="n">uuids</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Delete the compose results for the listed uuids"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuids</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
|
|
|
<span class="k">for</span> <span class="n">uuid</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">uuids</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)]:</span>
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">})</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"FINISHED"</span><span class="p">,</span> <span class="s2">"FAILED"</span><span class="p">]:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is not in FINISHED or FAILED."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is not in FINISHED or FAILED."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">})</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">uuid_delete</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
|
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">COMPOSE_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))})</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">"uuid"</span><span class="p">:</span><span class="n">uuid</span><span class="p">,</span> <span class="s2">"status"</span><span class="p">:</span><span class="kc">True</span><span class="p">})</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">uuids</span><span class="o">=</span><span class="n">results</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/info"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/info/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_info</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return detailed info about a compose"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">info</span> <span class="o">=</span> <span class="n">uuid_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">COMPOSE_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="o">**</span><span class="n">info</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">info</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="o">**</span><span class="n">info</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/metadata"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/metadata/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_metadata</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return a tar of the metadata for the build"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"FINISHED"</span><span class="p">,</span> <span class="s2">"FAILED"</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span>
|
|
|
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s2">"application/x-tar"</span><span class="p">,</span>
|
|
|
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s2">"Content-Disposition"</span><span class="p">,</span> <span class="s2">"attachment; filename=</span><span class="si">%s</span><span class="s2">-metadata.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
|
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/results"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/results/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_results</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return a tar of the metadata and the results for the build"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"FINISHED"</span><span class="p">,</span> <span class="s2">"FAILED"</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
|
|
|
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s2">"application/x-tar"</span><span class="p">,</span>
|
|
|
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s2">"Content-Disposition"</span><span class="p">,</span> <span class="s2">"attachment; filename=</span><span class="si">%s</span><span class="s2">.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
|
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/logs"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/logs/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_logs</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return a tar of the metadata for the build"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"FINISHED"</span><span class="p">,</span> <span class="s2">"FAILED"</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
|
|
|
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s2">"application/x-tar"</span><span class="p">,</span>
|
|
|
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s2">"Content-Disposition"</span><span class="p">,</span> <span class="s2">"attachment; filename=</span><span class="si">%s</span><span class="s2">-logs.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
|
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/image"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/image/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_image</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the output image for the build"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">"FINISHED"</span><span class="p">,</span> <span class="s2">"FAILED"</span><span class="p">]:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> not in FINISHED or FAILED state."</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">else</span><span class="p">:</span>
|
|
|
|
|
<span class="n">image_name</span><span class="p">,</span> <span class="n">image_path</span> <span class="o">=</span> <span class="n">uuid_image</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Make sure it really exists</span>
|
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">image_path</span><span class="p">):</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is missing image file </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="n">image_name</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_MISSING_FILE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> is missing image file </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">uuid</span><span class="p">,</span> <span class="n">image_name</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Make the image name unique</span>
|
|
|
|
|
<span class="n">image_name</span> <span class="o">=</span> <span class="n">uuid</span> <span class="o">+</span> <span class="s2">"-"</span> <span class="o">+</span> <span class="n">image_name</span>
|
|
|
|
|
<span class="c1"># XXX - Will mime type guessing work for all our output?</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">send_file</span><span class="p">(</span><span class="n">image_path</span><span class="p">,</span> <span class="n">as_attachment</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">attachment_filename</span><span class="o">=</span><span class="n">image_name</span><span class="p">,</span> <span class="n">add_etags</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/log"</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">'uuid'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
|
|
|
|
<span class="nd">@api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/api/v0/compose/log/<uuid>"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s2">"*"</span><span class="p">)</span>
|
|
|
|
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"uuid"</span><span class="p">,</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"no UUID given"</span><span class="p">)])</span>
|
|
|
|
|
<span class="k">def</span> <span class="nf">v0_compose_log_tail</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
|
|
|
<span class="sd">"""Return the end of the main anaconda.log, defaults to 1Mbytes"""</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">VALID_API_STRING</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Invalid characters in API path"</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="n">size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"size"</span><span class="p">,</span> <span class="s2">"1024"</span><span class="p">))</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">COMPOSE_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span>
|
|
|
|
|
|
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">UNKNOWN_UUID</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}]),</span> <span class="mi">400</span>
|
|
|
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s2">"queue_status"</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"WAITING"</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="s2">"Build </span><span class="si">%s</span><span class="s2"> has not started yet. No logs to view"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">])</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">BUILD_IN_WRONG_STATE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"Build </span><span class="si">%s</span><span class="s2"> has not started yet. No logs to view"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">}])</span>
|
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_log</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">size</span><span class="p">),</span> <span class="n">direct_passthrough</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|
|
|
|
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)]),</span> <span class="mi">400</span></div>
|
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span><span class="s2">"id"</span><span class="p">:</span> <span class="n">COMPOSE_ERROR</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}]),</span> <span class="mi">400</span></div>
|
|
|
|
|
</pre></div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
@ -1969,7 +2201,7 @@
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
var DOCUMENTATION_OPTIONS = {
|
|
|
|
|
URL_ROOT:'../../../',
|
|
|
|
|
VERSION:'28.16',
|
|
|
|
|
VERSION:'28.17',
|
|
|
|
|
LANGUAGE:'None',
|
|
|
|
|
COLLAPSE_INDEX:false,
|
|
|
|
|
FILE_SUFFIX:'.html',
|
|
|
|
|