Skip to content
Snippets Groups Projects
Commit 0cb5835e authored by John Feiner's avatar John Feiner
Browse files

Updated 1c with improved pipe demo

parent 5d058617
Branches
No related tags found
No related merge requests found
echo "server_url=http://data.imgs.com/" | ./data_processing.py
# Data piped into this script: 'server_url=http://data.imgs.com/'.
......@@ -2,5 +2,7 @@
import sys
input_from_other_prog=sys.stdin.read().strip()
print(f"Data piped into this script: '{input_from_other_prog}'.")
# echo "password=abc" | ./pipe.py
# Data piped into this script: 'password=abc'.
\ No newline at end of file
# echo "server_url=http://data.imgs.com/" | ./data_processing.py
# =>
# Data piped into this script: 'server_url=http://data.mycompany.com/'.
echo "password=abc" | ./pipe.py
# Data piped into this script: 'password=abc'.
\ No newline at end of file
......@@ -47,18 +47,9 @@
== Passwörter // "credentials" niemals im Source
#section_summary([
Idealerweise werden Skripts mit Daten gefüttert, sind extern konfiguirerbar
und haben keine sensiblen Daten wie Passwörter im Source code.
*Never hard code credentials*
Idealerweise erhalten Python Skripts ihre Daten von extern, sind also nicht fest in den Source Code hineinkodiert. Skripts sind ebenfalls über externe Settings konfigurierbar. Sensiblen Daten wie Passwörter landen auf keinen Fall im Code. #english_term([Never hard code credentials])!
])
/* Daten werden besser vom Programmcode getrennt.
Konfigurationen sollten auch nicht im Source hinterlegt,
sondern getrennt vom Programm konfiguriert werden.
Passwörter dürfen niemals
hart kodiert im Programmcode befinden. *Never hard code credentials!*
*/
#markup([Problem], [
Sensible Daten (wie Passwörter oder auch API keys) finden sich als Teil des Source Codes.
......@@ -70,27 +61,30 @@
- *Lösung A: Kommandozeilenargumente*. Übergabe von Konfigurationen als _command-line parameters_.
#sourcecode(lang: "Python", raw( read("../code/1c/cli-args-snippet.py") ))
#pysrc_with_ok("/1c/cli-args-snippet.py")
- *Lösung B: Umgebungsvariable*. Übergabe von Konfigurationen mittels _environment variables_.
- *Lösung B: Umgebungsvariable*. Übergabe von Konfigurationen mittels _environment variables_ (Dies ist vor allem im Umfeld von CI/CD -- siehe @git Git -- üblich).
#sourcecode(lang: "Python", raw( read("../code/1c/env-snippet.py") ))
#pysrc_with_ok("1c/env-snippet.py")
- *Lösung C: Konfigurationsfile*. Festlegen von Konfigurationen in einem _config-file_. Hier zum Beispiel _config.py_ mit dem Inhalt `ip="10.0.0.7"`.
#sourcecode(lang: "Python", raw( read("../code/1c/config-usage-snippet.py") ))
#pysrc_with_ok("1c/config-usage-snippet.py")
- *Lösung D: Standardwerte*. Das Festlegen von gut gewählten _default values_ erübrigt in vielen Fällen die explizite Übergabe von Startwerten.
#sourcecode(lang: "Python", raw( read("../code/1c/defaults-snippet.py") ))
#pysrc_with_ok("1c/defaults-snippet.py")
#pagebreak()
- *Lösung E: Pipes*. Werte können auch über eine sogenannte _Pipe_ an ein Programm übergeben werden.
#sourcecode(lang: "Python", raw( read("../code/1c/pipe-snippet.py") ))
#pysrc_with_ok("1c/./data_processing-snippet.py", y_offset: -2.6cm,
title: "data_processing.py", y_title_offset: 1.1cm)
bzw.
#sourcecode(lang: "Bash", raw( read("../code/1c/pipe-snippet.sh") ))
#bashscript("1c/./data_processing-startup.sh", title: "startup.sh")
*Weitere Empfehlungen:*
......
......@@ -9,7 +9,7 @@
]else[
== Code Repository
== Code Repository <git>
#section_summary([
Source Code Verwaltung mit Git gibt Sicherheit durch *Backup* am Server und ermöglicht
......
......@@ -180,27 +180,37 @@
)
}
#let bashscript(
filename, y_offset: -0.5em,) = {
filename, y_offset: -0.5em,title:none,) = {
let path_to_src="../code/"+filename
sourcecode(
lang: "Bash",
lang: "bash",
raw( read(path_to_src) ),
)
place(dx:-0.3em,dy:y_offset,
bottom+right,
text(size: 14pt, fill: red, [✔︎])
)
if title != none {
place(
right, dy:-1.2cm,
block(
fill: rgb(100, 100, 100, 100), outset: 0.1cm, radius: 0.1cm,
[#h(0.5cm) #title #h(0.5cm)]
)
)
}
}
#let pysrc_with_ok(
filename,
title:none,
y_offset: -0.5em,
y_title_offset: 1.2em,
) = {
let path_to_src="../code/"+filename
sourcecode(lang: "Python", raw( read(path_to_src) ))
if title != none {
place(
top+right, dy:1.2em,
top+right, dy:y_title_offset,
block(
fill: rgb(100, 100, 100, 100), outset: 0.1cm, radius: 0.1cm,
[#h(0.5cm) #title #h(0.5cm)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment