Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from lensesio/fix/exception_handling
Browse files Browse the repository at this point in the history
[lensesio/exceptions] raise exceptions rather exiting
  • Loading branch information
andmarios authored Mar 28, 2024
2 parents 645b44c + 3857504 commit 2b83b31
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
2 changes: 0 additions & 2 deletions _resources/lenses-kerberos/lenses-box.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ services:
]
network_mode: host
ports:
- 3030:3030
volumes:
- ./local/krb5.conf:/etc/krb5.conf
- ./local/krb5.keytab:/etc/krb5.keytab
Expand Down
10 changes: 7 additions & 3 deletions lensesio/core/exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env python3


class lenses_exception(Exception):
def __init__(self, error):
self.error = error
class lenses_exception(BaseException):
def __init__(self, value):
self.value = value

def __str__(self):
return(repr(self.value))

71 changes: 33 additions & 38 deletions lensesio/lenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from lensesio.data.policy import Policy
from lensesio.data.sql import SQLExec
from sys import modules as sys_mods
from sys import exit
import platform


Expand All @@ -44,7 +43,7 @@
class main(
Basic, KafkaTopic, SchemaRegistry, SQLExec,
KafkaQuotas, Policy, DataProcessor, DataConnector,
KafkaACL, LensesFlows, lenses_exception,
KafkaACL, LensesFlows,
DataConsumers, Topology, AdminPanel, SetupPulsar,
):
def __init__(
Expand All @@ -62,32 +61,32 @@ def __init__(

self.active_threads = active_threads

try:
if auth_type not in ['basic', 'service', 'krb5']:
print('''
Parameters:
Mandatory:
auth_type=basic/krb5/service
url=lenses endpoint
Optional:
username (
if auth_type is basic
)
password (
if username was defined
)
service_account (
if auth_type is basic
)
krb_service (
if auth_type is krb5 and platform
is either one of linux, darwin
)
''')
exit(1)
except NameError:
print("Please provide auth_type [basic, krb5, service]")
exit(1)
if auth_type not in ['basic', 'service', 'krb5']:
raise lenses_exception('''
Parameters:
Mandatory:
auth_type=basic/krb5/service
url=lenses endpoint
Optional:
username (
if auth_type is basic
)
password (
if username was defined
)
service_account (
if auth_type is basic
)
krb_service (
if auth_type is krb5 and platform
is either one of linux, darwin
)
''')

if url is None:
raise lenses_exception("URL can not be empty")
elif not url.startswith("http://") and not url.startswith("https://"):
raise lenses_exception("URL Schema is missing. Please provide the schema also: http(s)://example.com")

self.auth_type = auth_type
self.url = url
Expand All @@ -100,22 +99,19 @@ def __init__(
self.serviceConnect()
elif self.auth_type == 'krb5':
if platform.system().lower() not in ['linux', 'linux2', 'darwin']:
msg = "Error: gssapi kerberos integration is not supported for "
print(msg + platform.system())
exit(1)

raise lenses_exception(
"Error: gssapi kerberos integration is not supported for " + platform.system()
)
try:
from lensesio.core.krb_auth import krb5
self.krb5 = krb5
self.krb5.__init__(self, url=url, service=krb_service)
self.krb5.KrbAuth(self)
except NameError:
print("Kerberos client lib is not installed")
return None
raise lenses_exception("Kerberos client lib is not installed")

if self.ConnectionValidation() == 1:
print("Could not login to lenses. Please check the auth options")
exit(1)
raise lenses_exception("Could not login to lenses. Please check the auth options")

AdminPanel.__init__(self, verify_cert=verify_cert)
Topology.__init__(self, verify_cert=verify_cert)
Expand All @@ -133,5 +129,4 @@ def InitPulsarClient(self, host, **kwargs):
try:
self.Pulsar = SetupPulsar.__init__(self, active_threads, host)
except NameError:
print("Pulsar client lib is not installed")
return None
raise lenses_exception("Pulsar client lib is not installed")

0 comments on commit 2b83b31

Please sign in to comment.