Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FX CLI: Separate create, cert gen commands #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions openfl/interface/collaborator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ def start_(plan, collaborator_name, data_config, secure):

plan.get_collaborator(collaborator_name).run()

@collaborator.command(name='create')
@option('-n', '--collaborator_name', required=True,
help='The certified common name of the collaborator')
@option('-d', '--data_path',
help='The data path to be associated with the collaborator')
@option('-s', '--silent', help='Do not prompt', is_flag=True)
def create_(collaborator_name, data_path, silent):
"""Creates a user for an experiment."""
if data_path and is_directory_traversal(data_path):
echo('Data path is out of the openfl workspace scope.')
sys.exit(1)

common_name = f'{collaborator_name}'.lower()
subject_alternative_name = f'DNS:{common_name}'
file_name = f'col_{common_name}'

# TODO: There should be some association with the plan made here as well
register_data_path(common_name, data_path=data_path, silent=silent)

def register_data_path(collaborator_name, data_path=None, silent=False):
"""Register dataset path in the plan/data.yaml file.
Expand Down Expand Up @@ -103,30 +121,24 @@ def register_data_path(collaborator_name, data_path=None, silent=False):
d[collaborator_name] = dir_path

# Write the data.yaml
with open(data_yaml, 'w', encoding='utf-8') as f:
for key, val in d.items():
f.write(f'{key}{separator}{val}\n')

if isfile(data_yaml):
with open(data_yaml, 'w', encoding='utf-8') as f:
for key, val in d.items():
f.write(f'{key}{separator}{val}\n')

@collaborator.command(name='generate-cert-request')
@option('-n', '--collaborator_name', required=True,
help='The certified common name of the collaborator')
@option('-d', '--data_path',
help='The data path to be associated with the collaborator')
@option('-s', '--silent', help='Do not prompt', is_flag=True)
@option('-x', '--skip-package',
help='Do not package the certificate signing request for export',
is_flag=True)
def generate_cert_request_(collaborator_name,
data_path, silent, skip_package):
silent, skip_package):
"""Generate certificate request for the collaborator."""
if data_path and is_directory_traversal(data_path):
echo('Data path is out of the openfl workspace scope.')
sys.exit(1)
generate_cert_request(collaborator_name, data_path, silent, skip_package)

generate_cert_request(collaborator_name, silent, skip_package)

def generate_cert_request(collaborator_name, data_path, silent, skip_package):
def generate_cert_request(collaborator_name, silent, skip_package):
"""
Create collaborator certificate key pair.

Expand Down Expand Up @@ -192,10 +204,6 @@ def generate_cert_request(collaborator_name, data_path, silent, skip_package):
echo('This file should be sent to the certificate authority'
' (typically hosted by the aggregator) for signing')

# TODO: There should be some association with the plan made here as well
register_data_path(common_name, data_path=data_path, silent=silent)


def find_certificate_name(file_name):
"""Parse the collaborator name."""
col_name = str(file_name).split(os.sep)[-1].split('.')[0][4:]
Expand Down