can parse api key
This commit is contained in:
parent
32799b65d5
commit
3c0eece311
7
.env
Normal file
7
.env
Normal file
|
@ -0,0 +1,7 @@
|
|||
SYNCTHING_VERSION=latest
|
||||
PUID=1001
|
||||
PGID=1001
|
||||
TZ=Europe/London
|
||||
SYNC_LISTEN_PORT=22000
|
||||
SYNC1_LISTEN_PORT=22100
|
||||
SYNC2_LISTEN_PORT=22101
|
|
@ -1,12 +1,10 @@
|
|||
FROM python:2.7
|
||||
FROM python:3.9
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ADD requirements.txt /app/requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
ADD app.py /app/app.py
|
||||
ADD syncthing_monitor /app/syncthing_monitor
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
CMD ["python", "-m", "syncthing_monitor"]
|
||||
|
|
16
app.py
16
app.py
|
@ -1,16 +0,0 @@
|
|||
from flask import Flask
|
||||
from redis import Redis
|
||||
|
||||
app = Flask(__name__)
|
||||
redis = Redis(host="redis")
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
visits = redis.incr('counter')
|
||||
html = "<h3>Hello World!</h3>" \
|
||||
"<b>Visits:</b> {visits}" \
|
||||
"<br/>"
|
||||
return html.format(visits=visits)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=80)
|
|
@ -1,12 +1,66 @@
|
|||
sut:
|
||||
build: .
|
||||
dockerfile: Dockerfile.test
|
||||
---
|
||||
version: "2.1"
|
||||
|
||||
services:
|
||||
test:
|
||||
build: integrationtest
|
||||
links:
|
||||
- web
|
||||
web:
|
||||
- sync1
|
||||
- sync2
|
||||
volumes:
|
||||
- sync1data:/data1
|
||||
- sync2data:/data2
|
||||
|
||||
sut1:
|
||||
build: .
|
||||
dockerfile: Dockerfile
|
||||
links:
|
||||
- redis
|
||||
redis:
|
||||
image: redis
|
||||
- sync1
|
||||
volumes:
|
||||
- sync1config:/config:ro
|
||||
|
||||
sync1:
|
||||
image: ghcr.io/linuxserver/syncthing:${SYNCTHING_VERSION}
|
||||
environment:
|
||||
- PUID=${PUID}
|
||||
- PGID=${PGID}
|
||||
- TZ=${TZ}
|
||||
volumes:
|
||||
- sync1config:/config
|
||||
- sync1data:/data
|
||||
ports:
|
||||
- ${SYNC1_LISTEN_PORT}:22000
|
||||
|
||||
sut2:
|
||||
build: .
|
||||
links:
|
||||
- sync2
|
||||
volumes:
|
||||
- sync2config:/config:ro
|
||||
|
||||
sync2:
|
||||
image: ghcr.io/linuxserver/syncthing:${SYNCTHING_VERSION}
|
||||
environment:
|
||||
- PUID=${PUID}
|
||||
- PGID=${PGID}
|
||||
- TZ=${TZ}
|
||||
volumes:
|
||||
- sync2config:/config
|
||||
- sync2data:/data
|
||||
ports:
|
||||
- ${SYNC2_LISTEN_PORT}:22000
|
||||
|
||||
etcd:
|
||||
image: quay.io/coreos/etcd
|
||||
command: /usr/local/bin/etcd --data-dir=/etcd-data
|
||||
ports:
|
||||
- 2379:2379
|
||||
- 2380:2380
|
||||
volumes:
|
||||
- etcd-data:/etcd-data
|
||||
|
||||
volumes:
|
||||
sync1data:
|
||||
sync1config:
|
||||
sync2data:
|
||||
sync2config:
|
||||
etcd-data:
|
|
@ -1,9 +1,29 @@
|
|||
web:
|
||||
---
|
||||
version: "2.1"
|
||||
|
||||
services:
|
||||
syncmon:
|
||||
build: .
|
||||
dockerfile: Dockerfile
|
||||
links:
|
||||
- redis
|
||||
- sync
|
||||
volumes:
|
||||
- syncconfig:/config
|
||||
- syncdata:/data
|
||||
|
||||
sync:
|
||||
image: ghcr.io/linuxserver/syncthing:${SYNCTHING_VERSION}
|
||||
container_name: syncthing
|
||||
hostname: syncthing
|
||||
environment:
|
||||
- PUID=${PUID}
|
||||
- PGID=${PGID}
|
||||
- TZ=${TZ}
|
||||
volumes:
|
||||
- syncconfig:/config
|
||||
- syncdata:/data
|
||||
ports:
|
||||
- "80:80"
|
||||
redis:
|
||||
image: redis
|
||||
- ${SYNC_LISTEN_PORT}:22000
|
||||
|
||||
volumes:
|
||||
syncconfig:
|
||||
syncdata:
|
||||
|
|
12
integrationtest/test.sh
Normal file
12
integrationtest/test.sh
Normal file
|
@ -0,0 +1,12 @@
|
|||
sleep 5
|
||||
echo "test string" > /sync1/testfile
|
||||
echo /sync1/testfile
|
||||
echo /sync2/testfile
|
||||
|
||||
#if curl web | grep -q '<b>Visits:</b> '; then
|
||||
# echo "Tests passed!"
|
||||
# exit 0
|
||||
#else
|
||||
# echo "Tests failed!"
|
||||
# exit 1
|
||||
#fi
|
|
@ -1,2 +0,0 @@
|
|||
Flask
|
||||
Redis
|
0
syncthing_monitor/__init__.py
Normal file
0
syncthing_monitor/__init__.py
Normal file
10
syncthing_monitor/__main__.py
Normal file
10
syncthing_monitor/__main__.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from syncthing_monitor.config_xml import parse_api_key
|
||||
|
||||
|
||||
def loop():
|
||||
api_key = parse_api_key()
|
||||
print("Found API Key: {0}".format(api_key))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop()
|
10
syncthing_monitor/config_xml.py
Normal file
10
syncthing_monitor/config_xml.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from xml.etree import ElementTree as elementTree
|
||||
|
||||
|
||||
def parse_api_key(xml_path='/config/config.xml'):
|
||||
root = elementTree.parse(xml_path).getroot()
|
||||
api_key = ''
|
||||
for gui in root.findall('gui'):
|
||||
# noinspection SpellCheckingInspection
|
||||
api_key = gui.find('apikey').text
|
||||
return api_key
|
8
test.sh
8
test.sh
|
@ -1,8 +0,0 @@
|
|||
sleep 5
|
||||
if curl web | grep -q '<b>Visits:</b> '; then
|
||||
echo "Tests passed!"
|
||||
exit 0
|
||||
else
|
||||
echo "Tests failed!"
|
||||
exit 1
|
||||
fi
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
114
test/test-syncthing-config.xml
Normal file
114
test/test-syncthing-config.xml
Normal file
|
@ -0,0 +1,114 @@
|
|||
<configuration version="32">
|
||||
<folder id="data" label="Data" path="/data" type="sendreceive" rescanIntervalS="3600" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">
|
||||
<filesystemType>basic</filesystemType>
|
||||
<device id="MKXXCDW-3YWBXU4-PWJZU5P-VFOPIMT-22L7BAY-7GZY4I5-TQMLIYY-JSILEQC" introducedBy="">
|
||||
<encryptionPassword></encryptionPassword>
|
||||
</device>
|
||||
<device id="OSRS6BZ-WRXI67N-55XSQSH-X64E4CL-52D7BGZ-7X2CPEX-OMUZ42H-F52URAI" introducedBy="">
|
||||
<encryptionPassword></encryptionPassword>
|
||||
</device>
|
||||
<minDiskFree unit="%">1</minDiskFree>
|
||||
<versioning>
|
||||
<cleanupIntervalS>0</cleanupIntervalS>
|
||||
</versioning>
|
||||
<copiers>0</copiers>
|
||||
<pullerMaxPendingKiB>0</pullerMaxPendingKiB>
|
||||
<hashers>0</hashers>
|
||||
<order>random</order>
|
||||
<ignoreDelete>false</ignoreDelete>
|
||||
<scanProgressIntervalS>0</scanProgressIntervalS>
|
||||
<pullerPauseS>0</pullerPauseS>
|
||||
<maxConflicts>10</maxConflicts>
|
||||
<disableSparseFiles>false</disableSparseFiles>
|
||||
<disableTempIndexes>false</disableTempIndexes>
|
||||
<paused>false</paused>
|
||||
<weakHashThresholdPct>25</weakHashThresholdPct>
|
||||
<markerName>.stfolder</markerName>
|
||||
<copyOwnershipFromParent>false</copyOwnershipFromParent>
|
||||
<modTimeWindowS>0</modTimeWindowS>
|
||||
<maxConcurrentWrites>2</maxConcurrentWrites>
|
||||
<disableFsync>false</disableFsync>
|
||||
<blockPullOrder>standard</blockPullOrder>
|
||||
<copyRangeMethod>standard</copyRangeMethod>
|
||||
<caseSensitiveFS>false</caseSensitiveFS>
|
||||
<junctionsAsDirs>false</junctionsAsDirs>
|
||||
</folder>
|
||||
<device id="MKXXCDW-3YWBXU4-PWJZU5P-VFOPIMT-22L7BAY-7GZY4I5-TQMLIYY-JSILEQC" name="honeydew" compression="metadata" introducer="false" skipIntroductionRemovals="false" introducedBy="">
|
||||
<address>dynamic</address>
|
||||
<paused>false</paused>
|
||||
<allowedNetwork>10.122.122.0/24</allowedNetwork>
|
||||
<autoAcceptFolders>false</autoAcceptFolders>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<maxRequestKiB>0</maxRequestKiB>
|
||||
<untrusted>false</untrusted>
|
||||
<remoteGUIPort>0</remoteGUIPort>
|
||||
</device>
|
||||
<device id="OSRS6BZ-WRXI67N-55XSQSH-X64E4CL-52D7BGZ-7X2CPEX-OMUZ42H-F52URAI" name="blackberry" compression="metadata" introducer="false" skipIntroductionRemovals="false" introducedBy="">
|
||||
<address>tcp://blackberry</address>
|
||||
<paused>false</paused>
|
||||
<allowedNetwork>10.122.122.0/24</allowedNetwork>
|
||||
<autoAcceptFolders>false</autoAcceptFolders>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<maxRequestKiB>0</maxRequestKiB>
|
||||
<untrusted>false</untrusted>
|
||||
<remoteGUIPort>0</remoteGUIPort>
|
||||
</device>
|
||||
<gui enabled="true" tls="false" debugging="true">
|
||||
<address>127.0.0.1:8384</address>
|
||||
<user>syncadmin</user>
|
||||
<password>$2a$10$.nzDwmF2w9gWfPFWto1wmOOek4RzEF/MlolVyzOLsOCXL733IleVC</password>
|
||||
<apikey>dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2</apikey>
|
||||
<theme>default</theme>
|
||||
</gui>
|
||||
<ldap></ldap>
|
||||
<options>
|
||||
<listenAddress>default</listenAddress>
|
||||
<globalAnnounceServer>default</globalAnnounceServer>
|
||||
<globalAnnounceEnabled>false</globalAnnounceEnabled>
|
||||
<localAnnounceEnabled>false</localAnnounceEnabled>
|
||||
<localAnnouncePort>21027</localAnnouncePort>
|
||||
<localAnnounceMCAddr>[ff12::8384]:21027</localAnnounceMCAddr>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<reconnectionIntervalS>60</reconnectionIntervalS>
|
||||
<relaysEnabled>false</relaysEnabled>
|
||||
<relayReconnectIntervalM>10</relayReconnectIntervalM>
|
||||
<startBrowser>true</startBrowser>
|
||||
<natEnabled>false</natEnabled>
|
||||
<natLeaseMinutes>60</natLeaseMinutes>
|
||||
<natRenewalMinutes>30</natRenewalMinutes>
|
||||
<natTimeoutSeconds>10</natTimeoutSeconds>
|
||||
<urAccepted>-1</urAccepted>
|
||||
<urSeen>3</urSeen>
|
||||
<urUniqueID></urUniqueID>
|
||||
<urURL>https://data.syncthing.net/newdata</urURL>
|
||||
<urPostInsecurely>false</urPostInsecurely>
|
||||
<urInitialDelayS>1800</urInitialDelayS>
|
||||
<restartOnWakeup>true</restartOnWakeup>
|
||||
<autoUpgradeIntervalH>12</autoUpgradeIntervalH>
|
||||
<upgradeToPreReleases>false</upgradeToPreReleases>
|
||||
<keepTemporariesH>24</keepTemporariesH>
|
||||
<cacheIgnoredFiles>false</cacheIgnoredFiles>
|
||||
<progressUpdateIntervalS>5</progressUpdateIntervalS>
|
||||
<limitBandwidthInLan>false</limitBandwidthInLan>
|
||||
<minHomeDiskFree unit="%">1</minHomeDiskFree>
|
||||
<releasesURL>https://upgrades.syncthing.net/meta.json</releasesURL>
|
||||
<overwriteRemoteDeviceNamesOnConnect>false</overwriteRemoteDeviceNamesOnConnect>
|
||||
<tempIndexMinBlocks>10</tempIndexMinBlocks>
|
||||
<trafficClass>0</trafficClass>
|
||||
<defaultFolderPath>~</defaultFolderPath>
|
||||
<setLowPriority>true</setLowPriority>
|
||||
<maxFolderConcurrency>0</maxFolderConcurrency>
|
||||
<crashReportingURL>https://crash.syncthing.net/newcrash</crashReportingURL>
|
||||
<crashReportingEnabled>false</crashReportingEnabled>
|
||||
<stunKeepaliveStartS>180</stunKeepaliveStartS>
|
||||
<stunKeepaliveMinS>20</stunKeepaliveMinS>
|
||||
<stunServer>default</stunServer>
|
||||
<databaseTuning>auto</databaseTuning>
|
||||
<maxConcurrentIncomingRequestKiB>0</maxConcurrentIncomingRequestKiB>
|
||||
<announceLANAddresses>false</announceLANAddresses>
|
||||
<sendFullIndexOnUpgrade>false</sendFullIndexOnUpgrade>
|
||||
</options>
|
||||
</configuration>
|
10
test/test_config.py
Normal file
10
test/test_config.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
import unittest
|
||||
|
||||
from syncthing_monitor.config_xml import parse_api_key
|
||||
|
||||
|
||||
class ConfigTests(unittest.TestCase):
|
||||
|
||||
def test_can_parse_api_key(self):
|
||||
# noinspection SpellCheckingInspection
|
||||
self.assertEqual(parse_api_key('test/test-syncthing-config.xml'), "dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2")
|
Loading…
Reference in New Issue
Block a user