-
Notifications
You must be signed in to change notification settings - Fork 200
/
config.py
70 lines (54 loc) · 2 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from . import base
class Section(base.SectionBase):
@base.returns_single_item
def get(self, **kwargs):
#TODO: Support the optional `key` parameter
"""Returns the current used server configuration.
.. code-block:: python
>>> config = client.config.get()
>>> config['Addresses']
{'API': '/ip4/127.0.0.1/tcp/5001',
'Gateway': '/ip4/127.0.0.1/tcp/8080',
'Swarm': ['/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001']},
>>> config['Discovery']
{'MDNS': {'Enabled': True, 'Interval': 10}}
Returns
-------
dict
The entire IPFS daemon configuration
"""
return self._client.request('/config/show', decoder='json', **kwargs)
@base.returns_single_item
def replace(self, config, **kwargs):
"""Replaces the existing configuration with a new configuration tree.
Make sure to back up the config file first if neccessary, as this
operation can not be undone.
"""
return self._client.request('/config/replace', (config,), decoder='json', **kwargs)
@base.returns_single_item
def set(self, key, value=None, **kwargs):
"""Add or replace a single configuration value.
.. code-block:: python
>>> client.config.set("Addresses.Gateway")
{'Key': 'Addresses.Gateway', 'Value': '/ip4/127.0.0.1/tcp/8080'}
>>> client.config.set("Addresses.Gateway", "/ip4/127.0.0.1/tcp/8081")
{'Key': 'Addresses.Gateway', 'Value': '/ip4/127.0.0.1/tcp/8081'}
Parameters
----------
key : str
The key of the configuration entry (e.g. "Addresses.API")
value : dict
The value to set the configuration entry to
Returns
-------
dict
+-------+---------------------------------------------+
| Key | The requested configuration key |
+-------+---------------------------------------------+
| Value | The new value of the this configuration key |
+-------+---------------------------------------------+
"""
args = (key, value)
return self._client.request('/config', args, decoder='json', **kwargs)