Skip to content

Commit 010ca98

Browse files
committed
File contents can now be only strings
Allowing file contents to be represented with lists added unnecessary complexity also in UI implementations.
1 parent 75c259d commit 010ca98

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

docs/source/backends/openwrt.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ dictionary is structured as follows:
202202
+===================+================+==========+==========================================================+
203203
| ``path`` | string | yes | path of the file in the tar.gz archive |
204204
+-------------------+----------------+----------+----------------------------------------------------------+
205-
| ``contents`` | string or list | yes | | *string*: plain text contents of the file |
206-
| | | | | *list*: lines of strings representing lines of file |
205+
| ``contents`` | string | yes | plain text contents of the file, new lines must be |
206+
| | | | encoded as `\n` |
207207
+-------------------+----------------+----------+----------------------------------------------------------+
208208
| ``mode`` | string | no | permissions, if omitted will default to ``0644`` |
209209
+-------------------+----------------+----------+----------------------------------------------------------+

netjsonconfig/backends/openwrt/schema.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,8 @@
297297
"type": "string"
298298
},
299299
"contents": {
300-
"anyOf": [
301-
{"type": "string", "format": "textarea"},
302-
{"type": "array"}
303-
]
300+
"type": "string",
301+
"format": "textarea"
304302
},
305303
"mode": {
306304
"type": "string",

tests/openwrt/test_backend.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ def test_file_inclusion(self):
284284
"files": [
285285
{
286286
"path": "/etc/crontabs/root",
287-
"contents": [
288-
'* * * * * echo "test" > /etc/testfile',
289-
'* * * * * echo "test2" > /etc/testfile2'
290-
]
287+
"contents": '* * * * * echo "test" > /etc/testfile\n'
288+
'* * * * * echo "test2" > /etc/testfile2'
291289
},
292290
{
293291
"path": "/etc/dummy.conf",
@@ -304,7 +302,7 @@ def test_file_inclusion(self):
304302
# first file
305303
crontab = tar.getmember('etc/crontabs/root')
306304
contents = tar.extractfile(crontab).read().decode()
307-
self.assertEqual(contents, '\n'.join(o.config['files'][0]['contents']))
305+
self.assertEqual(contents, o.config['files'][0]['contents'])
308306
self.assertEqual(crontab.mtime, 0)
309307
self.assertEqual(crontab.mode, 420)
310308
# second file
@@ -314,27 +312,6 @@ def test_file_inclusion(self):
314312
self.assertEqual(dummy.mode, 420)
315313
tar.close()
316314

317-
def test_file_inclusion_list_contents(self):
318-
o = OpenWrt({
319-
"files": [
320-
{
321-
"path": "/root/.ssh/authorized_keys",
322-
"contents": [
323-
"key1 user@machine1",
324-
"key2 user@machine2",
325-
"key3 user@machine3",
326-
]
327-
}
328-
]
329-
})
330-
tar = tarfile.open(fileobj=o.generate(), mode='r')
331-
self.assertEqual(len(tar.getmembers()), 1)
332-
# check file
333-
crontab = tar.getmember('root/.ssh/authorized_keys')
334-
contents = tar.extractfile(crontab).read().decode()
335-
self.assertEqual(contents, '\n'.join(o.config['files'][0]['contents']))
336-
tar.close()
337-
338315
def test_file_permissions(self):
339316
o = OpenWrt({
340317
"files": [

0 commit comments

Comments
 (0)