Client side integration for ShareWorkspace endpoint

Summary: This diff adds the necessary code changes to integrate the client with the `ShareWorkspace` endpoint on the `CommitCloud` service. The command `hg cloud share` can be used by workspace owners to provide access to their workspaces to other users.

Reviewed By: liubov-dmitrieva

Differential Revision: D39609834

fbshipit-source-id: f8c4781848d2d18023516cf9242ac518e903f88e
This commit is contained in:
Rajiv Sharma 2022-10-05 07:21:48 -07:00 committed by Facebook GitHub Bot
parent a47fef4ec3
commit 210d0f5723
4 changed files with 34 additions and 0 deletions

View File

@ -256,6 +256,10 @@ class BaseService(pycompat.ABC):
def renameworkspace(self, reponame, workspace, new_workspace):
"""Rename the given workspace"""
@abstractmethod
def shareworkspace(self, reponame, workspace):
"""Enable sharing for the given workspace"""
@staticmethod
def _makesmartloginfo(data):
"""Returns a SmartlogInfo that supports DAG operations like heads, parents,

View File

@ -129,6 +129,7 @@ subcmd = cloud.subcommand(
["backup", "check"],
),
("Manage automatic backup or sync", ["disable", "enable"]),
("Enable sharing for a cloud workspace", ["share"]),
]
)
@ -1462,6 +1463,19 @@ def backupdisable(ui, repo, **opts):
return 0
@subcmd("share")
def shareworkspace(ui, repo, **opts):
"""Marks the given workspace for sharing and prints out the corresponding ACL"""
workspacename = workspace.currentworkspace(repo)
if workspacename is None:
ui.write(_("You are not connected to any workspace\n"))
return
sharing_data = service.get(ui, tokenmod.TokenLocator(ui).token).shareworkspace(
ccutil.getreponame(repo), workspacename
)
ui.write(sharing_data["sharing_message"] + "\n")
@subcmd("status")
def cloudstatus(ui, repo, **opts):
"""Shows information about the state of the user's workspace"""

View File

@ -523,6 +523,18 @@ class _HttpsCommitCloudService(baseservice.BaseService):
}
self._timedsend(path, data)
@perftrace.tracefunc("Share Workspace")
def shareworkspace(self, reponame, workspace):
"""Enable sharing for the given workspace"""
self.ui.debug("sending 'share_workspace' request\n", component="commitcloud")
path = "/commit_cloud/share_workspace"
data = {
"repo_name": reponame,
"workspace": workspace,
}
response = self._timedsend(path, data)
return response["sharing_data"]
# Make sure that the HttpsCommitCloudService is a singleton
HttpsCommitCloudService = baseservice.SingletonDecorator(_HttpsCommitCloudService)

View File

@ -326,6 +326,10 @@ class _LocalService(baseservice.BaseService):
else:
raise error.Abort(_("unknown workspace: %s") % workspace)
def shareworkspace(self, reponame, workspace):
"""Enable sharing for the given workspace"""
raise NotImplementedError # Since auth is disabled in tests
# Make sure that the LocalService is a singleton
LocalService = baseservice.SingletonDecorator(_LocalService)