<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Edmundo Sanchez</title>
    <description>The latest articles on Forem by Edmundo Sanchez (@gdledsan).</description>
    <link>https://forem.com/gdledsan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120218%2F9431ee25-2a64-4c34-b8fe-82b9630a838c.png</url>
      <title>Forem: Edmundo Sanchez</title>
      <link>https://forem.com/gdledsan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gdledsan"/>
    <language>en</language>
    <item>
      <title>How to install a package from a private repository on Poetry for CI</title>
      <dc:creator>Edmundo Sanchez</dc:creator>
      <pubDate>Fri, 30 Jun 2023 21:22:28 +0000</pubDate>
      <link>https://forem.com/gdledsan/how-to-install-a-package-from-a-private-repository-on-poetry-for-ci-1g5l</link>
      <guid>https://forem.com/gdledsan/how-to-install-a-package-from-a-private-repository-on-poetry-for-ci-1g5l</guid>
      <description>&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;One of the methods to install a package via poetry is to use &lt;code&gt;deploy tokens&lt;/code&gt; directly on the package URL, and that used to work on poetry too before version &lt;code&gt;1.0.3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What changed? The git URL parsing has changed significant to be more consistent.&lt;/p&gt;

&lt;p&gt;Are they planning on fixing this within poetry? No.&lt;br&gt;
They don't want to expose credentials on the &lt;code&gt;pyproject.toml&lt;/code&gt; file, which makes sense.&lt;/p&gt;

&lt;p&gt;source: &lt;a href="https://github.com/python-poetry/poetry/issues/2062" rel="noopener noreferrer"&gt;This issue on gitlab&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to do this then?
&lt;/h2&gt;

&lt;p&gt;There are multiple ways, using git credential helpers, setting credentials globally for a particular URL.&lt;/p&gt;

&lt;p&gt;The one thing that was easy enough to me was to tell git to replace the URL when calling gitlab via HTTPS.&lt;/p&gt;

&lt;p&gt;After &lt;a href="https://docs.gitlab.com/ee/user/project/deploy_tokens/" rel="noopener noreferrer"&gt;obtaining your deploy tokens from gitlab&lt;/a&gt;, this is how you tell git to use them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;deploy_user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_DEPLOY_TOKEN_USER
&lt;span class="nv"&gt;deploy_token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOU_DEPLOY_TOKEN
git config &lt;span class="nt"&gt;--global&lt;/span&gt; url.&lt;span class="s2"&gt;"https://&lt;/span&gt;&lt;span class="nv"&gt;$deploy_user&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$deploy_token&lt;/span&gt;&lt;span class="s2"&gt;@gitlab.com"&lt;/span&gt;.insteadOf https://gitlab.com

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note this is intended to run in a docker container via CI, so it does not matter that much if you rewrite that URL, I do not recommend you to do this on your local machine, for that use SSH keys.&lt;/p&gt;

&lt;p&gt;Which takes me to the next section&lt;/p&gt;

&lt;h3&gt;
  
  
  Poetry install Locally vs Gitlab CI
&lt;/h3&gt;

&lt;p&gt;I do use SSH to clone mu libraries from gitlab, and the deploy token requires cloning via HTTPS, so now what? &lt;/p&gt;

&lt;p&gt;I replace the urls on my &lt;code&gt;before_script&lt;/code&gt;, hacky but effective.&lt;/p&gt;

