Best practice for manipulating workspace on behalf of the user
Hello,
i am working on a use case where one of our services is going to produce a file and deliver it to a certain user workspace.
Ive been looking into existing to apis to accomplish something like that, I can see one way of potentially open a tty and execute a command there, but there are no examples of usage and I am not sure if that’s meant to be used for this kind of purpose. any recommendations?
14 Replies
<#1248953572935335987>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
If I understand correctly, you want to inject a file into a running workspace of another user?
That's correct, so they can use their file into their workspace, eg in pratical terms I give you an on demand change that you can apply in your project...
If you have the owner role. It should be possible with
scp
Yes assume the service is the owner. so it would just be a plain scp connection? Is there any API that given a workspace ID gives me the where to connect etc?
An owner can ssh into any workspace so scp can be used to copy any file into/from workspace
There could be. I will try to look through the API route to see what can be used here.
In a few days
ok
Have you checked the API docs?
Yes, I saw one to upload files only
and get workspace payload didn't seem to have anything relevant
maybe there is
hey, as Atif mentioned there isn't currently any API for this specific action
scp
/sftp
is probably the best way
unless if you maybe could use a centralized file server and configure workspaces to connect to it
you need the Coder CLI to connect to a workspace (bundled with the Agent, so it will be there within your workspace)
you should configure the coder-login module in your template so that the Coder CLI is automatically connected in your workspaces.
then run coder config-ssh
to add entries to your config,
then use the respective scp
/sftp
CLI commands
the name of the SSH connection will be coder.<name>
, so for example you can do ssh coder.myworkspace
if you own the workspace
hmm, except that won't work, config-ssh
doesn't seem to support adding other users' workspacesYes I've been considering other ways rather than ssh, probably will just have a service running inside the container etc.
if you can host that file on a server, you can download it within the
startup_script
If you're still looking for alternatives, depending on the file type, you can use a git repository and add a to the
Thank you I've ended up using a pull strategy originated from a very simple vs code extension, I see the startup_script equally valid as well, thanks for your suggestion.