SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
dry-wit
Bash framework
Jose San Leandro @rydnr
OSOCO
Contents
1 Introduction
2 dry-wit approach
3 dry-wit hooks
4 dry-wit API
5 Try it
Bash
In theory
• Powerful language.
• Conventions improve
reusability and
maintainability.
• Great fit for Unix and OSs
with strong command-line
focus.
dry-wit Introduction 3 / 16
Bash
In theory
• Powerful language.
• Conventions improve
reusability and
maintainability.
• Great fit for Unix and OSs
with strong command-line
focus.
In practice
• Easy to start with.
• Difficult to master.
• Write once, use twice,
dispose.
• Expensive maintenance.
• Hardly reusable.
dry-wit Introduction 3 / 16
dry-wit: Features
Features
1 Provides a consistent way to structure scripts.
2 Manages required dependencies.
3 Declarative approach for dealing with errors (Output message
+ error code).
4 Handles parameters, flags, and environment variables.
5 API for creating temporary files, logging, etc.
6 Composability: scripts can be injected into others.
dry-wit dry-wit approach 4 / 16
Usage / Help
usage()
function usage() {
cat <<EOF
Does this and that...
Where:
* myflag: changes the behavior somehow.
* param1: the first input.
Common flags:
* -h | --help: Display this message.
* -v: Increase the verbosity.
* -vv: Increase the verbosity further.
* -q | --quiet: Be silent.
EOF
}
dry-wit dry-wit hooks 5 / 16
Input: checking
checkInput()
function checkInput() {
local _flags=$(extractFlags $@);
logDebug -n "Checking input";
for _flag in ${_flags}; do
case ${_flag} in
-h | --help | -v | -vv | -f | --my-flag)
;;
*) logDebugResult FAILURE "fail";
exitWithErrorCode INVALID_OPTION ${_flag};
;;
esac
done
}
dry-wit dry-wit hooks 6 / 16
Input: parsing
parseInput()
function parseInput() {
local _flags=$(extractFlags $@);
for _flag in ${_flags}; do
case ${_flag} in
-f | --my-flag)
shift;
export MY_FLAG="${1}";
shift;
;;
*) shift;
;;
esac
done
}
dry-wit dry-wit hooks 7 / 16
Script requirements
Dependencies
function checkRequirements() {
checkReq docker DOCKER_NOT_INSTALLED;
checkReq realpath REALPATH_NOT_INSTALLED;
checkReq envsubst ENVSUBST_NOT_INSTALLED;
}
DSL
1 executable-file: The required dependency.
2 message: The name of a constant describing the error to
display should the dependency is not present.
3 dry-wit checks each dependency and exits if the check fails.
dry-wit dry-wit hooks 8 / 16
Error messages
defineErrors()
function defineErrors() {
export INVALID_OPTION="Unrecognized option";
export DOCKER_NOT_INSTALLED="docker is not installed. See http://www.docker.org";
export REPOSITORY_IS_MANDATORY="The repository argument is mandatory";
ERROR_MESSAGES=(
INVALID_OPTION 
DOCKER_NOT_INSTALLED 
REPOSITORY_IS_MANDATORY 
);
export ERROR_MESSAGES;
}
dry-wit takes care of the exit codes
exitWithErrorCode REPOSITORY_IS_MANDATORY;
dry-wit dry-wit hooks 9 / 16
main()
main()
function main() {
// Focus on the logic itself.
// Forget about defensive programming
// regarding input variables
// or dependencies.
// Start by writing pseudo-code,
// and later define the identified
// functions.
}
dry-wit dry-wit hooks 10 / 16
Logging
logging
logInfo -n "Calculating next prime number ...";
...
if [ $? -eq 0 ]; then
logInfoResult SUCCESS "done";
else
logInfoResult FAILURE "Too optimistic";
fi
output
[2015/10/26 15:09:54 my-script:main] Calculating next prime number ... [done]
dry-wit dry-wit API 11 / 16
Temporary files
API functions
1 Functions to create temporary files or folders.
2 dry-wit takes cares of cleaning them up afterwards.
createTempFile()
createTempFile;
local tempFile=${RESULT};
createTempFolder()
createTempFolder;
local tempFolder=${RESULT};
dry-wit dry-wit API 12 / 16
Environment variables: Declaration (1/3)
DSL for declaring environment variables
1 Declared in [script].inc.sh.
2 Safe to add to version control systems.
3 Mandatory information: description and default value.
defineEnvVar()
defineEnvVar 
MYPASSWORD 
"The description of MYPASSWORD" 
"secret";
dry-wit dry-wit API 13 / 16
Environment variables: Overridding (2/3)
DSL for overridding default values
1 Declared in .[script].inc.sh.
2 Not always safe to add to version control systems.
overrideEnvVar()
overrideEnvVar MYPASSWORD ".toor!";
dry-wit dry-wit API 14 / 16
Environment variables: Overridding (3/3)
Environment value overridden from the command line
MYPASSWORD="abc123" ./script.sh ...
dry-wit dry-wit API 15 / 16
Free as in freedom
You’re welcome to try, fork, improve, even criticize!
https://github.com/rydnr/dry-wit
dry-wit Try it 16 / 16

