-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplatform_git.py
More file actions
51 lines (35 loc) · 1.49 KB
/
platform_git.py
File metadata and controls
51 lines (35 loc) · 1.49 KB
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
##########################################################################
# This file provides an example of the broadcast API using Git #
##########################################################################
import configparser
from git import Repo
def broadcast_data(encrypted_message):
"""Write the encrypted_message to the git repository
:param encrypted_message: bytes = b'...' a sequence of octets
:returns:None
:rtype: None
"""
settings = configparser.ConfigParser()
settings.read('server_configuration.ini')
repository_path = settings.get('platform-configuration', 'repository-path')
with open("{}/encrypted".format(repository_path), 'wb') as encrypted_ip:
encrypted_ip.write(encrypted_message)
repo = Repo(repository_path)
repo.index.add(["{}/encrypted".format(repository_path)])
repo.index.commit("update")
origin = repo.remote(name='origin')
origin.push()
def read_data():
"""Read the encrypted IP from the git repository
:returns: returns the encrypted IP
:rtype: bytes
"""
settings = configparser.ConfigParser()
settings.read('server_configuration.ini')
repository_path = settings.get('platform-configuration', 'repository-path')
repo = Repo(repository_path)
origin = repo.remote(name='origin')
origin.pull()
with open("{}/encrypted".format(repository_path), 'rb') as encrypted_ip:
data = encrypted_ip.read()
return data