assetsmanage

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

View Source
var ErrConflict = errors.New("asset name already exists")

ErrConflict is returned when the server refuses a create because the name is already taken.

View Source
var ErrNotFound = errors.New("asset not found")

ErrNotFound is returned when no asset matches an id or name.

Functions

func DefaultNodeID

func DefaultNodeID(ctx context.Context, c *api.Client) (string, error)

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.

func Delete

func Delete(ctx context.Context, c *api.Client, id string) error

Delete removes an asset.

The asset view answers DELETE on the resource itself; it rejects POST with "method_not_allowed", so a delete cannot be expressed as a POST with an ?action=delete query.

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

func Create(ctx context.Context, c *api.Client, spec Spec) (Asset, error)

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

func FindByName(ctx context.Context, c *api.Client, name string) (Asset, error)

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 Get

func Get(ctx context.Context, c *api.Client, id string) (Asset, error)

Get returns one asset by id.

func List

func List(ctx context.Context, c *api.Client) ([]Asset, error)

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

func Update(ctx context.Context, c *api.Client, id string, fields UpdateFields) (Asset, error)

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 AssetNode

type AssetNode struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

AssetNode is a node an asset belongs to.

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.

func Nodes

func Nodes(ctx context.Context, c *api.Client) ([]Node, error)

Nodes returns the asset nodes.

type Platform

type Platform struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Platform is one asset platform.

func Platforms

func Platforms(ctx context.Context, c *api.Client) ([]Platform, error)

Platforms returns the asset platforms.

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

type UpdateFields struct {
	Name    *string
	Comment *string
	Address *string
}

UpdateFields carries the mutable fields of an asset. A nil pointer means "leave unchanged", so a caller can rename without clearing the comment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL