Skip to content

Commit eee303f

Browse files
committed
rename url to source and allow it to be AbsolutePath
This fixes a regression with previous functionality!
1 parent f87af03 commit eee303f

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

libioc/Provisioning/puppet.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,33 @@ def __init__(
5454
class ControlRepoDefinition(dict):
5555
"""Puppet control-repo definition."""
5656

57-
_url: str
57+
_source: str
5858
_pkgs: typing.List[str]
5959

6060
def __init__(
6161
self,
62-
url: urllib.parse.DefragResult,
62+
source: typing.Union[
63+
urllib.parse.DefragResult,
64+
libioc.Types.AbsolutePath
65+
],
6366
logger: 'libioc.Logger.Logger'
6467
) -> None:
6568
self.logger = logger
6669

67-
if isinstance(url, urllib.parse.ParseResult) is False:
68-
raise TypeError("Source must be an URL")
69-
self.url = url
70+
if isinstance(source, libioc.Types.AbsolutePath) is False \
71+
and isinstance(source, urllib.parse.ParseResult) is False:
72+
raise TypeError("Source must be an URL or an absolute path")
73+
self.source = source
7074

7175
self._pkgs = ['puppet6'] # make this a Global Varialbe
72-
if not (self.url.startswith('file://') or self.url.startswith('/')):
76+
if isinstance(source, libioc.Types.AbsolutePath) is False:
7377
self._pkgs += 'rubygem-r10k'
7478

7579
@property
7680
def local(self) -> bool:
7781
"""Return whether this control repo resides locally."""
78-
_url = self.url
79-
if not (_url.startswith('file://') or _url.startswith('/')):
82+
_source = self.source
83+
if isinstance(_source, libioc.Types.AbsolutePath) is False:
8084
return False
8185
return True
8286

@@ -86,28 +90,30 @@ def remote(self) -> bool:
8690
return not self.local
8791

8892
@property
89-
def url(self) -> str:
93+
def source(self) -> str:
9094
"""Return the Puppet Control-Repo URL."""
91-
return self._url
95+
return self._source
9296

93-
@url.setter
94-
def url(self, value: typing.Union[urllib.parse.ParseResult, str]) -> None:
97+
@source.setter
98+
def source(self, value: typing.Union[
99+
urllib.parse.ParseResult,
100+
libioc.Types.AbsolutePath
101+
]) -> None:
95102
"""Set the Puppet Control-Repo URL."""
96-
_url: urllib.parse.ParseResult
103+
_source: urllib.parse.ParseResult
97104
if isinstance(value, urllib.parse.ParseResult) is True:
98-
_url = typing.cast(urllib.parse.ParseResult, value)
99-
elif isinstance(value, str) is True:
100-
_url = urllib.parse.urlparse(
101-
str(value),
102-
allow_fragments=False
103-
)
104-
else:
105-
raise TypeError("URL must be urllib.parse.ParseResult or string")
105+
_source = typing.cast(urllib.parse.ParseResult, value)
106+
if _source.fragment != "":
107+
raise ValueError("URL may not contain fragment")
106108

107-
if _url.fragment != "":
108-
raise ValueError("URL may not contain fragment")
109+
self._source = _source.geturl()
110+
elif isinstance(value, libioc.Types.AbsolutePath) is True:
111+
_source = value
112+
else:
113+
raise TypeError(
114+
"Source must be urllib.parse.ParseResult or absolute path"
115+
)
109116

110-
self._url = _url.geturl()
111117

112118
@property
113119
def pkgs(self) -> typing.List[str]:
@@ -116,6 +122,7 @@ def pkgs(self) -> typing.List[str]:
116122

117123
def generate_postinstall(self) -> str:
118124
"""Return list of strings representing our postinstall."""
125+
basedir = "/usr/local/etc/puppet/environments"
119126
postinstall = """#!/bin/sh
120127
set -eu
121128
@@ -126,8 +133,8 @@ def generate_postinstall(self) -> str:
126133
---
127134
:source:
128135
puppet:
129-
basedir: /usr/local/etc/puppet/environments
130-
remote: {self.url}
136+
basedir: {basedir}
137+
remote: {self.source}
131138
>EOF
132139
133140
r10k deploy environment -p

0 commit comments

Comments
 (0)