Skip to content

Commit 21f329a

Browse files
authored
Merge pull request #75 from ushiboy/develop
Release 1.5.0
2 parents 8ef4246 + 6fa84c7 commit 21f329a

7 files changed

Lines changed: 92 additions & 64 deletions

File tree

.github/workflows/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: develop action
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
48

59
jobs:
610
build:

README.md

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
nmcli
2-
=====
1+
# nmcli
32

43
nmcli is a python wrapper library for the network-manager cli client.
54

@@ -31,62 +30,61 @@ except Exception as e:
3130

3231
## Dependency
3332

34-
* NetworkManager
35-
* `sudo apt install network-manager` (Debian)
36-
* User who can execute nmcli with sudo with NOPASSWD
37-
* If sudo is not needed (like root user), use `disable_use_sudo` at the beginning of the process.
33+
- NetworkManager
34+
- `sudo apt install network-manager` (Debian)
35+
- User who can execute nmcli with sudo with NOPASSWD
36+
- If sudo is not needed (like root user), use `disable_use_sudo` at the beginning of the process.
3837

3938
## Compatibility table
4039

41-
| Object | Command | Status |
42-
|--------|---------|--------|
43-
| general | | supported |
44-
| general | status | supported |
45-
| general | hostname | supported |
46-
| general | permissions | not supported |
47-
| general | logging | not supported |
48-
| networking | | supported |
49-
| networking | on | supported |
50-
| networking | off | supported |
51-
| networking | connectivity | supported |
52-
| radio | | supported |
53-
| radio | all | supported |
54-
| radio | wifi | supported |
55-
| radio | wwan | supported |
56-
| connection | | supported |
57-
| connection | show | supported |
58-
| connection | up | supported |
59-
| connection | down | supported |
60-
| connection | add | supported |
61-
| connection | modify | supported |
62-
| connection | clone | not supported |
63-
| connection | edit | not supported |
64-
| connection | delete | supported |
65-
| connection | reload | supported |
66-
| connection | load | not supported |
67-
| connection | import | not supported |
68-
| connection | export | not supported |
69-
| device | | supported |
70-
| device | status | supported |
71-
| device | show | supported |
72-
| device | set | not supported |
73-
| device | connect | supported |
74-
| device | reapply | supported |
75-
| device | modify | not supported |
76-
| device | disconnect | supported |
77-
| device | delete | supported |
78-
| device | monitor | not supported |
79-
| device | wifi | supported |
80-
| device | wifi connect | supported |
81-
| device | wifi rescan | supported |
82-
| device | wifi hotspot | supported |
83-
| device | lldp | not supported |
84-
| agent | | not supported |
85-
| agent | secret | not supported |
86-
| agent | polkit | not supported |
87-
| agent | all | not supported |
88-
| monitor | | not supported |
89-
40+
| Object | Command | Status |
41+
| ---------- | ------------ | ------------- |
42+
| general | | supported |
43+
| general | status | supported |
44+
| general | hostname | supported |
45+
| general | permissions | not supported |
46+
| general | logging | not supported |
47+
| networking | | supported |
48+
| networking | on | supported |
49+
| networking | off | supported |
50+
| networking | connectivity | supported |
51+
| radio | | supported |
52+
| radio | all | supported |
53+
| radio | wifi | supported |
54+
| radio | wwan | supported |
55+
| connection | | supported |
56+
| connection | show | supported |
57+
| connection | up | supported |
58+
| connection | down | supported |
59+
| connection | add | supported |
60+
| connection | modify | supported |
61+
| connection | clone | not supported |
62+
| connection | edit | not supported |
63+
| connection | delete | supported |
64+
| connection | reload | supported |
65+
| connection | load | not supported |
66+
| connection | import | not supported |
67+
| connection | export | not supported |
68+
| device | | supported |
69+
| device | status | supported |
70+
| device | show | supported |
71+
| device | set | not supported |
72+
| device | connect | supported |
73+
| device | reapply | supported |
74+
| device | modify | not supported |
75+
| device | disconnect | supported |
76+
| device | delete | supported |
77+
| device | monitor | not supported |
78+
| device | wifi | supported |
79+
| device | wifi connect | supported |
80+
| device | wifi rescan | supported |
81+
| device | wifi hotspot | supported |
82+
| device | lldp | not supported |
83+
| agent | | not supported |
84+
| agent | secret | not supported |
85+
| agent | polkit | not supported |
86+
| agent | all | not supported |
87+
| monitor | | not supported |
9088

9189
## API
9290

@@ -155,8 +153,10 @@ nmcli.connection.down(name: str, wait: int = None) -> None
155153

156154
Show details for specified connections.
157155

