From 1f04ab050063b5bbbd7a76bbff3904c3fe2f125e Mon Sep 17 00:00:00 2001 From: palubaj Date: Mon, 18 Dec 2023 12:15:25 +0100 Subject: [PATCH 1/4] core: create ADT connection from REST connection --- sap/adt/core.py | 5 +++-- sap/rest/connection.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sap/adt/core.py b/sap/adt/core.py index 8b992bc1..29c1b7c6 100644 --- a/sap/adt/core.py +++ b/sap/adt/core.py @@ -93,7 +93,8 @@ class Connection: """ # pylint: disable=too-many-arguments - def __init__(self, host, client, user, password, port=None, ssl=True, verify=True): + def __init__(self, host, client, user, password=None, port=None, ssl=True, verify=True, + auth=None): """Parameters: - host: string host name - client: string SAP client @@ -124,7 +125,7 @@ def __init__(self, host, client, user, password, port=None, ssl=True, verify=Tru self._base_url = f'{protocol}://{host}:{port}/{self._adt_uri}' self._query_args = f'sap-client={client}&saml2=disabled' self._user = user - self._auth = HTTPBasicAuth(user, password) + self._auth = auth if auth else HTTPBasicAuth(user, password) self._session = None self._collection_types = None self._timeout = config_get('http_timeout') diff --git a/sap/rest/connection.py b/sap/rest/connection.py index 7d96e56d..226d57a4 100644 --- a/sap/rest/connection.py +++ b/sap/rest/connection.py @@ -8,6 +8,7 @@ import requests from requests.auth import HTTPBasicAuth +import sap.adt.core from sap import get_logger, config_get from sap.rest.errors import ( HTTPRequestError, @@ -93,6 +94,7 @@ def __init__(self, icf_path, login_path, host, client, user, password, port=None self._session = None self._login_path = login_path self._timeout = config_get('http_timeout') + self._client = client @property def user(self): @@ -242,3 +244,10 @@ def delete_json(self, uri_path, params=None): response = self.execute('DELETE', uri_path, accept='application/json', params=params) return response.json() + + def get_adt_connection(self): + """Build ADT Connection from this connection. + """ + + return sap.adt.core.Connection(self._host, self._client, self._user, port=self._port, ssl=self._ssl, + verify=self._ssl_verify, auth=self._auth) From db942f3b2c2e737de030f69917547d7fca11e237 Mon Sep 17 00:00:00 2001 From: palubaj Date: Mon, 18 Dec 2023 12:17:09 +0100 Subject: [PATCH 2/4] gcts: list ADT objects of GCTS repo --- sap/rest/gcts/remote_repo.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sap/rest/gcts/remote_repo.py b/sap/rest/gcts/remote_repo.py index b52c0186..0fbc3d17 100644 --- a/sap/rest/gcts/remote_repo.py +++ b/sap/rest/gcts/remote_repo.py @@ -545,3 +545,10 @@ def list_branches(self): raise SAPCliError("gCTS response does not contain 'branches'") return branches + + def list_objects(self): + """List ADT objects of repository""" + + response = self._http.get_json('objects') + + return response['objects'] From faae52861887b5a9744967bb47891cfd48bb4fa3 Mon Sep 17 00:00:00 2001 From: palubaj Date: Mon, 18 Dec 2023 12:20:06 +0100 Subject: [PATCH 3/4] adt: add default object builder types --- sap/adt/object_factory.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sap/adt/object_factory.py b/sap/adt/object_factory.py index 1bdffb56..0e0b0cc5 100644 --- a/sap/adt/object_factory.py +++ b/sap/adt/object_factory.py @@ -20,7 +20,11 @@ def __init__(self, connection: sap.adt.core.Connection, builders: Optional[ADTOb if builders: self._builders = builders else: - self._builders = cast(ADTObjectBuilderDictType, {}) + self._builders = cast(ADTObjectBuilderDictType, { + 'CLAS': sap.adt.Class, + 'FUGR': sap.adt.FunctionGroup, + 'PROG': sap.adt.Program, + }) def register(self, typ: str, producer: ADTObjectBuilderType, overwrite: bool = False) -> None: """Registers ADT object builder""" From 223f7a3da37b982c43eaf2da401ec66b2e6be644 Mon Sep 17 00:00:00 2001 From: palubaj Date: Mon, 18 Dec 2023 12:20:45 +0100 Subject: [PATCH 4/4] gcts: add command to run AUNIT for GCTS repo This is work in progress. I took an inspiration from the jenkins-library project, more precisely from the `gctsExecuteAbapQualityChecks`. See: https://github.com/SAP/jenkins-library/blob/master/cmd/gctsExecuteABAPQualityChecks.go --- sap/cli/gcts.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sap/cli/gcts.py b/sap/cli/gcts.py index 6962f2ff..c8e9082c 100644 --- a/sap/cli/gcts.py +++ b/sap/cli/gcts.py @@ -358,6 +358,40 @@ def install_parser(self, arg_parser): self.branch_grp.install_parser(branch_parser) +@RepoCommandGroup.argument('package') +@RepoCommandGroup.command('run-aunit') +def run_aunit(connection, args): + """Run AUNIT for GCTS repository""" + + adt_connection = connection.get_adt_connection() + repo = get_repository(connection, args.package) + objects = repo.list_objects() + # remove object type DEVC, because it is already included in scope packages + # also if you run ATC Checks for DEVC together with other object types, ATC checks will run only for DEVC + # SUSH is removed because this type is not supported yet + objects = [obj for obj in objects if obj['type'] != 'DEVC' and obj['type'] != 'SUSH'] + objfactory = sap.adt.object_factory.ADTObjectFactory(adt_connection) + + sets = sap.adt.objects.ADTObjectSets() + + for obj in objects: + objname = obj['object'] + objtype = obj['type'] + try: + sets.include(objfactory.make(objtype, objname)) + except SAPCliError as ex: + sap.cli.core.printerr(str(ex)) + return 1 + + aunit = sap.adt.AUnit(adt_connection) + aunit_response = aunit.execute(sets) + if aunit_response.status_code != 200: + print('AUNIT fail:', aunit_response.text) + return 1 + + return 0 + + @RepoCommandGroup.argument('url') @RepoCommandGroup.argument('package') @RepoCommandGroup.command('set-url')