Skip to content

Commit

Permalink
Moved container name sanitisation code to puppet function. (puppetlab…
Browse files Browse the repository at this point in the history
…s#401)

Make sanitisation code available for external modules
so it can be reused when working with scripts and container names.
  • Loading branch information
glorpen authored and davejrt committed Jan 8, 2019
1 parent 73c6424 commit 2169b8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* [Defined types](#definedtypes)
* [Types](#types)
* [Parameters](#parameters)
* [Functions](#functions)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)

Expand Down Expand Up @@ -1503,6 +1504,12 @@ Extends the pool by the specified percentage when the threshold is passed.

For further explanation please refer to the[PE documentation](https://puppet.com/docs/pe/2017.3/orchestrator/running_tasks.html) or [Bolt documentation](https://puppet.com/docs/bolt/latest/bolt.html) on how to execute a task.

### Functions

#### `docker::sanitised_name`

Sanitises string or array of strings for safe usage as container name inside scripts and commands.

## Limitations

This module supports:
Expand Down
12 changes: 12 additions & 0 deletions functions/sanitised_name.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# == Function: docker::sanitised_name
#
# Function to sanitise container name.
#
# === Parameters
#
# [*name*]
# Name to sanitise
#
function docker::sanitised_name($name){
regsubst($name, '[^0-9A-Za-z.\-_]', '-', 'G')
}
6 changes: 3 additions & 3 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@
osfamily => $::osfamily,
})

$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-_]', '-', 'G')
$sanitised_title = docker::sanitised_name($title)
if empty($depends_array) {
$sanitised_depends_array = []
}
else {
$sanitised_depends_array = regsubst($depends_array, '[^0-9A-Za-z.\-_]', '-', 'G')
$sanitised_depends_array = docker::sanitised_name($depends_array)
}

if empty($after_array) {
$sanitised_after_array = []
}
else {
$sanitised_after_array = regsubst($after_array, '[^0-9A-Za-z.\-_]', '-', 'G')
$sanitised_after_array = docker::sanitised_name($after_array)
}

if $::osfamily == 'windows' {
Expand Down

0 comments on commit 2169b8b

Please sign in to comment.