I'm building my python package using Azure DevOps pipeline and the generated artifact is then uploaded to a feed. Everything is working fine, however, I don't like the fact that I have a .pypirc file containing the credentials for the upload sitting in my repository.
Basically I'm uploading the artifact using:
- script: 'twine upload -r imglib --config-file .pypirc dist/imglib-*.tar.gz'
Is there another way to store the credentials, preferably not in a file that anyone could edit? I read something about storing the credentials in the key vault, but I don't see how change the pipeline (the yml file) to do this.
Thanks in advance.
EDIT:
Shaykis answere seems to be the right way, however, I'm not able to replace the placeholder in the .pypirc file using a bash command. All I get is three asterics when I print the content of .pypirc after replacement. For the replacement I use:
- script: 'sed -i "s/__password__/$PYPI_CRED_MAPPED/g" .pypirc'
displayName: 'Setting PyPI credentials'
env:
PYPI_CRED_MAPPED: $(pypi_cred)
The content of .pypirs is (displayed during the build task using a bash cat .pypirc. Is there an easier way to debug the build prozess?):
[distutils]
Index-servers =
pypi
imglib
[imglib]
Repository = https://pkgs.dev.azure.com/XXX/_packaging/imglib/pypi/upload
username = imglib
password = ***
Does anyone know what is happening there?
EDIT 2:
I also tried to use $env:PYPI_CRED_MAPPED but in that case only the $env is replaced by nothing and all I'm left with is :PYPI_CRED_MAPPED. Also, I look at the docs and they use the variable directly (e.g. $PYPI_CRED_MAPPED, see bottom of page).
EDIT 3:
The three asterics are just a placeholder. It worked with $PYPI_CRED_MAPPED as mentioned in EDIT 2. The build process was failing because of another reason. I also tried it with the powershell command provided in the answer and it worked as well. So thank you for your help.
You can store the variable as a secret variable, in the .pypirc file put a placeholder and in the pipeline add a script that replace the placeholder with the variable.
1) In the .yaml editor click on the 3 dots near the Save/Run button on the top right and then click "Variables".
2) Add a new variable (pythonCred fore example) with the password and click on the lock icon to make it secret.
3) Go to your .pypirc file and replace the password with __password__.
4) In your pipeline add a PowerShell task to put the password:
- powershell: |
(Get-Content path/to/pypirc) -replace "__password__" , "$env:CredPython" | Set-Content -Path path/to/pypirc
env: CredPython: $(pythonCred) # you must to map the variable because is a secret variable
You can also use Azure Key Vault with this way, download the password from there in with Azure Key Vault task and replace update the .pypirc file.
Related
I access to one remote machine to automate some ssl task. To accomplish this from the remote I need import a file from a shared network folder in windows. I´m using pywinrm then after a successful session started I run:
s.run_ps('''
$Password = ConvertTo-SecureString -AsPlainText -Force {0}
Import-PfxCertificate -FilePath {1} -CertStoreLocation Cert:\LocalMachine\WebHosting -
Password $Password
'''.format(secret, path)
using similar script with local folder paths I don't have any problem but typing kind of this \\192.168.1.19\cert\testcert.pfx I have the following error
std_error b'Import-PfxCertificate : The system cannot find the path specified. 0x80070003 \n(WIN32: 3 ERROR_PATH_NOT_FOUND)\nAt line:3 char:9\n+ Import-PfxCertificate -FilePath \\192.168.1.19\\Certificates1\\test ...\n+
I built this path like string "host"+"\\"+cert+"\\"+file where host = "\\192.168.1.19", cert = "Certificates1", and file = "testcert.pfx"
I have seen that in powershell I should type exactly PS C:\>\\192.168.1.19\cert\testcert.pfx and it works but pointing to the error the string that is passing python to powershell is \ and not escaping and passing only one backslash.
Any help or advice?
Thank you in advance.
the error the string that is passing python to powershell is \ and not escaping and passing only one backslash.
\\ = \ so you need to do host = "\\\\192.168.1.19"
The problem deals with the second hop issue, so the script can't access to another network shared file while remoting.
The solution was change authentication to CredSSP and allowing the second hop delegate the credentials.
After this, no errors referring to any path appears.
I have a web application deployed to Heroku. In the address line of the application, the name of the running file and the designation of the streamlit. How can I change this line with integer. Maybe you need to add some kind of configuration file?
I need to change the line "dashboard . Strealit"
Additionally, I ran into the fact that I have no application theme settings.
How can I enable them?
There is also a question about configuration files. They are located along the path: /.streamlit/
but if I place the code on GitHUB, then where should these files be located, in particular the file config.toml??
A few questions here. To change your page name, you can set that a the beginning of your app code with:
st.set_page_config(
page_title="My Page Title",
)
Streamlit theming was added in a recent update. To update your version and see the theme in the settings, you can run:
pip install streamlit --upgrade
and make sure to save the new version number in your requirements.txt.
Your're right, the config.toml file should be located inside a directory called .streamlit at the root of your app. You would need to commit that directory to your Github repo along with the rest of your files. Other config files, like editor configs, .gitignore, etc should be at the root of your project as well and can be committed with everything else.
Your problem is solved using st.set_page_config().
Streamlit has this attribute to change page title, page icon (favicon),layout, initial sidebar state, sidebar menu items.
Please check the Streamlit documentation answering your query from here,
st.set_page_config.
Use this code at the top of your streamlit_app.py file (if it has your main function)
st.set_page_config(page_title = "New Name")
Regarding the second question,
Use this code in setup.sh file, when ran in the Procfile this will create a dir with the theme configuration set in the config.toml under .streamlit directory.
mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"your-email#domain.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[theme]\n\
base='light'\n\
primaryColor='#3a70ec'\n\
backgroundColor='#FFD600'\n\
secondaryBackgroundColor = '#F0F2F6'\n\
textColor='#0e1862'\n\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
You may also checkout this answer on the second question,
https://stackoverflow.com/a/67001757/12007117
Thanks, upvote if found helpful!😊
You can change the app name, logo, etc. You should write the below code at the beginning of your script.
import streamlit as st
from PIL import Image
image_directory = "C:\\Users\Documents\logo.PNG"
image = Image.open(image_directory)
PAGE_CONFIG = {"page_title":"MyApp",
"page_icon":image,
"layout":"centered",
"initial_sidebar_state":"auto"}
st.set_page_config(**PAGE_CONFIG)
I'm trying to launch may main Python script with some arguments listed in a txt file (config.txt).
Because parameters change almost every launch and I dont want to type them every time. They are not literally a "config" but I didn't find the correct file name (that's an other story).
See below:
-param1 1
-param2 2
-verbose
Using Run Configuration of PyCharm.
I would like to finally do something like :
python C:\somewhere\main.py -param1 1 -param2 2 -verbose
Instead of current behavior :python C:\somewhere\main.py config.txt
Which, by the way, is missed understood by the program (obviously).
#32951846
I already tried windows for loops in the section "before launch: activate tools":
$: for /f "delims=" %x in (config.txt) do set ARGS=%ARGS%%x
$: python C:\somewhere\main.py %ARGS%
But it only keep the last line of the config.txt inside ARGS.
#51948712
I also tried to pipe the content of the file into my python main program like:
python C:\somewhere\main.py < config.txt
But it do not work neither.
#syntax-redirection
Am I right that you'd like to see something like https://youtrack.jetbrains.com/issue/PY-5543?
Consider using the following plugin: https://plugins.jetbrains.com/plugin/7861-envfile/
This is not exactly what you were asking for, but you can follow this guideline to store the run configurations in a file and then modify the file, share it or add to git.
The key steps are to tick the box "Store as project file" in PyCharm's "Run/Debug Configurations" window. This will create the new subfolder "runConfigurations" in the ".idea" folder in the project folder.
The folder will contain an xml file with the line
<option name="PARAMETERS" value=""arg1" "arg2"" />
where "arg1" and "arg2" are the arguments which are passed to your script.
I am using Ride (RobotFramework IDE) and I have imported Library AllureReportLibrary in my project.
Using the Set Output Dir, I am creating a Directory C:/AutomationLogs/Allure and all the allure properties and xml files are getting generated in that path.
Set Output Dir C:/AutomationLogs/
Then I am using the "allure serve C:\AutomationLogs\Allure" command to try and generate the html report file in command prompt, but it shows the below error -
"Could not read result
C:\AutomationLogs\Allure\f56f4796-d30a-47f3-a988-d17f6c4e13ca-testsuite.xml:
{} com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot
deserialize va lue of type
ru.yandex.qatools.allure.model.SeverityLevel from String "None":
value not one of declared Enum instance names: [trivial, blocker,
minor, normal, critical]"
The xml file "f56f4796-d30a-47f3-a988-d17f6c4e13ca-testsuite.xml" was generated using the AllureReportLibrary
Also the index.html file which is generated after the command opens after this command and shows Allure Report unknown
unknown - unknown (Unknown) 0 test cases NaN%
I am using the below -
Allure version - 2.4.1
Ride version - RIDE 1.5.2.1 running on Python 2.7.12.
I am new to Robot Framework and Allure. Please let me know whether I have implemented it correctly and why I am facing the above error.
-Ryan M
I'm using the 1.1.1 version of Allure Adaptor for Robot Framework and the severity is picked from the test case tags and added as a label under the test-case element of the report.
However, it seems that Allure 2.6.0 is also expecting a valid value for the severity attribute of the test-case element.
In order to use Allure2 with the current reports I have altered AllureListener.py to also add the severity to the test case:
elif tag in SEVERITIES:
test.severity = tag
test.labels.append(TestLabel(
name='severity',
value=tag
))
If your output.xml has severity = None for any testcase then the allure-robotframework-adaptor will give the error that you have mentioned. Creating TestCase() object with severity='' in start_suitesetup method of AllureListener.py will do the trick.
def start_suitesetup(self, name, attributes):
....
....
test = TestCase(name=name,
description=description,
start=now(),
attachments=[],
labels=[],
parameters=[],
steps=[],
severity='')
How to create the Allure reports in Robot Framework ?
Initially, Download the Command line and UNzip the file and save the path of the bin folder in environment.
Link : http://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.8.0/allure-commandline-2.8.0.zip
Unzip the above file then put it in the Environment folder.
Then Pip install the below modules
pip install allure-robotframework
pip install robotframework-allurereport
In robot file, Add the Library in Settings like,
Example :
Library AllureReportLibrary D:\eclipse\RobotFramework\results
Then Use the Below commands to run the robot code.
robot --listener allure_robotframework;D:\eclipse\RobotFramework\results
Example.txt
Finally,
Generate the HTML file by,
allure generate D:\eclipse\RobotFramework\results
Note : Use the same path what you used in the previous command to generate the HTml.file.
and
Open in Mozhila FireFox. It wont be work in Chrome. I dont know exactly why.
Regards,
Vijay
I have a Python script with secret keys for the Tweeter API. I would like to version control my script using Github. How do I keep my keys secret while still uploading to Github? That is, the values of these
KEY = ""
KEY_SECRET = ""
TOKEN = ""
TOKEN_SECRET = ""
should be kept secret. Maybe I can put them in another file and load them, but .gitignor'ing said file? What is the correct pattern?
# project/.gitignore
passwords.py
# project/passwords.py
GITHUB_KEY = '123'
GITHUB_KEY_SECRET = 'ABC'
GITHUB_TOKEN = '456'
GITHUB_TOKEN_SECRET = 'XYZ'
# project/my_script.py
from passwords import GITHUB_KEY, GITHUB_KEY_SECRET, GITHUB_TOKEN, GITHUB_TOKEN_SECRET
KEY = GITHUB_KEY
KEY_SECRET = GITHUB_KEY_SECRET
TOKEN = GITHUB_TOKEN
TOKEN_SECRET = GITHUB_TOKEN_SECRET
As hinted to by #chishaku, a good idea would be to save all your confidential information in a separate file that is not version controlled ie: is not known by git. You do this by adding it to the .gitignore file.
With this in place, you can safely commit your code to GitHub where everyone can see your project - however your confidential information and passwords are no where to be seen!
Within your project, you can now read that file (or import it) and use the information held within.
Keep in mind that when you (or someone else) accesses this project, you will have to ensure that your "secret" file exists since your project depends on it.
In my projects, creating this "secret" file is part of the deploy script. Something like:
echo '{"password": "123"}' > config.json && git checkout master
This line of code writes the (simple) settings file to config.json and only afterwards retrieves the latest code version from the master branch.