Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Systemd::Unit type stricter #290

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* [`Systemd::MachineInfoSettings`](#systemdmachineinfosettings): Matches Systemd machine-info (hostnamectl) file Struct
* [`Systemd::OomdSettings`](#systemdoomdsettings): Configurations for oomd.conf
* [`Systemd::ServiceLimits`](#systemdservicelimits): Matches Systemd Service Limit Struct
* [`Systemd::Unit`](#systemdunit): custom datatype that validates different filenames for systemd units
* [`Systemd::Unit`](#systemdunit): custom datatype that validates different filenames for systemd units and unit templates

## Classes

Expand Down Expand Up @@ -1803,11 +1803,14 @@ Struct[{

### <a name="systemdunit"></a>`Systemd::Unit`

custom datatype that validates different filenames for systemd units
custom datatype that validates different filenames for systemd units and unit templates

* **See also**
* https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Alias of

```puppet
Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']
Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]
```

32 changes: 32 additions & 0 deletions spec/type_aliases/unit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Systemd::Unit' do
context 'with a permitted unit name' do
[
'foo.service',
'foo.socket',
'atemplate@.service',
'atemplate@instance.service',
'backward\slash.swap',
'extra.dot.scope',
'a:colon.path',
'an_underscore.device',
'a-dash.slice',
].each do |unit|
it { is_expected.to allow_value(unit.to_s) }
end
end

context 'with a illegal unit name' do
[
'a space.service',
'noending',
'wrong.ending',
'forward/slash.unit',
].each do |unit|
it { is_expected.not_to allow_value(unit.to_s) }
end
end
end
5 changes: 3 additions & 2 deletions types/unit.pp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# @summary custom datatype that validates different filenames for systemd units
type Systemd::Unit = Pattern['^[^/]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$']
# @summary custom datatype that validates different filenames for systemd units and unit templates
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]