assets

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 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 assets looks up JumpServer assets and resolves their connection parameters.

Endpoints and selection rules mirror the Python reference implementation (DESIGN.md「KoKo 协议」的「认证」). The account-selection order in particular is not arbitrary: the connection-token API requires the account *alias* (e.g. "@USER"), and the server rejects the display name.

Dependency direction: assets depends on api.

Index

Constants

View Source
const (
	PathSelfAssets = "/api/v1/perms/users/self/assets/"
)

PathSelfAssets is the listing endpoint; a detail request appends "<id>/".

Variables

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

ErrNotFound is returned when no asset matches a name.

Functions

func SelectAccount

func SelectAccount(permed []map[string]any) string

SelectAccount picks the best account alias: @USER > a named account > @INPUT.

The connection-token API needs the account *alias* (e.g. "@USER"), not the display name (e.g. "Dynamic user"). An entry that carries neither a usable alias nor username is skipped, which is why the "@USER" scan is a separate pass.

func SelectProtocol

func SelectProtocol(permed []map[string]any) string

SelectProtocol picks the best protocol, preferring ssh (case insensitive). It returns the canonical lower-case "ssh" so callers do not have to normalize.

Types

type Asset

type Asset struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Address  string `json:"address"`
	Platform string `json:"platform"`
	// Type is the asset type label (e.g. "Linux", "网站"). The API returns
	// it as {"label":...,"value":...} or as a bare string.
	Type string `json:"type"`
}

Asset is one row of an asset listing.

func List

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

List returns authorized assets, at most limit entries.

A limit of 0 or less returns everything. Pagination is api.Client.GetAll's job, so the whole listing is fetched and then truncated; the Python reference stops paging early, but the Go transport materializes pages.

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

Search returns every authorized asset matching keyword (name, address or comment).

type Info

type Info struct {
	ID       string
	Name     string
	Address  string
	Account  string
	Protocol string
	Platform string
	Type     string
	OrgID    string
}

Info is a resolved, connectable asset.

func Resolve

func Resolve(ctx context.Context, c *api.Client, name, account, protocol string) (Info, error)

Resolve searches an asset by name and resolves its connection parameters. An exact name match wins; otherwise the first decodable search result is used.

account and protocol override the automatic selection when non-empty.

Errors: ErrNotFound (wrapped) when the search yields no usable asset.

Jump to

Keyboard shortcuts

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