Skip to content

Commit

Permalink
HTTP/TLS Support (closes #1 and #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmeggle committed Oct 24, 2022
1 parent 3c0e78d commit 2d7c0af
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 22 deletions.
9 changes: 3 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed
- HTTPS/TLS support (#4)


### Fixed

- Default params für Discovery ergänzt (#3)
### Removed

### Deprecated


- Custom HTTP port übergabe gefixt (#1)

### Changed

Expand Down
42 changes: 27 additions & 15 deletions agents/special/agent_gematik_tikonn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import re
import os
import sys
from zeep import helpers, Client, Settings
from requests import Session
from zeep.transports import Transport

import zeep
import datetime
import hashlib
Expand Down Expand Up @@ -48,6 +51,7 @@ class AgentGematikKonnektor:
parser.add_argument(
"-p", "--port", dest="port", default=80, required=False, help="TCP Port"
)
parser.add_argument("--verifyssl", default=False, action="store_true")
parser.add_argument(
"-m",
"--mandant",
Expand All @@ -73,6 +77,10 @@ class AgentGematikKonnektor:
return parser.parse_args(argv)

def main(self, args: Args):
if not args.verifyssl:
os.environ.pop("REQUESTS_CA_BUNDLE", None)
os.environ.pop("CURL_CA_BUNDLE", None)

kontexts = [
Kontext(args.mandant_id, args.client_id, workplace_id)
for workplace_id in args.workplace_ids.split(",")
Expand All @@ -81,11 +89,11 @@ class AgentGematikKonnektor:
# Todo Section manager

strategy = EventServiceGetResourceInformation()
session = Session(konnektor, strategy, kontexts)
session = KonnektorSession(konnektor, strategy, kontexts, args.port)
session.produce_output()

strategy = EventServiceGetCardTerminals()
session = Session(konnektor, strategy, kontexts)
session = KonnektorSession(konnektor, strategy, kontexts, args.port)
session.produce_output()


Expand Down Expand Up @@ -127,16 +135,12 @@ class Konnektor(object):
else:
self.sds_path = sds_path

# self.last_request = ""
# self.last_response = ""
# self.last_statuscode = 0
# self.last_message = ""
# self.last_reply_headers = ""
# self.last_reply_body = ""

@property
def url(self):
return "http://" + self.ip_address + ":" + str(self.port)
if self.port == "443":
return "https://" + self.ip_address + ":" + str(self.port)
else:
return "http://" + self.ip_address + ":" + str(self.port)


def zeep2dict(f_wrapped):
Expand Down Expand Up @@ -489,14 +493,15 @@ class PiggybackGroup:


# Context
class Session:
def __init__(self, konnektor: Konnektor, service: EventService, kontexts):
class KonnektorSession:
def __init__(self, konnektor: Konnektor, service: EventService, kontexts, port):
self.service = service
self.konnektor = konnektor
if not type(kontexts) == list:
self.kontexts = [kontexts]
else:
self.kontexts = kontexts
self.port = port
self.zeep_settings = Settings(forbid_entities=False)
self._client = None

Expand All @@ -523,9 +528,16 @@ class Session:
@property
def client(self):
if self._client is None:
# TODO: How can WSDL be loaded from variable?
# HEREIWAS
self._client = Client(str(self.service.wsdl), settings=self.zeep_settings)
# SSL support
transport = None
if self.port == "443":
sess = Session()
sess.verify = False
transport = Transport(session=sess)

self._client = Client(
str(self.service.wsdl), transport=transport, settings=self.zeep_settings
)
return self._client

@property
Expand Down
7 changes: 7 additions & 0 deletions checks/agent_gematik_tikonn
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def agent_gematik_tikonn_arguments(params, hostname, ipaddress):
wsdl_v_eventservice = params["wsdl_versions"][0]
wsdl_v_signatureservice = params["wsdl_versions"][1]
workplace_ids = ",".join(params["workplace_ids"])

args = [
"--hostname",
ipaddress,
"--port",
str(params["port"]),
"--mandant",
params["mandant_id"],
"--client",
Expand All @@ -23,6 +26,10 @@ def agent_gematik_tikonn_arguments(params, hostname, ipaddress):
"--wsdlversion",
"SignatureService:{}".format(wsdl_v_signatureservice),
]

if params["verify_ssl"]:
args.append("--verifyssl")

return args


Expand Down
34 changes: 33 additions & 1 deletion web/plugins/wato/datasource_gematik_tikonn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
DropdownChoice,
Tuple,
ListOfStrings,
FixedValue,
Transform,
Alternative,
)

from cmk.gui.log import logger

# FIXME: Dokumentation versch. Rulespecs!
from cmk.gui.plugins.wato.datasource_programs import (
RulespecGroupDatasourceProgramsHardware,
Expand All @@ -27,6 +32,18 @@
# return TextAscii(title=_("Sector name"))


def forth(data):
if not "verify_ssl" in data:
# logger.critical("BEFORE: " + str(data))
data["verify_ssl"] = True
# logger.critical("AFTER: " + str(data))
return data


def _transform_valuespec_special_agents_gematik_tikonn():
return Transform(_valuespec_special_agents_gematik_tikonn(), forth=forth)


def _valuespec_special_agents_gematik_tikonn():
return Dictionary(
title=_("Gematik TI-Konnektor"),
Expand All @@ -44,6 +61,21 @@ def _valuespec_special_agents_gematik_tikonn():
default_value=80,
),
),
(
"verify_ssl",
# Transform(
Alternative(
title=_("Gültigkeit des SSL-Zertifikats"),
default_value=True,
elements=[
FixedValue(True, title=_("überprüfen"), totext=""),
FixedValue(False, title=_("nicht überprüfen"), totext=""),
],
),
# forth=lambda v: v if isinstance(v, dict) else {""}),
# forth=forth,
# ),
),
(
"wsdl_versions",
Tuple(
Expand Down Expand Up @@ -121,7 +153,7 @@ def _valuespec_special_agents_gematik_tikonn():
HostRulespec(
group=RulespecGroupDatasourceProgramsHardware,
name="special_agents:gematik_tikonn",
valuespec=_valuespec_special_agents_gematik_tikonn,
valuespec=_transform_valuespec_special_agents_gematik_tikonn,
)
)
)

0 comments on commit 2d7c0af

Please sign in to comment.