mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Move "org" command to the account module
This commit is contained in:
@ -46,3 +46,7 @@ def validate_password(value):
|
|||||||
" including a number and a lowercase letter"
|
" including a number and a lowercase letter"
|
||||||
)
|
)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def validate_orgname(value):
|
||||||
|
return validate_username(value, "Organization name")
|
||||||
|
13
platformio/account/org/__init__.py
Normal file
13
platformio/account/org/__init__.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
38
platformio/account/org/cli.py
Normal file
38
platformio/account/org/cli.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.org.commands.add import org_add_cmd
|
||||||
|
from platformio.account.org.commands.create import org_create_cmd
|
||||||
|
from platformio.account.org.commands.destroy import org_destroy_cmd
|
||||||
|
from platformio.account.org.commands.list import org_list_cmd
|
||||||
|
from platformio.account.org.commands.remove import org_remove_cmd
|
||||||
|
from platformio.account.org.commands.update import org_update_cmd
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(
|
||||||
|
"account",
|
||||||
|
commands=[
|
||||||
|
org_add_cmd,
|
||||||
|
org_create_cmd,
|
||||||
|
org_destroy_cmd,
|
||||||
|
org_list_cmd,
|
||||||
|
org_remove_cmd,
|
||||||
|
org_update_cmd,
|
||||||
|
],
|
||||||
|
short_help="Manage organizations",
|
||||||
|
)
|
||||||
|
def cli():
|
||||||
|
pass
|
13
platformio/account/org/commands/__init__.py
Normal file
13
platformio/account/org/commands/__init__.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
34
platformio/account/org/commands/add.py
Normal file
34
platformio/account/org/commands/add.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("add", short_help="Add a new owner to organization")
|
||||||
|
@click.argument(
|
||||||
|
"orgname",
|
||||||
|
)
|
||||||
|
@click.argument(
|
||||||
|
"username",
|
||||||
|
)
|
||||||
|
def org_add_cmd(orgname, username):
|
||||||
|
client = AccountClient()
|
||||||
|
client.add_org_owner(orgname, username)
|
||||||
|
return click.secho(
|
||||||
|
"The new owner `%s` has been successfully added to the `%s` organization."
|
||||||
|
% (username, orgname),
|
||||||
|
fg="green",
|
||||||
|
)
|
38
platformio/account/org/commands/create.py
Normal file
38
platformio/account/org/commands/create.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
from platformio.account.helpers import validate_email, validate_orgname
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("create", short_help="Create a new organization")
|
||||||
|
@click.argument(
|
||||||
|
"orgname",
|
||||||
|
callback=lambda _, __, value: validate_orgname(value),
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--email", callback=lambda _, __, value: validate_email(value) if value else value
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--displayname",
|
||||||
|
)
|
||||||
|
def org_create_cmd(orgname, email, displayname):
|
||||||
|
client = AccountClient()
|
||||||
|
client.create_org(orgname, email, displayname)
|
||||||
|
return click.secho(
|
||||||
|
"The organization `%s` has been successfully created." % orgname,
|
||||||
|
fg="green",
|
||||||
|
)
|
34
platformio/account/org/commands/destroy.py
Normal file
34
platformio/account/org/commands/destroy.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("destroy", short_help="Destroy organization")
|
||||||
|
@click.argument("orgname")
|
||||||
|
def org_destroy_cmd(orgname):
|
||||||
|
client = AccountClient()
|
||||||
|
click.confirm(
|
||||||
|
"Are you sure you want to delete the `%s` organization account?\n"
|
||||||
|
"Warning! All linked data will be permanently removed and can not be restored."
|
||||||
|
% orgname,
|
||||||
|
abort=True,
|
||||||
|
)
|
||||||
|
client.destroy_org(orgname)
|
||||||
|
return click.secho(
|
||||||
|
"Organization `%s` has been destroyed." % orgname,
|
||||||
|
fg="green",
|
||||||
|
)
|
48
platformio/account/org/commands/list.py
Normal file
48
platformio/account/org/commands/list.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
import click
|
||||||
|
from tabulate import tabulate
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("list", short_help="List organizations and their members")
|
||||||
|
@click.option("--json-output", is_flag=True)
|
||||||
|
def org_list_cmd(json_output):
|
||||||
|
client = AccountClient()
|
||||||
|
orgs = client.list_orgs()
|
||||||
|
if json_output:
|
||||||
|
return click.echo(json.dumps(orgs))
|
||||||
|
if not orgs:
|
||||||
|
return click.echo("You do not have any organization")
|
||||||
|
for org in orgs:
|
||||||
|
click.echo()
|
||||||
|
click.secho(org.get("orgname"), fg="cyan")
|
||||||
|
click.echo("-" * len(org.get("orgname")))
|
||||||
|
data = []
|
||||||
|
if org.get("displayname"):
|
||||||
|
data.append(("Display Name:", org.get("displayname")))
|
||||||
|
if org.get("email"):
|
||||||
|
data.append(("Email:", org.get("email")))
|
||||||
|
data.append(
|
||||||
|
(
|
||||||
|
"Owners:",
|
||||||
|
", ".join((owner.get("username") for owner in org.get("owners"))),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
click.echo(tabulate(data, tablefmt="plain"))
|
||||||
|
return click.echo()
|
34
platformio/account/org/commands/remove.py
Normal file
34
platformio/account/org/commands/remove.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("remove", short_help="Remove an owner from organization")
|
||||||
|
@click.argument(
|
||||||
|
"orgname",
|
||||||
|
)
|
||||||
|
@click.argument(
|
||||||
|
"username",
|
||||||
|
)
|
||||||
|
def org_remove_cmd(orgname, username):
|
||||||
|
client = AccountClient()
|
||||||
|
client.remove_org_owner(orgname, username)
|
||||||
|
return click.secho(
|
||||||
|
"The `%s` owner has been successfully removed from the `%s` organization."
|
||||||
|
% (username, orgname),
|
||||||
|
fg="green",
|
||||||
|
)
|
52
platformio/account/org/commands/update.py
Normal file
52
platformio/account/org/commands/update.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.account.client import AccountClient
|
||||||
|
from platformio.account.helpers import validate_email, validate_orgname
|
||||||
|
|
||||||
|
|
||||||
|
@click.command("update", short_help="Update organization")
|
||||||
|
@click.argument("cur_orgname")
|
||||||
|
@click.option(
|
||||||
|
"--orgname",
|
||||||
|
callback=lambda _, __, value: validate_orgname(value),
|
||||||
|
help="A new orgname",
|
||||||
|
)
|
||||||
|
@click.option("--email")
|
||||||
|
@click.option("--displayname")
|
||||||
|
def org_update_cmd(cur_orgname, **kwargs):
|
||||||
|
client = AccountClient()
|
||||||
|
org = client.get_org(cur_orgname)
|
||||||
|
del org["owners"]
|
||||||
|
new_org = org.copy()
|
||||||
|
if not any(kwargs.values()):
|
||||||
|
for field in org:
|
||||||
|
new_org[field] = click.prompt(
|
||||||
|
field.replace("_", " ").capitalize(), default=org[field]
|
||||||
|
)
|
||||||
|
if field == "email":
|
||||||
|
validate_email(new_org[field])
|
||||||
|
if field == "orgname":
|
||||||
|
validate_orgname(new_org[field])
|
||||||
|
else:
|
||||||
|
new_org.update(
|
||||||
|
{key.replace("new_", ""): value for key, value in kwargs.items() if value}
|
||||||
|
)
|
||||||
|
client.update_org(cur_orgname, new_org)
|
||||||
|
return click.secho(
|
||||||
|
"The organization `%s` has been successfully updated." % cur_orgname,
|
||||||
|
fg="green",
|
||||||
|
)
|
@ -1,165 +0,0 @@
|
|||||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
import click
|
|
||||||
from tabulate import tabulate
|
|
||||||
|
|
||||||
from platformio.account.client import AccountClient
|
|
||||||
from platformio.account.helpers import validate_email, validate_username
|
|
||||||
|
|
||||||
|
|
||||||
@click.group("org", short_help="Manage organizations")
|
|
||||||
def cli():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def validate_orgname(value):
|
|
||||||
return validate_username(value, "Organization name")
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("create", short_help="Create a new organization")
|
|
||||||
@click.argument(
|
|
||||||
"orgname",
|
|
||||||
callback=lambda _, __, value: validate_orgname(value),
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--email", callback=lambda _, __, value: validate_email(value) if value else value
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--displayname",
|
|
||||||
)
|
|
||||||
def org_create(orgname, email, displayname):
|
|
||||||
client = AccountClient()
|
|
||||||
client.create_org(orgname, email, displayname)
|
|
||||||
return click.secho(
|
|
||||||
"The organization `%s` has been successfully created." % orgname,
|
|
||||||
fg="green",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("list", short_help="List organizations and their members")
|
|
||||||
@click.option("--json-output", is_flag=True)
|
|
||||||
def org_list(json_output):
|
|
||||||
client = AccountClient()
|
|
||||||
orgs = client.list_orgs()
|
|
||||||
if json_output:
|
|
||||||
return click.echo(json.dumps(orgs))
|
|
||||||
if not orgs:
|
|
||||||
return click.echo("You do not have any organization")
|
|
||||||
for org in orgs:
|
|
||||||
click.echo()
|
|
||||||
click.secho(org.get("orgname"), fg="cyan")
|
|
||||||
click.echo("-" * len(org.get("orgname")))
|
|
||||||
data = []
|
|
||||||
if org.get("displayname"):
|
|
||||||
data.append(("Display Name:", org.get("displayname")))
|
|
||||||
if org.get("email"):
|
|
||||||
data.append(("Email:", org.get("email")))
|
|
||||||
data.append(
|
|
||||||
(
|
|
||||||
"Owners:",
|
|
||||||
", ".join((owner.get("username") for owner in org.get("owners"))),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
click.echo(tabulate(data, tablefmt="plain"))
|
|
||||||
return click.echo()
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("update", short_help="Update organization")
|
|
||||||
@click.argument("cur_orgname")
|
|
||||||
@click.option(
|
|
||||||
"--orgname",
|
|
||||||
callback=lambda _, __, value: validate_orgname(value),
|
|
||||||
help="A new orgname",
|
|
||||||
)
|
|
||||||
@click.option("--email")
|
|
||||||
@click.option("--displayname")
|
|
||||||
def org_update(cur_orgname, **kwargs):
|
|
||||||
client = AccountClient()
|
|
||||||
org = client.get_org(cur_orgname)
|
|
||||||
del org["owners"]
|
|
||||||
new_org = org.copy()
|
|
||||||
if not any(kwargs.values()):
|
|
||||||
for field in org:
|
|
||||||
new_org[field] = click.prompt(
|
|
||||||
field.replace("_", " ").capitalize(), default=org[field]
|
|
||||||
)
|
|
||||||
if field == "email":
|
|
||||||
validate_email(new_org[field])
|
|
||||||
if field == "orgname":
|
|
||||||
validate_orgname(new_org[field])
|
|
||||||
else:
|
|
||||||
new_org.update(
|
|
||||||
{key.replace("new_", ""): value for key, value in kwargs.items() if value}
|
|
||||||
)
|
|
||||||
client.update_org(cur_orgname, new_org)
|
|
||||||
return click.secho(
|
|
||||||
"The organization `%s` has been successfully updated." % cur_orgname,
|
|
||||||
fg="green",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("destroy", short_help="Destroy organization")
|
|
||||||
@click.argument("orgname")
|
|
||||||
def account_destroy(orgname):
|
|
||||||
client = AccountClient()
|
|
||||||
click.confirm(
|
|
||||||
"Are you sure you want to delete the `%s` organization account?\n"
|
|
||||||
"Warning! All linked data will be permanently removed and can not be restored."
|
|
||||||
% orgname,
|
|
||||||
abort=True,
|
|
||||||
)
|
|
||||||
client.destroy_org(orgname)
|
|
||||||
return click.secho(
|
|
||||||
"Organization `%s` has been destroyed." % orgname,
|
|
||||||
fg="green",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("add", short_help="Add a new owner to organization")
|
|
||||||
@click.argument(
|
|
||||||
"orgname",
|
|
||||||
)
|
|
||||||
@click.argument(
|
|
||||||
"username",
|
|
||||||
)
|
|
||||||
def org_add_owner(orgname, username):
|
|
||||||
client = AccountClient()
|
|
||||||
client.add_org_owner(orgname, username)
|
|
||||||
return click.secho(
|
|
||||||
"The new owner `%s` has been successfully added to the `%s` organization."
|
|
||||||
% (username, orgname),
|
|
||||||
fg="green",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("remove", short_help="Remove an owner from organization")
|
|
||||||
@click.argument(
|
|
||||||
"orgname",
|
|
||||||
)
|
|
||||||
@click.argument(
|
|
||||||
"username",
|
|
||||||
)
|
|
||||||
def org_remove_owner(orgname, username):
|
|
||||||
client = AccountClient()
|
|
||||||
client.remove_org_owner(orgname, username)
|
|
||||||
return click.secho(
|
|
||||||
"The `%s` owner has been successfully removed from the `%s` organization."
|
|
||||||
% (username, orgname),
|
|
||||||
fg="green",
|
|
||||||
)
|
|
@ -22,7 +22,7 @@ import pytest
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio.account.cli import cli as cmd_account
|
from platformio.account.cli import cli as cmd_account
|
||||||
from platformio.commands.org import cli as cmd_org
|
from platformio.account.org.cli import cli as cmd_org
|
||||||
from platformio.commands.team import cli as cmd_team
|
from platformio.commands.team import cli as cmd_team
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(
|
pytestmark = pytest.mark.skipif(
|
||||||
|
Reference in New Issue
Block a user