Skip to content

Commit f87af03

Browse files
committed
puppet provisioning uses urllib.parse
1 parent 3cdd4a5 commit f87af03

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

libioc/Provisioning/puppet.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""iocage provisioner for use with `puppet apply`."""
2525
import typing
2626
import os.path
27+
import urllib.parse
2728

2829
import git
2930

@@ -54,27 +55,28 @@ class ControlRepoDefinition(dict):
5455
"""Puppet control-repo definition."""
5556

5657
_url: str
57-
_name: str
5858
_pkgs: typing.List[str]
5959

6060
def __init__(
6161
self,
62-
name: str,
63-
url: str,
62+
url: urllib.parse.DefragResult,
6463
logger: 'libioc.Logger.Logger'
6564
) -> None:
6665
self.logger = logger
66+
67+
if isinstance(url, urllib.parse.ParseResult) is False:
68+
raise TypeError("Source must be an URL")
6769
self.url = url
68-
self.name = name
6970

70-
_pkgs = ['puppet6'] # make this a Global Varialbe
71-
if not (url.startswith('file://') or url.startswith('/')):
72-
_pkgs += 'rubygem-r10k'
71+
self._pkgs = ['puppet6'] # make this a Global Varialbe
72+
if not (self.url.startswith('file://') or self.url.startswith('/')):
73+
self._pkgs += 'rubygem-r10k'
7374

7475
@property
7576
def local(self) -> bool:
7677
"""Return whether this control repo resides locally."""
77-
if not (self.url.startswith('file://') or self.url.startswith('/')):
78+
_url = self.url
79+
if not (_url.startswith('file://') or _url.startswith('/')):
7880
return False
7981
return True
8082

@@ -86,22 +88,26 @@ def remote(self) -> bool:
8688
@property
8789
def url(self) -> str:
8890
"""Return the Puppet Control-Repo URL."""
89-
return str(self._url)
91+
return self._url
9092

9193
@url.setter
92-
def url(self, value: str) -> None:
94+
def url(self, value: typing.Union[urllib.parse.ParseResult, str]) -> None:
9395
"""Set the Puppet Control-Repo URL."""
94-
self._url = value
96+
_url: urllib.parse.ParseResult
97+
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")
95106

96-
@property
97-
def name(self) -> str:
98-
"""Return the unique name for this Puppet Control-Repo URL."""
99-
return self._name
107+
if _url.fragment != "":
108+
raise ValueError("URL may not contain fragment")
100109

101-
@name.setter
102-
def name(self, value: str) -> None:
103-
"""Set a unique name for this Puppet Control-Repo URL."""
104-
self._name = value
110+
self._url = _url.geturl()
105111

106112
@property
107113
def pkgs(self) -> typing.List[str]:
@@ -148,7 +154,6 @@ def provision(
148154
ioc set \
149155
provisioning.method=puppet \
150156
provisioning.source=http://example.com/my/puppet-env \
151-
provisioning.name=my-puppet-env \
152157
myjail
153158
154159
"""
@@ -168,8 +173,7 @@ def provision(
168173
try:
169174
yield jailProvisioningAssetDownloadEvent.begin()
170175
pluginDefinition = ControlRepoDefinition(
171-
name=self.name,
172-
url=self.source,
176+
url=urllib.parse.urlparse(self.source).geturl(),
173177
logger=self.jail.logger
174178
)
175179
yield jailProvisioningAssetDownloadEvent.end()

0 commit comments

Comments
 (0)