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
Codercord
Codercord4mo ago
<#1248953572935335987>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif4mo ago
If I understand correctly, you want to inject a file into a running workspace of another user?
LoopAj4x
LoopAj4x4mo ago
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...
Atif
Atif4mo ago
If you have the owner role. It should be possible with scp
LoopAj4x
LoopAj4x4mo ago
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?
Atif
Atif4mo ago
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
LoopAj4x
LoopAj4x4mo ago
ok
Atif
Atif4mo ago
Have you checked the API docs?
LoopAj4x
LoopAj4x4mo ago
Yes, I saw one to upload files only and get workspace payload didn't seem to have anything relevant maybe there is
Phorcys
Phorcys3mo ago
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' workspaces
LoopAj4x
LoopAj4x3mo ago
Yes I've been considering other ways rather than ssh, probably will just have a service running inside the container etc.
Atif
Atif3mo ago
if you can host that file on a server, you can download it within the startup_script
TitiMoby
TitiMoby3mo ago
If you're still looking for alternatives, depending on the file type, you can use a git repository and add a
git pull
git pull
to the
startup_script
startup_script
LoopAj4x
LoopAj4x2mo ago
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.
Want results from more Discord servers?
Add your server