Debian Codegraph @

cylc/flow/network/authentication.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """Authentication key setup"""
17
18 from cylc.flow.workflow_files import (
19 KeyInfo,
20 KeyOwner,
21 KeyType,
22 create_server_keys,
23 get_workflow_srv_dir,
24 remove_keys_on_server)
25
26
27 def key_housekeeping(id_, platform=None, create=True):
28
29 """Clean any existing authentication keys and create new ones.
30 If create is set to false, keys will only be cleaned from
31 server."""
32 workflow_srv_dir = get_workflow_srv_dir(id_)
33 keys = {
34 "client_public_key": KeyInfo(
35 KeyType.PUBLIC,
36 KeyOwner.CLIENT,
37 workflow_srv_dir=workflow_srv_dir, install_target=platform),
38 "client_private_key": KeyInfo(
39 KeyType.PRIVATE,
40 KeyOwner.CLIENT,
41 workflow_srv_dir=workflow_srv_dir),
42 "server_public_key": KeyInfo(
43 KeyType.PUBLIC,
44 KeyOwner.SERVER,
45 workflow_srv_dir=workflow_srv_dir),
46 "server_private_key": KeyInfo(
47 KeyType.PRIVATE,
48 KeyOwner.SERVER,
49 workflow_srv_dir=workflow_srv_dir)
50 }
51 remove_keys_on_server(keys)
52 if create:
53 create_server_keys(keys, workflow_srv_dir)