Skip to content

Commit

Permalink
fix(jans-cli): jans cli pkg fixes (#854)
Browse files Browse the repository at this point in the history
* fix: jans-cli pkg fixes

* fix: jans-linux-setup copy log4j2.xml to config-api custom dir

* fix: linux-setup update swagger client

* fix: jans-linux-setup remove unused code block

* fix: jans-linux-setup remove unused function

* fix: jans-cli redirect ancoding errors to /dev/null (ref: #857)

* fix: jans-cli code smell

* fix: jans-linux-setup scim-cli uses role based client for jwt token

* fix: jans-linux-setup mode of setup.properties
  • Loading branch information
devrimyatar authored Feb 19, 2022
1 parent ce5b2e6 commit 9e96e4c
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 39 deletions.
7 changes: 5 additions & 2 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
sys.path.append(cur_dir)

from pylib.tabulate.tabulate import tabulate
from pylib import jwt
try:
import jwt
except ModuleNotFoundError:
from pylib import jwt

tabulate_endpoints = {
'jca.get-config-scripts': ['scriptType', 'name', 'enabled', 'inum'],
Expand Down Expand Up @@ -66,7 +69,7 @@ def encode_decode(s, decode=False):
cmd = '/opt/jans/bin/encode.py '
if decode:
cmd += '-D '
result = os.popen(cmd + s).read()
result = os.popen(cmd + s + ' 2>/dev/null').read()
return result.strip()


Expand Down
165 changes: 161 additions & 4 deletions jans-cli/cli/jca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ tags:
- name: OAuth - Scopes
- name: Statistics - User
- name: Health - Check
- name: Server Stats
- name: SCIM - User Management
- name: SCIM - Config Management
- name: Organization Configuration
- name: Auth Server Health - Check
- name: Admin UI - Role
- name: Admin UI - Permission
Expand Down Expand Up @@ -2377,6 +2379,23 @@ paths:
$ref: '#/components/schemas/HealthStatusItem'
'500':
description: Internal Server Error

/jans-config-api/api/v1/health/server-stat:
get:
summary: Returns application server status.
description: Returns application server status.
operationId: get-server-stat
tags:
- Server Stats
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/StatsData'
'500':
description: Internal Server Error

/jans-config-api/scim/user:
get:
Expand Down Expand Up @@ -2806,7 +2825,7 @@ paths:
$ref: '#/components/schemas/ErrorResponse'
security:
- oauth2: [https://jans.io/oauth/config/scim/users.read https://jans.io/scim/users.read]

/jans-config-api/scim/config:
get:
summary: Retrieves SCIM App configuration.
Expand Down Expand Up @@ -2859,7 +2878,60 @@ paths:
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'

/jans-config-api/api/v1/org:
get:
summary: Retrieves organization configuration.
description: Retrieves organization configuration.
operationId: get-organization-config
security:
- oauth2: [https://jans.io/oauth/config/organization.readonly]
tags:
- Organization Configuration
responses:
'200':
description: OK
content:
application/json:
schema:
title: Organization
description: Organization configuration.
$ref: '#/components/schemas/Organization'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
patch:
summary: Partially modifies organization configuration.
description: Partially modifies organization configuration.
operationId: patch-organization-config
security:
- oauth2: [https://jans.io/oauth/config/organization.write]
tags:
- Organization Configuration
requestBody:
content:
application/json-patch+json:
schema:
type: array
items:
$ref: '#/components/schemas/PatchRequest'
description: String representing patch-document.
example: '[{"op": "add", "path": "/jsFaviconPath", "value": "/opt/jans/jetty/jans-auth/custom/static/"}]'
responses:
'200':
description: OK
content:
application/json:
schema:
title: Organization
description: Organization configuration.
$ref: '#/components/schemas/Organization'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'

/jans-config-api/api/v1/jans-auth-server/health:
get:
summary: Returns auth server health status.
Expand Down Expand Up @@ -3336,6 +3408,8 @@ components:
https://jans.io/oauth/config/scim/users.write: Manage scim user related information
https://jans.io/scim/config.readonly: Vew SCIM App configuration
https://jans.io/scim/config.write: Manage SCIM App configuration
https://jans.io/oauth/config/organization.readonly: View organization configuration information
https://jans.io/oauth/config/organization.write: Manage organization configuration information

responses:
Found:
Expand Down Expand Up @@ -6542,5 +6616,88 @@ components:
useLocalCache:
type: boolean
description: Boolean value specifying whether to enable local in-memory cache.

Organization:
type: object
properties:
displayName:
type: string
description: Organization name
description:
type: string
description: Organization description
member:
type: string
description: String describing memberOf
countryName:
type: string
description: Organization country name
organization:
type: string
status:
type: string
managerGroup:
type: string
description: qualified id of the group
example: inum=60B7,ou=groups,o=jans
themeColor:
type: string
description: color of the theme
example: 166309
shortName:
type: string
customMessages:
type: array
items:
type: string
title:
type: string
jsLogoPath:
type: string
description: Path to organization logo image
jsFaviconPath:
type: string
description: Path to organization favicon image


FacterData:
type: object
properties:
memoryfree:
type: string
description: Server free memory
swapfree:
type: string
description: Server swap free
hostname:
type: string
description: Server hostname
ipaddress:
type: string
description: Server ipaddress
uptime:
type: string
description: Server uptime
free_disk_space:
type: string
description: Server free disk space
load_average:
type: string
description: Server average load time


StatsData:
type: object
properties:
dbType:
type: string
description: Jans Server DB type
lastUpdate:
type: string
description: Stats update time
facterData:
type: object
$ref: '#/components/schemas/FacterData'
description: Underlying Server stats


6 changes: 5 additions & 1 deletion jans-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def find_version(*file_paths):
package_data={'': ['*.yaml']},
zip_safe=False,
install_requires=[
"ruamel.yaml>=0.16.5"
"ruamel.yaml>=0.16.5",
"PyJWT==2.3.0",
"jca-swagger-client @ https://ox.gluu.org/icrby8xcvbcv/cli-swagger/jca_swagger_client.zip",
"scim_swagger_client @ https://ox.gluu.org/icrby8xcvbcv/cli-swagger/scim_swagger_client.zip",

],
classifiers=[
"Intended Audience :: Developers",
Expand Down
1 change: 0 additions & 1 deletion jans-linux-setup/install.py

This file was deleted.

10 changes: 2 additions & 8 deletions jans-linux-setup/jans_setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def download_files():
download(urljoin(maven_base_url, 'jans-config-api-server/{0}{1}/jans-config-api-server-{0}{1}.war'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), os.path.join(jans_app_dir, 'jans-config-api.war'))
download('https://github.com/sqlalchemy/sqlalchemy/archive/rel_1_3_23.zip', sqlalchemy_zip_file)
download(urljoin(maven_base_url, 'scim-plugin/{0}{1}/scim-plugin-{0}{1}-distribution.jar'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), os.path.join(jans_app_dir, 'scim-plugin.jar'))
download('https://ox.gluu.org/icrby8xcvbcv/cli-swagger/jca.tgz', os.path.join(jans_app_dir, 'jca-swagger-client.tgz'))
download('https://ox.gluu.org/icrby8xcvbcv/cli-swagger/scim.tgz', os.path.join(jans_app_dir, 'scim-swagger-client.tgz'))
download('https://ox.gluu.org/icrby8xcvbcv/cli-swagger/jca_swagger_client.zip', os.path.join(jans_app_dir, 'jca-swagger-client.zip'))
download('https://ox.gluu.org/icrby8xcvbcv/cli-swagger/scim_swagger_client.zip', os.path.join(jans_app_dir, 'scim-swagger-client.zip'))
download('https://raw.githubusercontent.com/GluuFederation/gluu-snap/master/facter/facter', os.path.join(jans_app_dir, 'facter'))
download('https://github.com/jpadilla/pyjwt/archive/refs/tags/2.3.0.zip', os.path.join(app_dir, 'pyjwt.zip'))

Expand Down Expand Up @@ -311,11 +311,6 @@ def extract_yaml_files():
extract_file(jans_zip_file, 'jans-config-api/server/src/main/resources/log4j2.xml', jans_app_dir)


def prepare_jans_cli_package():
print("Preparing jans-cli package")
extract_subdir(jans_zip_file, 'jans-cli', 'jans-cli', os.path.join(jans_app_dir, 'jans-cli.zip'))


def uninstall_jans():
check_installation()
print('\033[31m')
Expand Down Expand Up @@ -408,7 +403,6 @@ def main():
else:
profile_setup()

prepare_jans_cli_package()

if not argsp.no_setup:
print("Launching Janssen Setup")
Expand Down
2 changes: 1 addition & 1 deletion jans-linux-setup/jans_setup/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def progress(self, service_name, msg, incr=False):
self.ldapCertFn = self.opendj_cert_fn = os.path.join(self.certFolder, 'opendj.crt')
self.ldapTrustStoreFn = self.opendj_p12_fn = os.path.join(self.certFolder, 'opendj.p12')

self.oxd_package = base.determine_package(os.path.join(Config.distJansFolder, 'oxd-server*.tgz'))
self.oxd_package = base.determine_package(os.path.join(self.distJansFolder, 'oxd-server*.tgz'))

self.opendj_p12_pass = None

Expand Down
23 changes: 17 additions & 6 deletions jans-linux-setup/jans_setup/setup_app/installers/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def install(self):
self.copyFile(self.source_files[1][0], self.libDir)
scim_plugin_path = os.path.join(self.libDir, os.path.basename(self.source_files[1][0]))
self.add_extra_class(scim_plugin_path)
base.extract_file(
os.path.join(Config.distJansFolder, 'jans.zip'),
'jans-config-api/server/src/main/resources/log4j2.xml',
self.custom_config_dir
)

self.enable()

def installed(self):
Expand Down Expand Up @@ -192,15 +198,11 @@ def render_import_templates(self):
self.dbUtils.import_ldif(self.load_ldif_files)


def load_test_data(self):
if not self.installed():
return

check_result = self.check_clients([('jca_test_client_id', '1802.')])
def prepare_scope_list(self):

result = self.dbUtils.search('ou=scopes,o=jans', search_filter='(&(inum=1800.*)(objectClass=jansScope))', fetchmany=True)
scopes = []
scopes_id_list = []
result = self.dbUtils.search('ou=scopes,o=jans', search_filter='(&(inum=1800.*)(objectClass=jansScope))', fetchmany=True)

for scope in result:
if isinstance(scope, dict):
Expand All @@ -220,6 +222,15 @@ def load_test_data(self):
Config.templateRenderingDict['config_api_scopes'] = '\n'.join(scopes)
Config.templateRenderingDict['config_api_scopes_list'] = ' '.join(scopes_id_list)


def load_test_data(self):
if not self.installed():
return

check_result = self.check_clients([('jca_test_client_id', '1802.')])

self.prepare_scope_list()

if check_result.get('1802.') == 1:
warning = "Test data for Config Api was allready loaded."
self.logIt(warning)
Expand Down
20 changes: 8 additions & 12 deletions jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def __init__(self):
self.register_progess()

self.source_files = [
(os.path.join(Config.distJansFolder, 'jans-cli.zip'), 'https://api.github.com/repos/JanssenProject/jans-cli/tarball/main'.format(Config.oxVersion)),
(os.path.join(Config.distJansFolder, 'jca-swagger-client.tgz'), 'https://ox.gluu.org/icrby8xcvbcv/cli-swagger/jca.tgz'),
(os.path.join(Config.distJansFolder, 'scim-swagger-client.tgz'), 'https://ox.gluu.org/icrby8xcvbcv/cli-swagger/scim.tgz'),
(os.path.join(Config.distJansFolder, 'jans.zip'), 'https://github.com/JanssenProject/jans/archive/refs/heads/{}.zip'.format(Config.githubBranchName)),
(os.path.join(Config.distJansFolder, 'jca-swagger-client.zip'), 'https://ox.gluu.org/icrby8xcvbcv/cli-swagger/jca_swagger_client.zip'),
(os.path.join(Config.distJansFolder, 'scim-swagger-client.zip'), 'https://ox.gluu.org/icrby8xcvbcv/cli-swagger/scim_swagger_client.zip'),
(os.path.join(Config.distAppFolder, 'pyjwt.zip'), 'https://github.com/jpadilla/pyjwt/archive/refs/tags/2.3.0.zip'),
]

Expand All @@ -48,18 +48,14 @@ def install(self):
self.logIt("Installing Jans Cli", pbar=self.service_name)

#extract jans-cli tgz archieve
base.extract_from_zip(self.source_files[0][0], 'cli', self.jans_cli_install_dir)
base.extract_from_zip(self.source_files[0][0], 'jans-cli/cli', self.jans_cli_install_dir)

self.run([paths.cmd_ln, '-s', os.path.join(self.jans_cli_install_dir, 'config_cli.py'), os.path.join(self.jans_cli_install_dir, 'config-cli.py')])
self.run([paths.cmd_ln, '-s', os.path.join(self.jans_cli_install_dir, 'config_cli.py'), os.path.join(self.jans_cli_install_dir, 'scim-cli.py')])
self.run([paths.cmd_chmod, '+x', os.path.join(self.jans_cli_install_dir, 'config_cli.py')])

for i, app_mod in enumerate(('jca', 'scim')):
swagger_cli_dir = os.path.join(self.jans_cli_install_dir, app_mod)
self.createDirs(swagger_cli_dir)
init_fn = os.path.join(swagger_cli_dir, '__init__.py')
self.writeFile(init_fn, '')
shutil.unpack_archive(self.source_files[i+1][0], swagger_cli_dir)
base.extract_from_zip(self.source_files[1][0], 'jca', os.path.join(self.jans_cli_install_dir, 'jca'))
base.extract_from_zip(self.source_files[2][0], 'scim', os.path.join(self.jans_cli_install_dir, 'scim'))

#extract pyjwt from archieve
base.extract_from_zip(self.source_files[3][0], 'jwt', os.path.join(self.jans_cli_install_dir, 'pylib/jwt'))
Expand Down Expand Up @@ -90,8 +86,8 @@ def configure(self, options={}):
config['DEFAULT']['jca_client_secret_enc'] = Config.role_based_client_encoded_pw

if Config.get('installScimServer'):
config['DEFAULT']['scim_client_id'] = Config.scim_client_id
config['DEFAULT']['scim_client_secret_enc'] = Config.scim_client_encoded_pw
config['DEFAULT']['scim_client_id'] = Config.role_based_client_id
config['DEFAULT']['scim_client_secret_enc'] = Config.role_based_client_encoded_pw

config.write(self.config_ini_fn.open('w'))

Expand Down
16 changes: 16 additions & 0 deletions jans-linux-setup/jans_setup/setup_app/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ def download(url, dst):
else:
break

def extract_file(zip_file, source, target, ren=False):
zip_obj = zipfile.ZipFile(zip_file, "r")
for member in zip_obj.infolist():
if not member.is_dir() and member.filename.endswith(source):
if ren:
target_p = Path(target)
else:
p = Path(member.filename)
target_p = Path(target).joinpath(p.name)
if not target_p.parent.exists():
target_p.parent.mkdir(parents=True)
target_p.write_bytes(zip_obj.read(member))
break
zip_obj.close()


def extract_from_zip(zip_file, sub_dir, target_dir, remove_target_dir=False):
zipobj = zipfile.ZipFile(zip_file, "r")
parent_dir = zipobj.namelist()[0]
Expand Down
Loading

0 comments on commit 9e96e4c

Please sign in to comment.