156+
Use `show_secrets` argument to reveal associated secrets as well.
157+
158158
```
159-
nmcli.connection.show(name: str) -> ConnectionDetails
159+
nmcli.connection.show(name: str, show_secrets: bool = False) -> ConnectionDetails
160160
```
161161

162162
#### nmcli.connection.reload
@@ -239,7 +239,6 @@ Delete the software devices.
239239

240240
The `wait` argument applies the same effect to the command as the `--wait` option. If it is omitted, the default behavior is followed.
241241

242-
243242
```
244243
nmcli.device.delete(ifname: str, wait: int = None) -> None
245244
```
@@ -459,6 +458,10 @@ nmcli.set_lang(lang: str) -> None
459458

460459
## Change Log
461460

461+
### 1.5.0
462+
463+
- Added show_secrets option to `nmcli.connection.show`
464+
462465
### 1.4.0
463466

464467
- Supported unsupported cases of `DeviceWifi.parse`.

nmcli/_connection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def up(self, name: str, wait: int = None) -> None:
3131
def down(self, name: str, wait: int = None) -> None:
3232
raise NotImplementedError
3333

34-
def show(self, name: str) -> ConnectionDetails:
34+
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
3535
raise NotImplementedError
3636

3737
def reload(self) -> None:
@@ -88,8 +88,11 @@ def down(self, name: str, wait: int = None) -> None:
8888
wait) + ['connection', 'down', name]
8989
self._syscmd.nmcli(cmd)
9090

91-
def show(self, name: str) -> ConnectionDetails:
92-
r = self._syscmd.nmcli(['connection', 'show', name])
91+
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
92+
cmd = ['connection', 'show', name]
93+
if show_secrets:
94+
cmd += ["--show-secrets"]
95+
r = self._syscmd.nmcli(cmd)
9396
results = {}
9497
for row in r.split('\n'):
9598
m = re.search(r'^(\S+):\s*([\S\s]+)\s*', row)

nmcli/dummy/_connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def up_args(self):
2727
def down_args(self):
2828
return self._down_args
2929

30+
@property
31+
def show_args(self):
32+
return self._show_args
33+
3034
@property
3135
def called_reload(self) -> int:
3236
return self._called_reload
@@ -43,6 +47,7 @@ def __init__(self,
4347
self._delete_args: List[Tuple] = []
4448
self._up_args: List[Tuple] = []
4549
self._down_args: List[Tuple] = []
50+
self._show_args: List[Tuple] = []
4651
self._called_reload = 0
4752

4853
def __call__(self) -> List[Connection]:
@@ -74,8 +79,9 @@ def down(self, name: str, wait: int = None) -> None:
7479
self._raise_error_if_needed()
7580
self._down_args.append((name, wait))
7681

77-
def show(self, name: str) -> ConnectionDetails:
82+
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
7883
self._raise_error_if_needed()
84+
self._show_args.append((name, show_secrets))
7985
if not self._result_show is None:
8086
return self._result_show
8187
raise ValueError("'result_show' is not properly initialized")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def run_tests(self):
1313

1414
setup(
1515
name='nmcli',
16-
version='1.4.0',
16+
version='1.5.0',
1717
author='ushiboy',
1818
license='MIT',
1919
license_files = ('LICENSE.txt',),

tests/dummy/test_connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ def test_show():
110110
'key': 'value'
111111
}
112112
c = DummyConnectionControl(result_show=result_show)
113+
113114
name = 'MyHome'
114115
assert c.show(name) == result_show
116+
assert c.show_args[0] == (name, False)
117+
118+
c.show(name, show_secrets=True)
119+
assert c.show_args[1] == (name, True)
115120

116121

117122
def test_show_when_raise_error():

tests/test_connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,21 @@ def test_show():
112112
buf = f.read()
113113
s = DummySystemCommand(buf)
114114
connection = ConnectionControl(s)
115-
r = connection.show('Wired connection 1')
115+
name = 'Wired connection 1'
116+
117+
r = connection.show(name)
118+
assert s.passed_parameters == ['connection', 'show', name]
116119
assert len(r.keys()) == 114
117120
assert r['connection.id'] == 'Wired connection 1'
118121
assert r['connection.stable-id'] is None
119122
assert r['ipv4.dns-options'] is None
120123
assert r['IP4.ADDRESS[1]'] == '192.168.1.10/24'
121124
assert r['DHCP6.OPTION[8]'] == 'requested_dhcp6_name_servers = 1'
122125

126+
connection.show(name, show_secrets=True)
127+
assert s.passed_parameters == [
128+
'connection', 'show', name, "--show-secrets"]
129+
123130

124131
def test_reload():
125132
s = DummySystemCommand()

0 commit comments

Comments
 (0)