368 lines
27 KiB
HTML
368 lines
27 KiB
HTML
|
|
||
|
|
||
|
<!DOCTYPE html>
|
||
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
||
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
||
|
<title>pylorax.api.v1 — Lorax 31.10 documentation</title>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
|
||
|
|
||
|
|
||
|
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
|
||
|
<script type="text/javascript" src="../../../_static/jquery.js"></script>
|
||
|
<script type="text/javascript" src="../../../_static/underscore.js"></script>
|
||
|
<script type="text/javascript" src="../../../_static/doctools.js"></script>
|
||
|
<script type="text/javascript" src="../../../_static/language_data.js"></script>
|
||
|
|
||
|
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
|
||
|
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
|
||
|
<link rel="index" title="Index" href="../../../genindex.html" />
|
||
|
<link rel="search" title="Search" href="../../../search.html" />
|
||
|
</head>
|
||
|
|
||
|
<body class="wy-body-for-nav">
|
||
|
|
||
|
|
||
|
<div class="wy-grid-for-nav">
|
||
|
|
||
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
|
<div class="wy-side-scroll">
|
||
|
<div class="wy-side-nav-search" >
|
||
|
|
||
|
|
||
|
|
||
|
<a href="../../../index.html" class="icon icon-home"> Lorax
|
||
|
|
||
|
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="version">
|
||
|
31.10
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div role="search">
|
||
|
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
|
||
|
<input type="text" name="q" placeholder="Search docs" />
|
||
|
<input type="hidden" name="check_keywords" value="yes" />
|
||
|
<input type="hidden" name="area" value="default" />
|
||
|
</form>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<ul>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
|
||
|
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
|
||
|
</ul>
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</nav>
|
||
|
|
||
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
|
||
|
|
||
|
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
|
||
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
|
<a href="../../../index.html">Lorax</a>
|
||
|
|
||
|
</nav>
|
||
|
|
||
|
|
||
|
<div class="wy-nav-content">
|
||
|
|
||
|
<div class="rst-content">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
|
||
|
<ul class="wy-breadcrumbs">
|
||
|
|
||
|
<li><a href="../../../index.html">Docs</a> »</li>
|
||
|
|
||
|
<li><a href="../../index.html">Module code</a> »</li>
|
||
|
|
||
|
<li><a href="../../pylorax.html">pylorax</a> »</li>
|
||
|
|
||
|
<li>pylorax.api.v1</li>
|
||
|
|
||
|
|
||
|
<li class="wy-breadcrumbs-aside">
|
||
|
|
||
|
</li>
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
|
||
|
<hr/>
|
||
|
</div>
|
||
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
|
<div itemprop="articleBody">
|
||
|
|
||
|
<h1>Source code for pylorax.api.v1</h1><div class="highlight"><pre>
|
||
|
<span></span><span class="c1">#</span>
|
||
|
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
|
||
|
<span class="c1">#</span>
|
||
|
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
|
||
|
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
|
||
|
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
|
||
|
<span class="c1"># (at your option) any later version.</span>
|
||
|
<span class="c1">#</span>
|
||
|
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
|
||
|
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
||
|
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
||
|
<span class="c1"># GNU General Public License for more details.</span>
|
||
|
<span class="c1">#</span>
|
||
|
<span class="c1"># You should have received a copy of the GNU General Public License</span>
|
||
|
<span class="c1"># along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
|
||
|
<span class="c1">#</span>
|
||
|
<span class="sd">""" Setup v1 of the API server</span>
|
||
|
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="kn">import</span> <span class="nn">logging</span>
|
||
|
<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">"lorax-composer"</span><span class="p">)</span>
|
||
|
|
||
|
<span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">jsonify</span><span class="p">,</span> <span class="n">request</span>
|
||
|
<span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">current_app</span> <span class="k">as</span> <span class="n">api</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.errors</span> <span class="k">import</span> <span class="n">INVALID_CHARS</span><span class="p">,</span> <span class="n">PROJECTS_ERROR</span><span class="p">,</span> <span class="n">SYSTEM_SOURCE</span><span class="p">,</span> <span class="n">UNKNOWN_SOURCE</span>
|
||
|
<span class="kn">from</span> <span class="nn">pylorax.api.flask_blueprint</span> <span class="k">import</span> <span class="n">BlueprintSkip</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">new_repo_source</span><span class="p">,</span> <span class="n">repo_to_source</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">import</span> <span class="nn">pylorax.api.toml</span> <span class="k">as</span> <span class="nn">toml</span>
|
||
|
|
||
|
<span class="c1"># Create the v1 routes Blueprint with skip_routes support</span>
|
||
|
<span class="n">v1_api</span> <span class="o">=</span> <span class="n">BlueprintSkip</span><span class="p">(</span><span class="s2">"v1_routes"</span><span class="p">,</span> <span class="vm">__name__</span><span class="p">)</span>
|
||
|
|
||
|
<div class="viewcode-block" id="v1_projects_source_info"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v1.v1_projects_source_info">[docs]</a><span class="nd">@v1_api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/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_ids'</span><span class="p">:</span> <span class="s2">""</span><span class="p">})</span>
|
||
|
<span class="nd">@v1_api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/projects/source/info/<source_ids>"</span><span class="p">)</span>
|
||
|
<span class="nd">@checkparams</span><span class="p">([(</span><span class="s2">"source_ids"</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">v1_projects_source_info</span><span class="p">(</span><span class="n">source_ids</span><span class="p">):</span>
|
||
|
<span class="sd">"""Return detailed info about the list of sources</span>
|
||
|
|
||
|
<span class="sd"> **/api/v1/projects/source/info/<source-ids>**</span>
|
||
|
|
||
|
<span class="sd"> Return information about the comma-separated list of source ids. Or all of the</span>
|
||
|
<span class="sd"> sources if '*' is passed. Note that general globbing is not supported, only '*'.</span>
|
||
|
|
||
|
<span class="sd"> Immutable system sources will have the "system" field set to true. User added sources</span>
|
||
|
<span class="sd"> will have it set to false. System sources cannot be changed or deleted.</span>
|
||
|
|
||
|
<span class="sd"> Example::</span>
|
||
|
|
||
|
<span class="sd"> {</span>
|
||
|
<span class="sd"> "errors": [],</span>
|
||
|
<span class="sd"> "sources": {</span>
|
||
|
<span class="sd"> "fedora": {</span>
|
||
|
<span class="sd"> "check_gpg": true,</span>
|
||
|
<span class="sd"> "check_ssl": true,</span>
|
||
|
<span class="sd"> "gpgkey_urls": [</span>
|
||
|
<span class="sd"> "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-28-x86_64"</span>
|
||
|
<span class="sd"> ],</span>
|
||
|
<span class="sd"> "id": "fedora",</span>
|
||
|
<span class="sd"> "name": "Fedora $releasever - $basearch",</span>
|
||
|
<span class="sd"> "proxy": "http://proxy.brianlane.com:8123",</span>
|
||
|
<span class="sd"> "system": true,</span>
|
||
|
<span class="sd"> "type": "yum-metalink",</span>
|
||
|
<span class="sd"> "url": "https://mirrors.fedoraproject.org/metalink?repo=fedora-28&arch=x86_64"</span>
|
||
|
<span class="sd"> }</span>
|
||
|
<span class="sd"> }</span>
|
||
|
<span class="sd"> }</span>
|
||
|
|
||
|
<span class="sd"> In v0 the ``name`` field was used for the id (a short name for the repo). In v1 ``name`` changed</span>
|
||
|
<span class="sd"> to ``id`` and ``name`` is now used for the longer descriptive name of the repository.</span>
|
||
|
<span class="sd"> """</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_ids</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_ids</span> <span class="o">==</span> <span class="s2">"*"</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">source_ids</span> <span class="o">=</span> <span class="s2">","</span><span class="o">.</span><span class="n">join</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">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">iter_enabled</span><span class="p">())</span>
|
||
|
|
||
|
<span class="n">sources</span> <span class="o">=</span> <span class="p">{}</span>
|
||
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</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">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">source_ids</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">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">"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> <span class="n">api</span><span class="o">=</span><span class="mi">1</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="ow">and</span> <span class="ow">not</span> <span class="n">errors</span><span class="p">:</span>
|
||
|
<span class="c1"># With TOML output we just want to dump the raw sources, skipping the errors</span>
|
||
|
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">sources</span><span class="p">)</span>
|
||
|
<span class="k">elif</span> <span class="n">out_fmt</span> <span class="o">==</span> <span class="s2">"toml"</span> <span class="ow">and</span> <span class="n">errors</span><span class="p">:</span>
|
||
|
<span class="c1"># TOML requested, but there was an error</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>
|
||
|
<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">sources</span><span class="o">=</span><span class="n">sources</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span></div>
|
||
|
|
||
|
<div class="viewcode-block" id="v1_projects_source_new"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v1.v1_projects_source_new">[docs]</a><span class="nd">@v1_api</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">"/projects/source/new"</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="k">def</span> <span class="nf">v1_projects_source_new</span><span class="p">():</span>
|
||
|
<span class="sd">"""Add a new package source. Or change an existing one</span>
|
||
|
|
||
|
<span class="sd"> **POST /api/v0/projects/source/new**</span>
|
||
|
|
||
|
<span class="sd"> Add (or change) a source for use when depsolving blueprints and composing images.</span>
|
||
|
|
||
|
<span class="sd"> The ``proxy`` and ``gpgkey_urls`` entries are optional. All of the others are required. The supported</span>
|
||
|
<span class="sd"> types for the urls are:</span>
|
||
|
|
||
|
<span class="sd"> * ``yum-baseurl`` is a URL to a yum repository.</span>
|
||
|
<span class="sd"> * ``yum-mirrorlist`` is a URL for a mirrorlist.</span>
|
||
|
<span class="sd"> * ``yum-metalink`` is a URL for a metalink.</span>
|
||
|
|
||
|
<span class="sd"> If ``check_ssl`` is true the https certificates must be valid. If they are self-signed you can either set</span>
|
||
|
<span class="sd"> this to false, or add your Certificate Authority to the host system.</span>
|
||
|
|
||
|
<span class="sd"> If ``check_gpg`` is true the GPG key must either be installed on the host system, or ``gpgkey_urls``</span>
|
||
|
<span class="sd"> should point to it.</span>
|
||
|
|
||
|
<span class="sd"> You can edit an existing source (other than system sources), by doing a POST</span>
|
||
|
<span class="sd"> of the new version of the source. It will overwrite the previous one.</span>
|
||
|
|
||
|
<span class="sd"> Example::</span>
|
||
|
|
||
|
<span class="sd"> {</span>
|
||
|
<span class="sd"> "id": "custom-source-1",</span>
|
||
|
<span class="sd"> "name": "Custom Package Source #1",</span>
|
||
|
<span class="sd"> "url": "https://url/path/to/repository/",</span>
|
||
|
<span class="sd"> "type": "yum-baseurl",</span>
|
||
|
<span class="sd"> "check_ssl": true,</span>
|
||
|
<span class="sd"> "check_gpg": true,</span>
|
||
|
<span class="sd"> "gpgkey_urls": [</span>
|
||
|
<span class="sd"> "https://url/path/to/gpg-key"</span>
|
||
|
<span class="sd"> ]</span>
|
||
|
<span class="sd"> }</span>
|
||
|
|
||
|
<span class="sd"> In v0 the ``name`` field was used for the id (a short name for the repo). In v1 ``name`` changed</span>
|
||
|
<span class="sd"> to ``id`` and ``name`` is now used for the longer descriptive name of the repository.</span>
|
||
|
<span class="sd"> """</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">source</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</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">source</span> <span class="o">=</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="c1"># Check for id in source, return error if not</span>
|
||
|
<span class="k">if</span> <span class="s2">"id"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">source</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_SOURCE</span><span class="p">,</span> <span class="s2">"msg"</span><span class="p">:</span> <span class="s2">"'id' field is missing from API v1 request."</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</span><span class="p">[</span><span class="s2">"id"</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">"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">"id"</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>
|
||
|
<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_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="n">new_repo_source</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">source</span><span class="p">[</span><span class="s2">"id"</span><span class="p">],</span> <span class="n">source</span><span class="p">,</span> <span class="n">repo_dir</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">"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></div>
|
||
|
</pre></div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
<footer>
|
||
|
|
||
|
|
||
|
<hr/>
|
||
|
|
||
|
<div role="contentinfo">
|
||
|
<p>
|
||
|
© Copyright 2018, Red Hat, Inc.
|
||
|
|
||
|
</p>
|
||
|
</div>
|
||
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
|
||
|
</footer>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
jQuery(function () {
|
||
|
SphinxRtdTheme.Navigation.enable(true);
|
||
|
});
|
||
|
</script>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|