2016-07-20 16:32:01 +02:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2016-07-05 17:26:26 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import pillarsdk
|
|
|
|
from pillarsdk import exceptions as sdk_exceptions
|
|
|
|
from .pillar import pillar_call
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2021-02-16 11:21:06 +01:00
|
|
|
HOME_PROJECT_ENDPOINT = "/bcloud/home-project"
|
2016-07-05 17:26:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def get_home_project(params=None) -> pillarsdk.Project:
|
|
|
|
"""Returns the home project."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("Getting home project")
|
2016-07-05 17:26:26 +02:00
|
|
|
try:
|
2021-02-16 11:21:06 +01:00
|
|
|
return await pillar_call(
|
|
|
|
pillarsdk.Project.find_from_endpoint, HOME_PROJECT_ENDPOINT, params=params
|
|
|
|
)
|
2016-07-05 17:26:26 +02:00
|
|
|
except sdk_exceptions.ForbiddenAccess:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.warning(
|
|
|
|
"Access to the home project was denied. "
|
|
|
|
"Double-check that you are logged in with valid BlenderID credentials."
|
|
|
|
)
|
2016-07-05 17:26:26 +02:00
|
|
|
raise
|
|
|
|
except sdk_exceptions.ResourceNotFound:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.warning("No home project available.")
|
2016-07-05 17:26:26 +02:00
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
async def get_home_project_id() -> str:
|
|
|
|
"""Returns just the ID of the home project."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
home_proj = await get_home_project({"projection": {"_id": 1}})
|
|
|
|
home_proj_id = home_proj["_id"]
|
2016-07-05 17:26:26 +02:00
|
|
|
return home_proj_id
|