&lt;p&gt;For example, let's say you have this library on your &lt;code&gt;pyproject.toml&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;testrail-api-wrapper = {git = "git@gitlab.com:mundo03/sample_library.git", rev = "main"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can rewrite it using &lt;code&gt;sed&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;SSH_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;git@gitlab&lt;span class="se"&gt;\.&lt;/span&gt;com:mundo03&lt;span class="se"&gt;\/&lt;/span&gt;sample_library.git
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TOKEN_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https:&lt;span class="se"&gt;\\&lt;/span&gt;/&lt;span class="se"&gt;\\&lt;/span&gt;/gitlab.com&lt;span class="se"&gt;\\&lt;/span&gt;/mundo03&lt;span class="se"&gt;\/&lt;/span&gt;sample_library.git
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"s|&lt;/span&gt;&lt;span class="nv"&gt;$SSH_URL&lt;/span&gt;&lt;span class="s2"&gt;|&lt;/span&gt;&lt;span class="nv"&gt;$TOKEN_URL&lt;/span&gt;&lt;span class="s2"&gt;|g"&lt;/span&gt; pyproject.toml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file would look like this, given you want to install you project and run &lt;code&gt;pytest&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;stages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;

&lt;span class="na"&gt;.build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;before_script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;pip install poetry&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;poetry config virtualenvs.in-project &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;#Ignore venv&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;export SSH_URL=git@gitlab\.com:mundo03\/sample_library.git&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;export TOKEN_URL=https:\\/\\/gitlab.com\\/mundo03\/sample_library.git&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;sed -i "s|$SSH_URL|$TOKEN_URL|g" pyproject.toml&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;git config --global url."https://$deploy_user:$deploy_token@gitlab.com".insteadOf https://gitlab.com&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;poetry update&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;poetry install -v&lt;/span&gt;

&lt;span class="na"&gt;pytest_311&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python:3.11&lt;/span&gt;
  &lt;span class="na"&gt;extends&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.build&lt;/span&gt;
  &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;test&lt;/span&gt;
  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;poetry run pytest --cov&lt;/span&gt;
  &lt;span class="na"&gt;retry&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
  &lt;span class="na"&gt;coverage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/TOTAL.*\s+(\d+%)$/'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Poetry did me dirty and I had to find another way to install dependencies in CI that come from private git repositories.&lt;/p&gt;

</description>
      <category>python</category>
      <category>poetry</category>
      <category>gitlabci</category>
      <category>ci</category>
    </item>
    <item>
      <title>The Ultimate Guide You Need To Publish Your Python Package In Just 3 Easy Steps</title>
      <dc:creator>Edmundo Sanchez</dc:creator>
      <pubDate>Wed, 29 Dec 2021 20:34:04 +0000</pubDate>
      <link>https://forem.com/gdledsan/the-ultimate-guide-you-need-to-publish-your-python-package-in-just-2-easy-steps-2g2m</link>
      <guid>https://forem.com/gdledsan/the-ultimate-guide-you-need-to-publish-your-python-package-in-just-2-easy-steps-2g2m</guid>
      <description>&lt;p&gt;A reply to &lt;a href="https://dev.to/audarya07/the-ultimate-guide-you-need-to-publish-your-python-package-in-just-9-easy-steps-39o5"&gt;The Ultimate Guide You Need To Publish Your Python Package In Just 9 Easy Steps&lt;/a&gt;, using poetry instead of a &lt;code&gt;setup.py&lt;/code&gt; script.&lt;/p&gt;

&lt;p&gt;I will focus on the steps only, you can read a better and fuller &lt;a href="https://johnfraney.ca/posts/2019/05/28/create-publish-python-package-poetry/" rel="noopener noreferrer"&gt;article here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install all the things
&lt;/h2&gt;

&lt;p&gt;I am assuming you have python and poetry installed, if you do not have it, &lt;a href="https://python-poetry.org/docs/#installation" rel="noopener noreferrer"&gt;install&lt;/a&gt; it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a package
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;poetry new sample-package
Created package sample-package &lt;span class="k"&gt;in &lt;/span&gt;sample-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create the project layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sample-package/
├── sample-package/
│   └── __init__.py
├── tests/
│   ├── __init__.py
│   └── test_sample-package.py
├── pyproject.toml
└── README.rst 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Describe your package in &lt;code&gt;pyproject.toml&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Here is where you say what your package does and define dependencies.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[tool.poetry]&lt;/span&gt;
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"sample-package"&lt;/span&gt;
&lt;span class="py"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.0.1"&lt;/span&gt;
&lt;span class="py"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Sample Description for your sample file"&lt;/span&gt;
&lt;span class="py"&gt;authors&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"John Doe &amp;lt;john@doe.com&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nn"&gt;[tool.poetry.dependencies]&lt;/span&gt;
&lt;span class="c"&gt;# Updated Python version&lt;/span&gt;
&lt;span class="py"&gt;python&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"^3.6"&lt;/span&gt;