Más contenido relacionado

La actualidad más candente

Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in javajunnubabu
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statementmyrajendra
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in pythonjunnubabu
 
Exception Handling
Exception HandlingException Handling
Exception Handlingbackdoor
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in JavaJava2Blog
 
Extrabacon's sploit core
Extrabacon's sploit coreExtrabacon's sploit core
Extrabacon's sploit coreDaniel Reilly
 

La actualidad más candente (11)

Exceptions handling in java
Exceptions handling in javaExceptions handling in java
Exceptions handling in java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statement
 
Error and exception in python
Error and exception in pythonError and exception in python
Error and exception in python
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Exception
ExceptionException
Exception
 
Extrabacon's sploit core
Extrabacon's sploit coreExtrabacon's sploit core
Extrabacon's sploit core
 

Similar a Dry-wit Overview

PHP 7 Crash Course
PHP 7 Crash CoursePHP 7 Crash Course
PHP 7 Crash CourseColin O'Dell
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Alessio Ricco
 
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...Whymca
 
Exception handling
Exception handlingException handling
Exception handlingzindadili
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone CivettaCocoaHeads France
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Codeeddiehaber
 
Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Mauricio Velazco
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerJustin Bui
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopMax Kleiner
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CanSecWest
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfssuser705051
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
 
Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitationDharmalingam Ganesan
 
Android Open source coading guidel ine
Android Open source coading guidel ineAndroid Open source coading guidel ine
Android Open source coading guidel inePragati Singh
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersAlexandre Moneger
 

Similar a Dry-wit Overview (20)

PHP 7 Crash Course
PHP 7 Crash CoursePHP 7 Crash Course
PHP 7 Crash Course
 
Php 7 crash course
Php 7 crash coursePhp 7 crash course
Php 7 crash course
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator
 
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...
BEST PRACTICES PER LA SCRITTURA DI APPLICAZIONI TITANIUM APPCELERATOR - Aless...
 
Exception handling
Exception handlingException handling
Exception handling
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift Messenger
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
 
Terraform-2.pdf
Terraform-2.pdfTerraform-2.pdf
Terraform-2.pdf
 
Shell Script Tutorial
Shell Script TutorialShell Script Tutorial
Shell Script Tutorial
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Linux binary analysis and exploitation
Linux binary analysis and exploitationLinux binary analysis and exploitation
Linux binary analysis and exploitation
 
Android Open source coading guidel ine
Android Open source coading guidel ineAndroid Open source coading guidel ine
Android Open source coading guidel ine
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
 

Más de OSOCO

HackaTrips 2017 Team 10
HackaTrips 2017 Team 10HackaTrips 2017 Team 10
HackaTrips 2017 Team 10OSOCO
 
Take the Smalltalk Red Pill
Take the Smalltalk Red PillTake the Smalltalk Red Pill
Take the Smalltalk Red PillOSOCO
 
Spring Annotations: Proxy
Spring Annotations: ProxySpring Annotations: Proxy
Spring Annotations: ProxyOSOCO
 
Proactive monitoring with Monit
Proactive monitoring with MonitProactive monitoring with Monit
Proactive monitoring with MonitOSOCO
 
XSS Countermeasures in Grails
XSS Countermeasures in GrailsXSS Countermeasures in Grails
XSS Countermeasures in GrailsOSOCO
 
AWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosAWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosOSOCO
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesOSOCO
 
SSH Tunneling Recipes
SSH Tunneling RecipesSSH Tunneling Recipes
SSH Tunneling RecipesOSOCO
 

Más de OSOCO (8)

HackaTrips 2017 Team 10
HackaTrips 2017 Team 10HackaTrips 2017 Team 10
HackaTrips 2017 Team 10
 
Take the Smalltalk Red Pill
Take the Smalltalk Red PillTake the Smalltalk Red Pill
Take the Smalltalk Red Pill
 
Spring Annotations: Proxy
Spring Annotations: ProxySpring Annotations: Proxy
Spring Annotations: Proxy
 
Proactive monitoring with Monit
Proactive monitoring with MonitProactive monitoring with Monit
Proactive monitoring with Monit
 
XSS Countermeasures in Grails
XSS Countermeasures in GrailsXSS Countermeasures in Grails
XSS Countermeasures in Grails
 
AWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosAWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 Minutos
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
 
SSH Tunneling Recipes
SSH Tunneling RecipesSSH Tunneling Recipes
SSH Tunneling Recipes
 

