mirror of
https://github.com/rocky-linux/ansible-role-kojihub.git
synced 2024-11-22 04:41:31 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
d47474616f
commit
393c7bef11
@ -40,5 +40,3 @@ There are numerous other options within the [defaults/main.yml](./defaults/main.
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
The [changelog](./CHANGELOG.md) is stored externally
|
The [changelog](./CHANGELOG.md) is stored externally
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# Koji callback sent to Rocky Linux mqtt
|
# Koji callback sent to Rocky Linux mqtt
|
||||||
#
|
#
|
||||||
# Adapted from https://gitlab.cern.ch/linuxsupport/rpms/koji-hub-plugins-cern/blob/master/src/mash.py
|
# Adapted from https://gitlab.cern.ch/linuxsupport/rpms/koji-hub-plugins-cern/blob/master/src/mash.py
|
||||||
#
|
#
|
||||||
# License: GPLv2
|
# License: GPLv2
|
||||||
# Authors:
|
# Authors:
|
||||||
# Alex (dot) Iribarren (at) cern (dot) ch (original script)
|
# Alex (dot) Iribarren (at) cern (dot) ch (original script)
|
||||||
# Thomas (dot) Oulevey (at) cern (dot) ch (mqtt version)
|
# Thomas (dot) Oulevey (at) cern (dot) ch (mqtt version)
|
||||||
|
|
||||||
import koji
|
import koji
|
||||||
from koji import PluginError
|
from koji import PluginError
|
||||||
from koji.context import context
|
from koji.context import context
|
||||||
@ -16,25 +16,25 @@ import ConfigParser
|
|||||||
import logging
|
import logging
|
||||||
import base64, json
|
import base64, json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# mqtt client
|
# mqtt client
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
CONFIG_FILE = '/etc/koji-hub/plugins/rockymsg.conf'
|
CONFIG_FILE = '/etc/koji-hub/plugins/rockymsg.conf'
|
||||||
PLUGIN_NAME = 'koji.plugin.rockymsg'
|
PLUGIN_NAME = 'koji.plugin.rockymsg'
|
||||||
DEFAULT_ARCHES = 'x86_64'
|
DEFAULT_ARCHES = 'x86_64'
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
tagCache = {}
|
tagCache = {}
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
global config
|
global config
|
||||||
if config:
|
if config:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = ConfigParser.SafeConfigParser()
|
||||||
config.read(CONFIG_FILE)
|
config.read(CONFIG_FILE)
|
||||||
|
|
||||||
if not config.has_section('rockymsg'):
|
if not config.has_section('rockymsg'):
|
||||||
config.add_section('rockymsg')
|
config.add_section('rockymsg')
|
||||||
if not config.has_option('rockymsg', 'host'):
|
if not config.has_option('rockymsg', 'host'):
|
||||||
@ -61,33 +61,33 @@ def get_config():
|
|||||||
config.set('rockymsg' 'tls_version', '2')
|
config.set('rockymsg' 'tls_version', '2')
|
||||||
if not config.has_option('rockymsg', 'exclude_tags'):
|
if not config.has_option('rockymsg', 'exclude_tags'):
|
||||||
config.set('rockymsg', 'exclude_tags', '')
|
config.set('rockymsg', 'exclude_tags', '')
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def mqtt_on_publish(client,userdata,result):
|
def mqtt_on_publish(client,userdata,result):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _dispatch_on_topic(payload):
|
def _dispatch_on_topic(payload):
|
||||||
logger = logging.getLogger(PLUGIN_NAME)
|
logger = logging.getLogger(PLUGIN_NAME)
|
||||||
|
|
||||||
config = get_config()
|
config = get_config()
|
||||||
if not config:
|
if not config:
|
||||||
raise PluginError('Unable to use the bus, config not found')
|
raise PluginError('Unable to use the bus, config not found')
|
||||||
|
|
||||||
if not payload['tag']:
|
if not payload['tag']:
|
||||||
logger.info('No tag specified')
|
logger.info('No tag specified')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
exclude_tags = config.get('rockymsg', 'exclude_tags')
|
exclude_tags = config.get('rockymsg', 'exclude_tags')
|
||||||
if exclude_tags:
|
if exclude_tags:
|
||||||
exclude_tags = [x.strip() for x in exclude_tags.split(',')]
|
exclude_tags = [x.strip() for x in exclude_tags.split(',')]
|
||||||
else:
|
else:
|
||||||
exclude_tags = []
|
exclude_tags = []
|
||||||
|
|
||||||
if payload['tag'] in exclude_tags:
|
if payload['tag'] in exclude_tags:
|
||||||
logger.info('Tag %s excluded' % payload['tag'])
|
logger.info('Tag %s excluded' % payload['tag'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
mqtt_host = config.get('rockymsg', 'host')
|
mqtt_host = config.get('rockymsg', 'host')
|
||||||
mqtt_port = config.get('rockymsg', 'port')
|
mqtt_port = config.get('rockymsg', 'port')
|
||||||
mqtt_topic = config.get('rockymsg', 'topic')
|
mqtt_topic = config.get('rockymsg', 'topic')
|
||||||
@ -96,30 +96,30 @@ def _dispatch_on_topic(payload):
|
|||||||
mqtt_tls_key = config.get('rockymsg', 'tls_key')
|
mqtt_tls_key = config.get('rockymsg', 'tls_key')
|
||||||
mqtt_tls_insecure = config.get('rockymsg', 'tls_insecure')
|
mqtt_tls_insecure = config.get('rockymsg', 'tls_insecure')
|
||||||
mqtt_tls_version = config.get('rockymsg', 'tls_version')
|
mqtt_tls_version = config.get('rockymsg', 'tls_version')
|
||||||
|
|
||||||
# Connect to the bus
|
# Connect to the bus
|
||||||
try:
|
try:
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('mqtt client error: %s' % e.message)
|
logger.error('mqtt client error: %s' % e.message)
|
||||||
client.tls_set(ca_certs=mqtt_cacert, certfile=mqtt_tls_cert, keyfile=mqtt_tls_key, tls_version=2)
|
client.tls_set(ca_certs=mqtt_cacert, certfile=mqtt_tls_cert, keyfile=mqtt_tls_key, tls_version=2)
|
||||||
|
|
||||||
client.tls_insecure_set('False')
|
client.tls_insecure_set('False')
|
||||||
try:
|
try:
|
||||||
client.on_publish = mqtt_on_publish
|
client.on_publish = mqtt_on_publish
|
||||||
client.connect(mqtt_host,mqtt_port)
|
client.connect(mqtt_host,mqtt_port)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('mqtt connection error: %s' % e.message)
|
logger.error('mqtt connection error: %s' % e.message)
|
||||||
|
|
||||||
# Publish payload to the bus
|
# Publish payload to the bus
|
||||||
#
|
#
|
||||||
ret = client.publish(mqtt_topic, json.dumps(payload))
|
ret = client.publish(mqtt_topic, json.dumps(payload))
|
||||||
|
|
||||||
# Disconnect from the bus
|
# Disconnect from the bus
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _get_build_target(task_id):
|
def _get_build_target(task_id):
|
||||||
try:
|
try:
|
||||||
task = kojihub.Task(task_id)
|
task = kojihub.Task(task_id)
|
||||||
@ -135,27 +135,27 @@ def _get_build_target(task_id):
|
|||||||
return kojihub.get_build_target(request[2])
|
return kojihub.get_build_target(request[2])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Exception: %s', e)
|
logger.error('Exception: %s', e)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@callback('postTag', 'postUntag')
|
@callback('postTag', 'postUntag')
|
||||||
#@ignore_error
|
#@ignore_error
|
||||||
def rockymsg(cbtype, *args, **kws):
|
def rockymsg(cbtype, *args, **kws):
|
||||||
logger = logging.getLogger(PLUGIN_NAME)
|
logger = logging.getLogger(PLUGIN_NAME)
|
||||||
logger.debug('Called the %s callback, args: %s; kws: %s', cbtype, str(args), str(kws))
|
logger.debug('Called the %s callback, args: %s; kws: %s', cbtype, str(args), str(kws))
|
||||||
|
|
||||||
tag = kws['tag']['name']
|
tag = kws['tag']['name']
|
||||||
build_task_id = kws['build']['task_id']
|
build_task_id = kws['build']['task_id']
|
||||||
|
|
||||||
build_target = _get_build_target(build_task_id)
|
build_target = _get_build_target(build_task_id)
|
||||||
logger.debug('Build target: %s', build_target)
|
logger.debug('Build target: %s', build_target)
|
||||||
|
|
||||||
arches = DEFAULT_ARCHES
|
arches = DEFAULT_ARCHES
|
||||||
if build_target:
|
if build_target:
|
||||||
build_tag = kojihub.get_tag(build_target['build_tag_name'])
|
build_tag = kojihub.get_tag(build_target['build_tag_name'])
|
||||||
arches = build_tag['arches']
|
arches = build_tag['arches']
|
||||||
|
|
||||||
payload = { 'action': cbtype, 'tag': tag, 'arches': arches }
|
payload = { 'action': cbtype, 'tag': tag, 'arches': arches }
|
||||||
job = _dispatch_on_topic(payload)
|
job = _dispatch_on_topic(payload)
|
||||||
if job:
|
if job:
|
||||||
|
@ -48,4 +48,3 @@ Alias /kojifiles "{{ koji_mount }}/"
|
|||||||
GssapiCredStore keytab:/etc/koji.keytab
|
GssapiCredStore keytab:/etc/koji.keytab
|
||||||
Require valid-user
|
Require valid-user
|
||||||
</Location>
|
</Location>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ Alias /koji "/usr/share/koji-web/scripts/wsgi_publisher.py"
|
|||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
RewriteCond %{HTTPS} off
|
RewriteCond %{HTTPS} off
|
||||||
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
|
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
|
||||||
RewriteRule ^/$ /koji [R,L]
|
RewriteRule ^/$ /koji [R,L]
|
||||||
|
|
||||||
Header always set X-Frame-Options "SAMEORIGIN"
|
Header always set X-Frame-Options "SAMEORIGIN"
|
||||||
Header always set X-Xss-Protection "1; mode=block"
|
Header always set X-Xss-Protection "1; mode=block"
|
||||||
@ -69,4 +69,3 @@ Alias /repos {{ koji_mount }}/repos
|
|||||||
Require all granted
|
Require all granted
|
||||||
</IfVersion>
|
</IfVersion>
|
||||||
</Directory>
|
</Directory>
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
---
|
---
|
||||||
# vars file - Nothing should really go here but dynamic imports
|
# vars file - Nothing should really go here but dynamic imports
|
||||||
# and truely static items
|
# and truely static items
|
||||||
|
Loading…
Reference in New Issue
Block a user