&lt;span class="nn"&gt;[tool.poetry.dev-dependencies]&lt;/span&gt;
&lt;span class="py"&gt;pytest&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"^3.0"&lt;/span&gt;

&lt;span class="nn"&gt;[build-system]&lt;/span&gt;
&lt;span class="py"&gt;requires&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="py"&gt;["poetry&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.12&lt;/span&gt;&lt;span class="s"&gt;"]&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="py"&gt;build-backend&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"poetry.masonry.api"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  X. Write Your Package
&lt;/h2&gt;

&lt;p&gt;There isn't a reason to publish an empty package, make sure it does something.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Publish it!
&lt;/h2&gt;

&lt;p&gt;After your package works, all test pass, etc., you want to make it available to the world, lets build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;poetry build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Make sure you have pypi credentials
&lt;/h3&gt;

&lt;p&gt;Get your token from pypi, add it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry config pypi-token.pypi your-api-token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing Publish via TestPyPi
&lt;/h3&gt;

&lt;p&gt;This is optional, highly recommended.&lt;/p&gt;

&lt;p&gt;Add Test PyPi as a package repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;poetry config repositories.testpypi https://test.pypi.org/legacy/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Publish it to Test PyPi:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;poetry publish &lt;span class="nt"&gt;-r&lt;/span&gt; testpypi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install it from Test PyPi&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--index-url&lt;/span&gt; https://test.pypi.org/simple/ flake8-markdown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Really Publish it
&lt;/h3&gt;

&lt;p&gt;If all is good, and ready to make it public:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  NOTES
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;If you are new to Poetry, &lt;a href="https://python-poetry.org/docs/" rel="noopener noreferrer"&gt;read the docs &lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You need an account in Test PyPi and PyPi, &lt;a href="https://pypi.org/account/register/" rel="noopener noreferrer"&gt;register&lt;/a&gt; if you haven't&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>python</category>
      <category>poetry</category>
      <category>pypi</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Gitlab's Deploy Keys and Deploy Tokens for CI/CD</title>
      <dc:creator>Edmundo Sanchez</dc:creator>
      <pubDate>Mon, 19 Jul 2021 03:13:46 +0000</pubDate>
      <link>https://forem.com/gdledsan/access-a-private-repository-from-gitlab-ci-42mh</link>
      <guid>https://forem.com/gdledsan/access-a-private-repository-from-gitlab-ci-42mh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;UPDATE: Poetry no longer supports deploy tokens on the package URLs due to a change on how they parse git urls, go read &lt;a href="https://dev.to/gdledsan/how-to-install-a-package-from-a-private-repository-on-poetry-for-ci-1g5l"&gt;this other post&lt;/a&gt; for a solution&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Scenario: Need to install a requirement that is only available on a private repository, from my CI pipeline.&lt;/p&gt;

&lt;p&gt;There are two ways (I found) to do this, and the one you use depends on what you need to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I have a simple library with no dependencies or with only public dependencies&lt;/li&gt;
&lt;li&gt;I have a dependency that depends on other private repositories&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For context and illustration I used gitlab, python and poetry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Dependencies: Use a Deploy Token
&lt;/h2&gt;

