@@ -54,29 +54,33 @@ def __init__(
54
54
class ControlRepoDefinition (dict ):
55
55
"""Puppet control-repo definition."""
56
56
57
- _url : str
57
+ _source : str
58
58
_pkgs : typing .List [str ]
59
59
60
60
def __init__ (
61
61
self ,
62
- url : urllib .parse .DefragResult ,
62
+ source : typing .Union [
63
+ urllib .parse .DefragResult ,
64
+ libioc .Types .AbsolutePath
65
+ ],
63
66
logger : 'libioc.Logger.Logger'
64
67
) -> None :
65
68
self .logger = logger
66
69
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
70
74
71
75
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 :
73
77
self ._pkgs += 'rubygem-r10k'
74
78
75
79
@property
76
80
def local (self ) -> bool :
77
81
"""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 :
80
84
return False
81
85
return True
82
86
@@ -86,28 +90,30 @@ def remote(self) -> bool:
86
90
return not self .local
87
91
88
92
@property
89
- def url (self ) -> str :
93
+ def source (self ) -> str :
90
94
"""Return the Puppet Control-Repo URL."""
91
- return self ._url
95
+ return self ._source
92
96
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 :
95
102
"""Set the Puppet Control-Repo URL."""
96
- _url : urllib .parse .ParseResult
103
+ _source : urllib .parse .ParseResult
97
104
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" )
106
108
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
+ )
109
116
110
- self ._url = _url .geturl ()
111
117
112
118
@property
113
119
def pkgs (self ) -> typing .List [str ]:
@@ -116,6 +122,7 @@ def pkgs(self) -> typing.List[str]:
116
122
117
123
def generate_postinstall (self ) -> str :
118
124
"""Return list of strings representing our postinstall."""
125
+ basedir = "/usr/local/etc/puppet/environments"
119
126
postinstall = """#!/bin/sh
120
127
set -eu
121
128
@@ -126,8 +133,8 @@ def generate_postinstall(self) -> str:
126
133
---
127
134
:source:
128
135
puppet:
129
- basedir: /usr/local/etc/puppet/environments
130
- remote: {self.url }
136
+ basedir: {basedir}
137
+ remote: {self.source }
131
138
>EOF
132
139
133
140
r10k deploy environment -p
0 commit comments