diff --git a/.build/pre_build.py b/.build/pre_build.py index d144527de..41a1acee9 100644 --- a/.build/pre_build.py +++ b/.build/pre_build.py @@ -18,6 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from pathlib import Path import os import shutil from backports import configparser @@ -28,16 +29,19 @@ def cd(): def bundle_example_config(subdir): - examples_dir = os.path.join('examples', subdir) - files = [os.path.join(examples_dir, f) for f in os.listdir(examples_dir) if - os.path.isfile(os.path.join(examples_dir, f))] - bundle_dir = os.path.join('user_sync', 'resources', 'examples') - if not os.path.exists(bundle_dir): - os.mkdir(bundle_dir) - for f in files: - dest = os.path.join(bundle_dir, os.path.split(f)[-1]) - shutil.copy(f, dest) + examples_dir = Path('examples', subdir) + bundle_dir = Path('user_sync', 'resources', 'examples', subdir) + if bundle_dir.exists(): + shutil.rmtree(bundle_dir) + os.makedirs(bundle_dir, exist_ok=True) + for f in examples_dir.glob('*'): + shutil.copy(f, bundle_dir) +def bundle_basic_examples(): + examples_dir = Path('examples') / 'config files - basic' + for f in ['user-sync-config.yml', 'connector-ldap.yml', 'connector-umapi.yml']: + filename = examples_dir / f + shutil.copy(filename, Path('user_sync', 'resources', 'examples')) def bundle_feature_flag_config(): default_cfg_path = os.path.join('user_sync', 'resources', 'default_flags.cfg') @@ -63,5 +67,8 @@ def bundle_feature_flag_config(): if __name__ == '__main__': cd() + bundle_basic_examples() bundle_example_config('config files - basic') + bundle_example_config('config files - custom attributes and mappings') bundle_example_config('sign') + bundle_example_config('csv inputs - user and remove lists') diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index b06918455..f6d643887 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -26,18 +26,18 @@ jobs: uses: battila7/get-version-action@v2 - name: Ubuntu-Install dependencies run: | - sudo apt-get update - sudo apt-get install -y software-properties-common - sudo apt-get install -y build-essential - sudo apt-get install -y python3-dev python3-pip python3-virtualenv - sudo apt-get install -y pkg-config libssl-dev libdbus-1-dev libdbus-glib-1-dev python-dbus libffi-dev libkrb5-dev + sudo apt-get update && \ + apt-get install -y software-properties-common && \ + apt-get install -y build-essential && \ + apt-get install -y python3-dev python3-pip python3-virtualenv && \ + apt-get install -y pkg-config libssl-dev libdbus-1-dev libdbus-glib-1-dev python-dbus libffi-dev libkrb5-dev - run: | pip install external/okta-0.0.3.1-py2.py3-none-any.whl pip install -e . pip install -e .[test] pip install -e .[setup] - - name: Make standalone - run: make standalone + - name: Build executable + run: make env: UST_EXTENSION: ${{matrix.extension_support}} - name: Test with pytest @@ -79,7 +79,7 @@ jobs: pip install -e . pip install -e .[test] pip install -e .[setup] - - run: make standalone + - run: make env: UST_EXTENSION: ${{matrix.extension_support}} - name: Test with pytest diff --git a/user-sync.spec b/user-sync.spec index 301e1a943..3273b5ca7 100644 --- a/user-sync.spec +++ b/user-sync.spec @@ -8,7 +8,10 @@ a = Analysis(['user_sync/app.py'], ('user_sync/resources/*.cfg', 'resources'), ('user_sync/resources/manual_url', 'resources'), ('user_sync/resources/README.md', 'resources'), - ('user_sync/resources/examples/*', 'resources/examples'), + ('user_sync/resources/examples/config files - basic/*', 'resources/examples/config files - basic'), + ('user_sync/resources/examples/config files - custom attributes and mappings/*', 'resources/examples/config files - custom attributes and mappings'), + ('user_sync/resources/examples/sign/*', 'resources/examples/sign'), + ('user_sync/resources/examples/csv inputs - user and remove lists/*', 'resources/examples/csv inputs - user and remove lists'), ('user_sync/resources/shell_scripts/win', 'resources/shell_scripts/win'), ('user_sync/resources/shell_scripts/linux', 'resources/shell_scripts/linux'), ], diff --git a/user_sync/app.py b/user_sync/app.py index 02c4af70f..ed621d3f9 100644 --- a/user_sync/app.py +++ b/user_sync/app.py @@ -230,7 +230,7 @@ def init(ctx): sync = 'user-sync-config.yml' umapi = 'connector-umapi.yml' ldap = 'connector-ldap.yml' - ctx.forward(example_config, root=sync, umapi=umapi, ldap=ldap) + ctx.forward(example_config, extras=True, root=sync, umapi=umapi, ldap=ldap) @main.command(short_help="Generate invocation scripts") @@ -255,28 +255,47 @@ def shell_scripts(platform): @main.command() @click.help_option('-h', '--help') +@click.option('--extras', help="Install extra example configs and csv templates?", default=False, is_flag=True) @click.option('--root', help="Filename of root user sync config file", prompt='Main Config Filename', default='user-sync-config.yml') @click.option('--umapi', help="Filename of UMAPI credential config file", prompt='UMAPI Config Filename', default='connector-umapi.yml') @click.option('--ldap', help="Filename of LDAP credential config file", prompt='LDAP Config Filename', default='connector-ldap.yml') -def example_config(**kwargs): +def example_config(extras, **kwargs): """Generate example configuration files""" - res_files = { - 'root': os.path.join('examples', 'user-sync-config.yml'), - 'umapi': os.path.join('examples', 'connector-umapi.yml'), - 'ldap': os.path.join('examples', 'connector-ldap.yml'), + basic_res = { + 'root': Path('examples', 'user-sync-config.yml'), + 'umapi': Path('examples', 'connector-umapi.yml'), + 'ldap': Path('examples', 'connector-ldap.yml'), + } + extra_res = { + 'okta': Path('examples', 'config files - basic', 'connector-okta.yml'), + 'csv': Path('examples', 'config files - basic', 'connector-csv.yml'), + 'console': Path('examples', 'config files - basic', 'connector-adobe-console.yml'), + 'extension': Path('examples', 'config files - custom attributes and mappings', 'extension-config.yml'), + 'remove_list': Path('examples', 'csv inputs - user and remove lists', 'remove-list.csv'), + 'users_file_custom': Path('examples', 'csv inputs - user and remove lists', 'users-file-with-custom-attributes-and-mappings.csv'), + 'users_file': Path('examples', 'csv inputs - user and remove lists', 'users-file.csv') } + files_to_copy = [] + # basic files should go in current working dir for k, fname in kwargs.items(): target = Path.cwd() / fname - assert k in res_files, "Invalid option specified" - res_file = user_sync.resource.get_resource(res_files[k]) - assert res_file is not None, "Resource file '{}' not found".format(res_files[k]) + files_to_copy.append((basic_res[k], target)) + + # extras go in "examples" subdir + for fname in extra_res.values(): + files_to_copy.append((fname, fname)) + + for src, target in files_to_copy: + res_file = user_sync.resource.get_resource(str(src)) + assert res_file is not None, "Resource file '{}' not found".format(src) if target.exists() and not click.confirm('\nWarning - file already exists: \n{}\nOverwrite?'.format(target)): continue - click.echo("Generating file '{}'".format(fname)) + os.makedirs(os.path.dirname(target), exist_ok=True) + click.echo("Generating file '{}'".format(target)) with open(res_file, 'r') as file: content = file.read() with open(target, 'w') as file: @@ -289,12 +308,15 @@ def example_config(**kwargs): prompt='Sign Sync Config Filename', default='connector-sign-sync.yml') def example_config_sign(filename): """Generate Sign Sync Config""" - res_filename = os.path.join('examples', 'connector-sign-sync.yml') + res_filename = Path('examples', 'sign', 'connector-sign-sync.yml') - res_file = user_sync.resource.get_resource(res_filename) + res_file = user_sync.resource.get_resource(str(res_filename)) assert res_file is not None, "Resource file '{}' not found".format(res_filename) click.echo("Generating file '{}'".format(filename)) - shutil.copy(res_file, filename) + with open(res_file, 'r') as file: + content = file.read() + with open(filename, 'w') as file: + file.write(content) @main.command()