Merge branch 'main' into 'NewApproach'

# Conflicts:
#   .gitignore
#   README.md
#   docker-compose.yml
#   fab_access/config.py
#   fab_access/main.py
#   requirements.txt
This commit is contained in:
Luca Lutz 2022-11-04 18:10:55 +00:00
commit 9b52b63ea6
4 changed files with 97 additions and 2 deletions

View File

@ -1,2 +0,0 @@
FROM mysql:5.7
ADD FabAccess.sql /docker-entrypoint-initdb.d

54
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,54 @@
pipeline {
agent any
post {
failure {
updateGitlabCommitStatus name: 'build', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
}
aborted {
updateGitlabCommitStatus name: 'build', state: 'canceled'
}
}
options {
gitLabConnection('GitLab')
}
triggers {
gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All')
}
stages {
stage("build") {
steps {
updateGitlabCommitStatus name: 'build', state: 'running'
podTemplate(
containers: [
containerTemplate(name: 'docker-image-build', image: 'mgoltzsche/podman', ttyEnabled: true, command: 'cat', privileged: true),
]) {
node(POD_LABEL) {
updateGitlabCommitStatus name: 'build', state: 'pending'
checkout([$class: 'GitSCM', branches: [
[name: '*/main']
], userRemoteConfigs: [
[url: 'https://gitlab.com/luca_lutz/fabaccess.git']
]])
container('docker-image-build') {
withCredentials([
usernamePassword(credentialsId: 'docker.credentials',
usernameVariable: 'DOCKER_USERNAME',
passwordVariable: 'DOCKER_PASSWORD')
]) {
sh 'echo $(date +%s) > /time'
sh 'echo "nameserver 10.12.42.2" > /etc/resolv.conf'
sh 'podman build --tag docker.sfz-aalen.space/hackwerk/fabaccess:$(cat /time) .'
sh 'podman login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} docker.sfz-aalen.space'
sh 'podman push docker.sfz-aalen.space/hackwerk/fabaccess:$(cat /time)'
}
}
}
}
}
}
}
}

32
fab_access/mqtt_helper.py Normal file
View File

@ -0,0 +1,32 @@
from paho.mqtt import client as mqtt_client
import config
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
else:
raise Exception("Failed to connect, return code %d\n", rc)
class MQTTHelper():
def __init__(self, client_name: str, username: str, password: str, broker: str, port: int):
client = mqtt_client.Client(client_name)
if username and password:
client.username_pw_set(username, password)
else:
print("Connecting to MQTT without credentials")
client.on_connect = on_connect
try:
client.connect(broker, port)
except Exception as e:
raise Exception(f"Error connecting to MQTT {broker}:{port}") from e
self.client = client
def subscribe(self, topic: str, handler):
self.client.subscribe(topic)
self.client.on_message = handler
def loop_forever(self):
self.client.loop_forever()

11
sql/FabAccess.sql Normal file
View File

@ -0,0 +1,11 @@
CREATE TABLE ReaderPlug(
ReaderID INT NOT NULL,
PlugName VARCHAR(255) NOT NULL,
PermissionPath VARCHAR(255) NOT NULL,
Status BOOLEAN NOT NULL,
LastUser VARCHAR(255) NOT NULL
);
INSERT INTO ReaderPlug(
ReaderID, PlugName, PermissionPath, Status, LastUser
) VALUES (1, 'lasercutter', 'sfz.lasercutter.trotec', false, 'luca.lutz');