Último

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Último (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Dry-wit Overview

  • 1. dry-wit Bash framework Jose San Leandro @rydnr OSOCO
  • 2. Contents 1 Introduction 2 dry-wit approach 3 dry-wit hooks 4 dry-wit API 5 Try it
  • 3. Bash In theory • Powerful language. • Conventions improve reusability and maintainability. • Great fit for Unix and OSs with strong command-line focus. dry-wit Introduction 3 / 16
  • 4. Bash In theory • Powerful language. • Conventions improve reusability and maintainability. • Great fit for Unix and OSs with strong command-line focus. In practice • Easy to start with. • Difficult to master. • Write once, use twice, dispose. • Expensive maintenance. • Hardly reusable. dry-wit Introduction 3 / 16
  • 5. dry-wit: Features Features 1 Provides a consistent way to structure scripts. 2 Manages required dependencies. 3 Declarative approach for dealing with errors (Output message + error code). 4 Handles parameters, flags, and environment variables. 5 API for creating temporary files, logging, etc. 6 Composability: scripts can be injected into others. dry-wit dry-wit approach 4 / 16
  • 6. Usage / Help usage() function usage() { cat <<EOF Does this and that... Where: * myflag: changes the behavior somehow. * param1: the first input. Common flags: * -h | --help: Display this message. * -v: Increase the verbosity. * -vv: Increase the verbosity further. * -q | --quiet: Be silent. EOF } dry-wit dry-wit hooks 5 / 16
  • 7. Input: checking checkInput() function checkInput() { local _flags=$(extractFlags $@); logDebug -n "Checking input"; for _flag in ${_flags}; do case ${_flag} in -h | --help | -v | -vv | -f | --my-flag) ;; *) logDebugResult FAILURE "fail"; exitWithErrorCode INVALID_OPTION ${_flag}; ;; esac done } dry-wit dry-wit hooks 6 / 16
  • 8. Input: parsing parseInput() function parseInput() { local _flags=$(extractFlags $@); for _flag in ${_flags}; do case ${_flag} in -f | --my-flag) shift; export MY_FLAG="${1}"; shift; ;; *) shift; ;; esac done } dry-wit dry-wit hooks 7 / 16
  • 9. Script requirements Dependencies function checkRequirements() { checkReq docker DOCKER_NOT_INSTALLED; checkReq realpath REALPATH_NOT_INSTALLED; checkReq envsubst ENVSUBST_NOT_INSTALLED; } DSL 1 executable-file: The required dependency. 2 message: The name of a constant describing the error to display should the dependency is not present. 3 dry-wit checks each dependency and exits if the check fails. dry-wit dry-wit hooks 8 / 16
  • 10. Error messages defineErrors() function defineErrors() { export INVALID_OPTION="Unrecognized option"; export DOCKER_NOT_INSTALLED="docker is not installed. See http://www.docker.org"; export REPOSITORY_IS_MANDATORY="The repository argument is mandatory"; ERROR_MESSAGES=( INVALID_OPTION DOCKER_NOT_INSTALLED REPOSITORY_IS_MANDATORY ); export ERROR_MESSAGES; } dry-wit takes care of the exit codes exitWithErrorCode REPOSITORY_IS_MANDATORY; dry-wit dry-wit hooks 9 / 16
  • 11. main() main() function main() { // Focus on the logic itself. // Forget about defensive programming // regarding input variables // or dependencies. // Start by writing pseudo-code, // and later define the identified // functions. } dry-wit dry-wit hooks 10 / 16
  • 12. Logging logging logInfo -n "Calculating next prime number ..."; ... if [ $? -eq 0 ]; then logInfoResult SUCCESS "done"; else logInfoResult FAILURE "Too optimistic"; fi output [2015/10/26 15:09:54 my-script:main] Calculating next prime number ... [done] dry-wit dry-wit API 11 / 16
  • 13. Temporary files API functions 1 Functions to create temporary files or folders. 2 dry-wit takes cares of cleaning them up afterwards. createTempFile() createTempFile; local tempFile=${RESULT}; createTempFolder() createTempFolder; local tempFolder=${RESULT}; dry-wit dry-wit API 12 / 16
  • 14. Environment variables: Declaration (1/3) DSL for declaring environment variables 1 Declared in [script].inc.sh. 2 Safe to add to version control systems. 3 Mandatory information: description and default value. defineEnvVar() defineEnvVar MYPASSWORD "The description of MYPASSWORD" "secret"; dry-wit dry-wit API 13 / 16
  • 15. Environment variables: Overridding (2/3) DSL for overridding default values 1 Declared in .[script].inc.sh. 2 Not always safe to add to version control systems. overrideEnvVar() overrideEnvVar MYPASSWORD ".toor!"; dry-wit dry-wit API 14 / 16
  • 16. Environment variables: Overridding (3/3) Environment value overridden from the command line MYPASSWORD="abc123" ./script.sh ... dry-wit dry-wit API 15 / 16
  • 17. Free as in freedom You’re welcome to try, fork, improve, even criticize! https://github.com/rydnr/dry-wit dry-wit Try it 16 / 16