navidrome/plugins/host/storage_gen.go
Kendall Garner 54fe6c254e
feat(plugins): implement plugin specific storage (#5839)
* implement storage api/hooks

* fine. if the error messages are different, just match error

* rename storageMount

* add independent plugin test

* round 2

* .-.

* one more copypasta fail

* docs(plugins): document the Storage host service

The README is the plugin author reference and every other host service has a
section there, but Storage had none, so the /storage guest path contract only
existed in code.

Documents the mount point and its backing directory, the manifest permission,
the host function, and the two behaviours an author would otherwise discover
the hard way: there is no size limit, and the directory outlives an uninstall.

* docs(plugins): correct the library filesystem security notes

The README stated in three places that library filesystem access is read-only,
which stopped being true when AllowWriteAccess was added: an administrator can
grant a plugin write access to libraries.

Corrects those and gives the library and storage mounts the same wording for
what the sandbox guarantees, since both now go through the same jail.

* docs(plugins): describe symlink handling in mounts accurately

The security notes claimed paths resolving outside a mount are rejected, which
overstates the jail. Only lexical escapes are: '..' and absolute paths. Creating
symlinks is denied, but symlinks already present are followed and do reach
outside the mount, which is what lets music libraries link folders in from
elsewhere. Both behaviours are pinned by tests in the plugins package.

---------

Co-authored-by: Deluan Quintão <deluan@navidrome.org>
2026-08-03 14:23:42 -04:00

68 lines
1.8 KiB
Go

// Code generated by ndpgen. DO NOT EDIT.
package host
import (
"context"
"encoding/json"
extism "github.com/extism/go-sdk"
)
// StorageGetStoragePathResponse is the response type for Storage.GetStoragePath.
type StorageGetStoragePathResponse struct {
Result string `json:"result,omitempty"`
}
// RegisterStorageHostFunctions registers Storage service host functions.
// The returned host functions should be added to the plugin's configuration.
func RegisterStorageHostFunctions(service StorageService) []extism.HostFunction {
return []extism.HostFunction{
newStorageGetStoragePathHostFunction(service),
}
}
func newStorageGetStoragePathHostFunction(service StorageService) extism.HostFunction {
return extism.NewHostFunctionWithStack(
"storage_getstoragepath",
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
// Call the service method
result := service.GetStoragePath(ctx)
// Write JSON response to plugin memory
resp := StorageGetStoragePathResponse{
Result: result,
}
storageWriteResponse(p, stack, resp)
},
[]extism.ValueType{extism.ValueTypePTR},
[]extism.ValueType{extism.ValueTypePTR},
)
}
// storageWriteResponse writes a JSON response to plugin memory.
func storageWriteResponse(p *extism.CurrentPlugin, stack []uint64, resp any) {
respBytes, err := json.Marshal(resp)
if err != nil {
storageWriteError(p, stack, err)
return
}
respPtr, err := p.WriteBytes(respBytes)
if err != nil {
stack[0] = 0
return
}
stack[0] = respPtr
}
// storageWriteError writes an error response to plugin memory.
func storageWriteError(p *extism.CurrentPlugin, stack []uint64, err error) {
errResp := struct {
Error string `json:"error"`
}{Error: err.Error()}
respBytes, _ := json.Marshal(errResp)
respPtr, _ := p.WriteBytes(respBytes)
stack[0] = respPtr
}