Documentation
¶
Overview ¶
Package assetsmanage implements the write side of asset management: creating, updating, showing and deleting JumpServer assets.
The read side lives in the assets package. This one is kept separate because the write paths have different concerns: they need node and account ids, they mutate an external system, and their request bodies are version-sensitive.
Endpoint facts (verified against the running JumpServer on 2026-11-04):
- POST /api/v1/assets/hosts/ creates a host asset
- PUT /api/v1/assets/hosts/<id>/ updates it
- DELETE /api/v1/assets/hosts/<id>/ deletes it
- GET /api/v1/assets/hosts/ lists every host asset (admin view)
The plural "/assets/" view answers GET and POST with "Action not allowed: POST, only “ supported" — the hosts view is the one that implements creation.
Dependency direction: assetsmanage depends on api.
Index ¶
- Constants
- Variables
- func DefaultNodeID(ctx context.Context, c *api.Client) (string, error)
- func DefaultProtocols() []protocolRow
- func Delete(ctx context.Context, c *api.Client, id string) error
- type Account
- type AccountSpec
- type Asset
- func Create(ctx context.Context, c *api.Client, spec Spec) (Asset, error)
- func FindByName(ctx context.Context, c *api.Client, name string) (Asset, error)
- func Get(ctx context.Context, c *api.Client, id string) (Asset, error)
- func List(ctx context.Context, c *api.Client) ([]Asset, error)
- func Update(ctx context.Context, c *api.Client, id string, fields UpdateFields) (Asset, error)
- type AssetNode
- type Node
- type Platform
- type Spec
- type UpdateFields
Constants ¶
const ( // PathHosts is the host-asset collection. POST creates, GET lists. PathHosts = "/api/v1/assets/hosts/" // PathNodes lists the asset nodes (the "default" node is the one // every host asset belongs to). PathNodes = "/api/v1/assets/nodes/" // PathPlatforms lists the asset platforms; their id goes into a // create request as "platform". PathPlatforms = "/api/v1/assets/platforms/" )
Endpoint paths for the host-asset view.
const PlatformIDLinux = 1
PlatformIDLinux is the id of the built-in Linux platform. JumpServer assigns it at install time and it has been stable across the versions this client talks to.
Variables ¶
var ErrConflict = errors.New("asset name already exists")
ErrConflict is returned when the server refuses a create because the name is already taken.
var ErrNotFound = errors.New("asset not found")
ErrNotFound is returned when no asset matches an id or name.
Functions ¶
func DefaultNodeID ¶
DefaultNodeID returns the id of the default asset node, which is the node every host asset belongs to on a fresh install.
func DefaultProtocols ¶
func DefaultProtocols() []protocolRow
DefaultProtocols is what a host asset gets when Spec.Protocols is empty: ssh for the session and sftp for file transfer, both on 22.
Types ¶
type Account ¶
type Account struct {
ID string `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
Alias string `json:"alias"`
}
Account is an account attached to an asset. Creating a host asset with an account is what makes `jms exec` able to authenticate.
type AccountSpec ¶
type AccountSpec struct {
// Name is the account display name.
Name string
// Username is the login name on the target host.
Username string
// Password is the account secret. It is sent in the create request
// and never stored locally.
Password string
}
AccountSpec describes an account to attach to a new asset.
type Asset ¶
type Asset struct {
ID string `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Platform struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"platform"`
Comment string `json:"comment"`
Nodes []AssetNode `json:"nodes"`
Accounts []Account `json:"accounts"`
}
Asset is a host asset as the server reports it.
func Create ¶
Create creates a host asset and returns the created asset.
A name that already exists is reported as ErrConflict rather than a generic error, so a caller can tell "you already made this" from "the server said no".
func FindByName ¶
FindByName returns the asset with the given name.
The name must match exactly: two assets may share an address, and a prefix match would silently pick the wrong one.
func List ¶
List returns every host asset visible to the caller.
This is the admin view: it lists all assets, not only the ones the caller is permitted to connect to. Use the assets package's List for the permission-scoped view.
func Update ¶
Update applies the given fields to an existing asset.
The server treats PUT as a full replacement: it rejects the request unless name, address, platform and protocols are all present ("该字段 是必填项"). So the current asset is read first and the caller's fields are merged into it; only then is the complete object sent.
A field the caller did not mention keeps its current value — the merge is what stops an update from clearing the comment or the accounts.
type Node ¶
type Node struct {
ID string `json:"id"`
Key string `json:"key"`
Value string `json:"value"`
Name string `json:"name"`
}
Node is one asset node.
type Spec ¶
type Spec struct {
// Name is the asset name. It must be unique on the server.
Name string
// Address is the reachable address (IP or hostname).
Address string
// PlatformID selects the platform; zero means PlatformIDLinux.
PlatformID int
// NodeID is the node the asset belongs to. Empty means the default
// node is looked up.
NodeID string
// Accounts are the accounts to attach. An asset with no account can
// be listed but not connected to.
Accounts []AccountSpec
// Comment is the free-text note.
Comment string
// Protocols are the protocols to enable; empty means ssh+sftp.
Protocols []string
}
Spec describes the asset to create.
type UpdateFields ¶
UpdateFields carries the mutable fields of an asset. A nil pointer means "leave unchanged", so a caller can rename without clearing the comment.