&lt;p&gt;A &lt;a href="https://docs.gitlab.com/ee/user/project/deploy_tokens/" rel="noopener noreferrer"&gt;deploy token&lt;/a&gt; allows you to access a repository without your user name and password or ssh keys, and it is setup per repository or group.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Add the dependency on your requirements file as you would normally&lt;/li&gt;
&lt;li&gt;Setup the &lt;a href="https://docs.gitlab.com/ee/user/project/deploy_tokens/" rel="noopener noreferrer"&gt;deploy token&lt;/a&gt; on the private repository you want to access&lt;/li&gt;
&lt;li&gt;Store the user and token on &lt;a href="https://docs.gitlab.com/ee/ci/variables/" rel="noopener noreferrer"&gt;CI Variables&lt;/a&gt; on the repository you will access the private repository from&lt;/li&gt;
&lt;li&gt;On the CI Script, fill in the deploy token using the CI variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://gitlab.com/mundo03/sample-public-project/-/tree/deploy_token/" rel="noopener noreferrer"&gt;Example&lt;/a&gt;:
&lt;/h4&gt;

&lt;p&gt;Dependency on &lt;strong&gt;pyproject.toml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tool.poetry.dependencies]
python = "^3.9"
private-project = {git = "ssh://git@gitlab.com/mundo03/sample-private-repo.git", rev = "main"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the SSH URL is kept so you don;t have to use a &lt;a href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html" rel="noopener noreferrer"&gt;Personal Access Token&lt;/a&gt; every time you install your dependencies locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;gitlab-ci.yml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: python:3.9-buster

poetry_token:
  script:
    # Install Poetry
    - pip install poetry
    # setup string replacement
    - export SSH_URL=ssh:\\/\\/git@gitlab.com\\/mundo03
    - export TOKEN_URL=https:\\/\\/$deploy_user:$deploy_token@gitlab.com\\/mundo03
    - sed -i "s/$SSH_URL/$TOKEN_URL/g" pyproject.toml
    # Install repo
    - poetry install
    # Use Clonned Repo
    - poetry run print_something "LOOK AT ME!!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice &lt;code&gt;sed&lt;/code&gt; is being used to replace the SSH URL with an HTTP URL that has the Deploy Token in it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Complex Dependencies: Use a deploy key
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/user/project/deploy_keys/" rel="noopener noreferrer"&gt;Deploy keys&lt;/a&gt; also give you access to a repository with out your user name and password or SSH key, it is an SSH key you generate and can be used on multiple repositories, on multiple groups if necessary.&lt;/p&gt;

&lt;p&gt;There are also &lt;a href="https://docs.gitlab.com/ee/user/project/deploy_keys/#public-deploy-keys" rel="noopener noreferrer"&gt;Public deploy keys&lt;/a&gt; setup at Gitlab Instance level and can be given access to any of the projects in that instance by an admin.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Add the dependency on your requirements file as you would normally&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.gitlab.com/ee/ssh/index.html" rel="noopener noreferrer"&gt;Generate&lt;/a&gt; an ssh key&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.gitlab.com/ee/user/project/deploy_keys/#how-to-enable-deploy-keys" rel="noopener noreferrer"&gt;Deploy the generated public key&lt;/a&gt; on any repo you need&lt;/li&gt;
&lt;li&gt;Set up ssh-agent on the CI script&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://gitlab.com/mundo03/sample-public-project/-/tree/deploy_key" rel="noopener noreferrer"&gt;Example&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Dependency on &lt;strong&gt;pyproject.toml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tool.poetry.dependencies]
python = "^3.9"
private-project = {git = "ssh://git@gitlab.com/mundo03/sample-private-repo.git", rev = "main"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;gitlab-ci.yml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: python:3.9-buster

poetry_key:
  script:
      # Install OS dependencies
    - apt-get update -y -qq &amp;amp;&amp;amp; apt-get install -y -qq make openssh-client python3-pip
    # Start ssh-agent
    - eval $(ssh-agent -s)
    # Add Private key to SSH Agent
    - ssh-add &amp;lt;(echo "$SSH_PK")
    # Add gitlab as known host
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan gitlab.com &amp;gt;&amp;gt; ~/.ssh/known_hosts
    # Install Poetry
    - pip install poetry
    # Install repo
    - poetry install
    # Use Clonned Repo
    - poetry run print_something "LOOK AT ME!!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Enter the Vault
&lt;/h2&gt;

&lt;p&gt;CI Variables are not the best way available to store a secret, for that gitlab has &lt;a href="https://docs.gitlab.com/charts/installation/secrets.html" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt;, which is meant to store things like SSH keys, Passwords Etc.&lt;/p&gt;

&lt;p&gt;Read up:  &lt;a href="https://docs.gitlab.com/charts/installation/secrets.html" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt;&lt;br&gt;
Spoilers: You need a Hashicorp's Vault account&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;I have a dependency in my project that is hosted on a private repository, I need to install it during my CI/CD, I have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deploy Token&lt;/strong&gt;: Are setup by project or group, I can add the token info in a CI variable and manipulate my requirements file to insert the token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy Keys&lt;/strong&gt;: These are SSH keys that can be added to any project I need or in any group. I need to setup the SSH-Agent on the CI/CD script, the Public Key goes in the repository settings, the Private key goes in a CI variable or Vault, and use the ssh URL when requiring the dependency.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Have a look at the Complete Sample here:&lt;br&gt;
&lt;a href="https://gitlab.com/mundo03/sample-public-project/-/tree/deploy_token" rel="noopener noreferrer"&gt;Use a Deploy Token&lt;/a&gt;&lt;br&gt;
&lt;a href="https://gitlab.com/mundo03/sample-public-project/-/tree/deploy_key" rel="noopener noreferrer"&gt;Use a Deploy Key&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gitlab</category>
      <category>ci</category>
      <category>python</category>
      <category>poetry</category>
    </item>
    <item>
      <title>Selenium 4 and chrome driver, take full page screenshots</title>
      <dc:creator>Edmundo Sanchez</dc:creator>
      <pubDate>Wed, 10 Mar 2021 07:52:51 +0000</pubDate>
      <link>https://forem.com/gdledsan/selenium-4-and-chrome-driver-take-full-page-screenthos-2j8d</link>
      <guid>https://forem.com/gdledsan/selenium-4-and-chrome-driver-take-full-page-screenthos-2j8d</guid>
      <description>&lt;p&gt;I spent some time playing with Selenium 4 trying to get a full page screenshot, this is what I found.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We will use the devtools protocol of Chrome Driver&lt;/li&gt;
&lt;li&gt;this is done by driver.execute_cdp_cmd(command, parameters)&lt;/li&gt;
&lt;li&gt;The command is &lt;code&gt;Page.captureScreenshot&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Parameters are documented &lt;a href="https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;the tricky param is &lt;code&gt;clip&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# I am assuming we already have a driver object.
&lt;/span&gt;
&lt;span class="c1"&gt;# We need the dimensions of the content
&lt;/span&gt;&lt;span class="n"&gt;page_rect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute_cdp_cmd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Page.getLayoutMetrics&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;

&lt;span class="c1"&gt;# parameters needed for ful page screenshot
# note we are setting the width and height of the viewport to screenshot, same as the site's content size
&lt;/span&gt;&lt;span class="n"&gt;screenshot_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;captureBeyondViewport&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;fromSurface&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;clip&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;width&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;page_rect&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;contentSize&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;width&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                                      &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;page_rect&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;contentSize&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                                      &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                      &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;y&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                      &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;scale&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
                             &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;# Dictionary with 1 key: data
&lt;/span&gt;&lt;span class="n"&gt;base_64_png&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;driver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute_cdp_cmd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Page.captureScreenshot&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;screenshot_config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Write img to file
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;imageToSave.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlsafe_b64decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_64_png&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why am I writing this?
&lt;/h2&gt;

&lt;p&gt;There is no good documentation related to the DevTools protocol and its integration to selenium is still in the works in Selenium 4 at the time I wrote this.&lt;/p&gt;

&lt;p&gt;I Hope this helps any lost soul.&lt;/p&gt;

</description>
      <category>python</category>
      <category>selenium</category>
      <category>devtools</category>
    </item>
    <item>
      <title>Ruby, config this</title>
      <dc:creator>Edmundo Sanchez</dc:creator>
      <pubDate>Fri, 05 Mar 2021 21:50:58 +0000</pubDate>
      <link>https://forem.com/gdledsan/ruby-config-this-146o</link>
      <guid>https://forem.com/gdledsan/ruby-config-this-146o</guid>
      <description>&lt;h1&gt;
  
  
  Config_this
&lt;/h1&gt;

&lt;p&gt;Have you ever wondered where is the right way to store sensitive information like passwords for your ruby scripts and gems?&lt;/p&gt;

&lt;p&gt;I have, doing some research I found a few ways to do that, like the &lt;a href="https://medium.com/@vfreefly/the-most-simple-configuration-block-implementation-for-a-ruby-gem-815fe1dad5dc" rel="noopener noreferrer"&gt;Simplest configuration block implementation&lt;/a&gt; for a ruby gem ever or &lt;a href="http://lizabinante.com/blog/creating-a-configurable-ruby-gem/" rel="noopener noreferrer"&gt;Creating a configurable Ruby gem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I also found using a file is the best way to store sensitive information but there are use cases to have Environmental variables or just hard-coding values.&lt;/p&gt;

&lt;p&gt;However following that for every script I write is a bit cumbersome for me, I like easy things and automation so as a learning exercise I created a gem called &lt;a href="https://rubygems.org/gems/config_this" rel="noopener noreferrer"&gt;config_this&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;Config_this&lt;/strong&gt; you can load your configuration parameters from a YAML or json file, a block or a hash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Add this line to your application's Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s1"&gt;'config_this'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then execute:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ bundle install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Or install it yourself as:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ gem install config_this&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;The Config Module is the main interface for this gem, as you know you can not instantiate a Module so be careful with your values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"config"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get the Configuration object
&lt;/h3&gt;

&lt;p&gt;This will get the latest object you created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538ef2dc0&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting the configuration Object
&lt;/h3&gt;

&lt;p&gt;If you plan on having only one configuration object you don't need to assign it, it will always return&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"Arthur Dent"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538f3c9c0 @id=42, @name="Arthur Dent"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do plan to have multiple configurations, handle them properly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"Arthur Dent"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538f3c9c0 @id=42, @name="Arthur Dent"&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;number1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"Stefán Karl Stefánsson"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d53866ea00 @id=1, @name="Stefán Karl Stefánsson"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting it With a Hash
&lt;/h4&gt;

&lt;p&gt;As you noticed, this is how you set it with a hash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"Arthur Dent"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538f3c9c0 @id=42, @name="Arthur Dent"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting it with a YAML file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;yaml_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/absolute/path/file.yaml"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538ed7d90 @id=42, @name="Arthur Dent", @weapon="Towel"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting it with a JSON file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/absolute/path/file.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538a8f210 @id=42, @name="Arthur Dent", @weapon="Towel"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting it with a Environmental Variables
&lt;/h3&gt;

&lt;p&gt;Be sure the variables are set and accesible&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"42"&lt;/span&gt;
&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Arthur Dent"&lt;/span&gt;
&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env_variables&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538ef8b58 @id="42", @name="Arthur Dent"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting it with a Block
&lt;/h3&gt;

&lt;p&gt;To do this, you have to use the Config::Configuration class directly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Stefán Karl Stefánsson"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x00005630c8eda630 @id=1, @name="Stefán Karl Stefánsson"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the Configuration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x000055d538f3c9c0 @id=42, @name="Arthur Dent"&amp;gt;&lt;/span&gt;
&lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;
&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Arthur Dent"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also just set new values to the Configuration object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;
&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Earth"&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Config::Configuration:0x00005630c87f0e00 @id=42, @name="Arthur Dent", @location="Earth"&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
