api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("session expired: please log in again")

ErrUnauthorized is returned when the server returns HTTP 401 or API code 401, indicating the session has expired and the user must log in again.

Functions

func RoleName

func RoleName(role int) string

RoleName returns a human-readable role name. API role values: 1=User, 2=Admin, 3=Superadmin.

Types

type AdminUser

type AdminUser struct {
	Username    string `json:"username"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
	Role        int    `json:"role"`
}

AdminUser represents a user in the admin view (UserProfileDTO from API).

type AnalyzeCertRequest

type AnalyzeCertRequest struct {
	Cert string `json:"cert"`
}

AnalyzeCertRequest is the request to analyze a certificate.

type AnalyzePrivKeyRequest

type AnalyzePrivKeyRequest struct {
	PrivKey  string `json:"privkey"`
	Password string `json:"password,omitempty"`
}

AnalyzePrivKeyRequest is the request to analyze a private key.

type BatchDeleteUsersRequest

type BatchDeleteUsersRequest struct {
	Usernames []string `json:"usernames"`
}

BatchDeleteUsersRequest deletes multiple users.

type BindUsersRequest

type BindUsersRequest struct {
	Usernames []string `json:"usernames"`
}

BindUsersRequest binds users to a CA.

type CABindingDTO

type CABindingDTO struct {
	CaUUID   string `json:"caUuid"`
	Username string `json:"username"`
}

CABindingDTO represents a CA-User binding.

type CACert

type CACert struct {
	UUID       string `json:"uuid"`
	Owner      string `json:"owner"`
	AllowSubCa bool   `json:"allowSubCa"`
	ParentCa   string `json:"parentCa"`
	Comment    string `json:"comment"`
	Available  bool   `json:"available"`
	NotBefore  string `json:"notBefore"`
	NotAfter   string `json:"notAfter"`
}

CACert represents a CA certificate info DTO (CaInfoDTO from API).

func (*CACert) CAType

func (c *CACert) CAType() string

CAType returns the certificate type: "Root CA", "Int CA", or "Leaf CA".

type CertAnalysis

type CertAnalysis struct {
	Subject      string                 `json:"subject,omitempty"`
	Issuer       string                 `json:"issuer,omitempty"`
	NotBefore    string                 `json:"notBefore"`
	NotAfter     string                 `json:"notAfter"`
	SerialNumber string                 `json:"serialNumber,omitempty"`
	Algorithm    string                 `json:"algorithm"`
	IsCA         bool                   `json:"isCA"`
	Fingerprint  string                 `json:"fingerprint,omitempty"`
	PublicKey    map[string]interface{} `json:"publicKey,omitempty"`
	Extensions   map[string]string      `json:"extensions,omitempty"`
	SANs         []string               `json:"subjectAltNames,omitempty"`
}

CertAnalysis holds the result of a certificate analysis. The fields are a superset of all possible API response fields.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the CertVault API HTTP client.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates a new API client.

func (*Client) AnalyzeCert

func (c *Client) AnalyzeCert(ctx context.Context, cert string) (*CertAnalysis, error)

AnalyzeCert analyzes a PEM certificate. The cert argument must already be base64-encoded (as returned by the cert fetch endpoints).

func (*Client) AnalyzePrivKey

func (c *Client) AnalyzePrivKey(ctx context.Context, privKey, password string) (*PrivKeyAnalysis, error)

AnalyzePrivKey analyzes a private key. The privKey argument must already be base64-encoded (as returned by the privkey fetch endpoints).

func (*Client) BatchCreateUsers

func (c *Client) BatchCreateUsers(ctx context.Context, users []CreateUserRequest) error

BatchCreateUsers creates multiple users at once.

func (*Client) BatchDeleteUsers

func (c *Client) BatchDeleteUsers(ctx context.Context, usernames []string) error

BatchDeleteUsers deletes multiple users at once.

func (*Client) BindUsersToCA

func (c *Client) BindUsersToCA(ctx context.Context, caUUID string, usernames []string) error

BindUsersToCA binds a user to a CA. Uses POST /api/v1/admin/cert/ca/bind/create with CABindingDTO.

func (*Client) ConvertDERtoPEM

func (c *Client) ConvertDERtoPEM(ctx context.Context, der string) (*ConvertResult, error)

ConvertDERtoPEM converts a base64-encoded DER certificate to PEM format.

func (*Client) ConvertPEMtoDER

func (c *Client) ConvertPEMtoDER(ctx context.Context, pem string) (*ConvertResult, error)

ConvertPEMtoDER converts a PEM certificate to DER format.

func (*Client) ConvertPEMtoPFX

func (c *Client) ConvertPEMtoPFX(ctx context.Context, req ConvertPEMtoPFXRequest) (*ConvertResult, error)

ConvertPEMtoPFX converts a PEM cert+key to PFX format.

func (*Client) CountAdminCAs

func (c *Client) CountAdminCAs(ctx context.Context) (int64, error)

CountAdminCAs returns the total number of CA certs (admin+).

func (*Client) CountAdminUsers

func (c *Client) CountAdminUsers(ctx context.Context) (int64, error)

CountAdminUsers returns the total number of users (admin+).

func (*Client) CountAllCAs

func (c *Client) CountAllCAs(ctx context.Context) (int64, error)

CountAllCAs returns the total number of CA certs (superadmin only).

func (*Client) CountAllSSLCerts

func (c *Client) CountAllSSLCerts(ctx context.Context) (int64, error)

CountAllSSLCerts returns the total number of SSL certs (superadmin only).

func (*Client) CountUserCAs

func (c *Client) CountUserCAs(ctx context.Context) (int64, error)

CountUserCAs returns the number of CAs bound to the current user.

func (*Client) CountUserSSLCerts

func (c *Client) CountUserSSLCerts(ctx context.Context) (int64, error)

CountUserSSLCerts returns the number of SSL certs owned by the current user.

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, req CreateUserRequest) (*AdminUser, error)

CreateUser creates a new user (superadmin only).

func (*Client) DeleteAdminCA

func (c *Client) DeleteAdminCA(ctx context.Context, uuid string) error

DeleteAdminCA deletes a CA certificate.

func (*Client) DeleteSSLCert

func (c *Client) DeleteSSLCert(ctx context.Context, uuid string) error

DeleteSSLCert deletes an SSL certificate.

func (*Client) DeleteSuperadminUser

func (c *Client) DeleteSuperadminUser(ctx context.Context, username string) error

DeleteSuperadminUser deletes a user (superadmin only).

func (*Client) ForceLogoutUser

func (c *Client) ForceLogoutUser(ctx context.Context, username string) error

ForceLogoutUser force-logs out a user (superadmin only).

func (*Client) GetAdminCACert

func (c *Client) GetAdminCACert(ctx context.Context, uuid string, chain, needRoot bool) (string, error)

GetAdminCACert gets the CA certificate PEM.

func (*Client) GetAdminCAPrivKey

func (c *Client) GetAdminCAPrivKey(ctx context.Context, uuid, password string) (string, error)

GetAdminCAPrivKey gets the CA private key. The API returns the private key as a base64-encoded PEM string in the data field.

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

GetBaseURL returns the base URL.

func (*Client) GetBoundUsers

func (c *Client) GetBoundUsers(ctx context.Context, uuid string, page, size int) (*PageDTO[AdminUser], error)

GetBoundUsers gets users bound to a CA. Uses GET /api/v1/admin/cert/ca/{uuid}/bind.

func (*Client) GetOIDCAuthURL

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

GetOIDCAuthURL returns the OIDC authorization URL.

func (*Client) GetProfile

func (c *Client) GetProfile(ctx context.Context) (*UserProfile, error)

GetProfile returns the current user's profile.

func (*Client) GetSession

func (c *Client) GetSession() string

GetSession returns the current JSESSIONID value.

func (*Client) GetUnboundUsers

func (c *Client) GetUnboundUsers(ctx context.Context, uuid string, page, size int) (*PageDTO[AdminUser], error)

GetUnboundUsers gets users not yet bound to a CA. Uses GET /api/v1/admin/cert/ca/{uuid}/bind/not.

func (*Client) GetUserCACert

func (c *Client) GetUserCACert(ctx context.Context, uuid string, chain, needRoot bool) (string, error)

GetUserCACert gets the PEM certificate for a CA.

func (*Client) GetUserSSLCert

func (c *Client) GetUserSSLCert(ctx context.Context, uuid string, chain, needRoot bool) (string, error)

GetUserSSLCert gets the PEM certificate content. chain=true fetches the full certificate chain; needRoot=false excludes the root CA.

func (*Client) GetUserSSLPrivKey

func (c *Client) GetUserSSLPrivKey(ctx context.Context, uuid, password string) (string, error)

GetUserSSLPrivKey retrieves the encrypted private key. The API returns the private key as a base64-encoded PEM string in the data field.

func (*Client) ImportAdminCA

func (c *Client) ImportAdminCA(ctx context.Context, req ImportCACertRequest) (*CACert, error)

ImportAdminCA imports a CA certificate.

func (*Client) ListAdminCAs

func (c *Client) ListAdminCAs(ctx context.Context, page, size int) (*PageDTO[CACert], error)

ListAdminCAs lists all CA certificates (admin only).

func (*Client) ListAdminUsers

func (c *Client) ListAdminUsers(ctx context.Context, page, size int) (*PageDTO[AdminUser], error)

ListAdminUsers lists all users (admin only).

func (*Client) ListAllSessions

func (c *Client) ListAllSessions(ctx context.Context, page, limit int) (*PageDTO[LoginRecord], error)

ListAllSessions lists all sessions across all users (superadmin only).

func (*Client) ListUserCAs

func (c *Client) ListUserCAs(ctx context.Context, page, size int) (*PageDTO[CACert], error)

ListUserCAs lists CAs bound to the current user.

func (*Client) ListUserSSLCerts

func (c *Client) ListUserSSLCerts(ctx context.Context, page, size int) (*PageDTO[SSLCert], error)

ListUserSSLCerts lists SSL certs belonging to the current user.

func (*Client) ListUserSessions

func (c *Client) ListUserSessions(ctx context.Context, page, size int) (*PageDTO[LoginRecord], error)

ListUserSessions lists the current user's sessions.

func (*Client) ListUserSessionsBySuperadmin

func (c *Client) ListUserSessionsBySuperadmin(ctx context.Context, username string, page, limit int) (*PageDTO[LoginRecord], error)

ListUserSessionsBySuperadmin lists sessions for a specific user (superadmin only).

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) error

Login authenticates with the server and stores the session.

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout logs out the current session.

func (*Client) LogoutAllSessions

func (c *Client) LogoutAllSessions(ctx context.Context) error

LogoutAllSessions logs out all sessions for the current user.

func (*Client) LogoutSession

func (c *Client) LogoutSession(ctx context.Context, uuid string) error

LogoutSession logs out a specific session by UUID.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks if the server is reachable.

func (*Client) RenewAdminCA

func (c *Client) RenewAdminCA(ctx context.Context, uuid string, req RenewCACertRequest) (*CACert, error)

RenewAdminCA renews a CA certificate.

func (*Client) RenewSSLCert

func (c *Client) RenewSSLCert(ctx context.Context, uuid string, req RenewSSLCertRequest) (*SSLCert, error)

RenewSSLCert renews an SSL certificate.

func (*Client) RequestAdminCA

func (c *Client) RequestAdminCA(ctx context.Context, req RequestCACertRequest) (*CACert, error)

RequestAdminCA creates a new CA certificate.

func (*Client) RequestSSLCert

func (c *Client) RequestSSLCert(ctx context.Context, req RequestSSLCertRequest) (*SSLCert, error)

RequestSSLCert requests a new SSL certificate.

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string)

SetBaseURL updates the base URL.

func (*Client) SetSession

func (c *Client) SetSession(session string)

SetSession sets the JSESSIONID cookie on the client.

func (*Client) ToggleAdminCAAvailable

func (c *Client) ToggleAdminCAAvailable(ctx context.Context, uuid string, available bool) error

ToggleAdminCAAvailable toggles the CA availability.

func (*Client) UnbindUsersFromCA

func (c *Client) UnbindUsersFromCA(ctx context.Context, caUUID string, usernames []string) error

UnbindUsersFromCA unbinds a user from a CA. Uses POST /api/v1/admin/cert/ca/bind/delete with CABindingDTO.

func (*Client) UpdateAdminCAComment

func (c *Client) UpdateAdminCAComment(ctx context.Context, uuid, comment string) error

UpdateAdminCAComment updates the CA comment.

func (*Client) UpdateProfile

func (c *Client) UpdateProfile(ctx context.Context, req UpdateProfileRequest) error

UpdateProfile updates the current user's profile.

func (*Client) UpdateSSLCertComment

func (c *Client) UpdateSSLCertComment(ctx context.Context, uuid, comment string) error

UpdateSSLCertComment updates the comment on an SSL cert.

func (*Client) UpdateSuperadminUser

func (c *Client) UpdateSuperadminUser(ctx context.Context, username string, req UpdateSuperadminUserRequest) error

UpdateSuperadminUser updates a user's info (superadmin only).

func (*Client) UpdateUserRole

func (c *Client) UpdateUserRole(ctx context.Context, req UpdateUserRoleRequest) error

UpdateUserRole updates a user's role (superadmin only).

type ConvertPEMtoPFXRequest

type ConvertPEMtoPFXRequest struct {
	Cert     string `json:"cert"`
	PrivKey  string `json:"privkey"`
	Password string `json:"password"`
}

ConvertPEMtoPFXRequest converts PEM to PFX.

type ConvertRequest

type ConvertRequest struct {
	Cert    string `json:"cert,omitempty"`
	PrivKey string `json:"privkey,omitempty"`
}

ConvertRequest for PEM↔DER conversions.

type ConvertResult

type ConvertResult struct {
	Data string `json:"data"`
}

ConvertResult holds a converted certificate.

type CreateUserRequest

type CreateUserRequest struct {
	Username    string `json:"username"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
	Password    string `json:"password"`
	Role        int    `json:"role"`
}

CreateUserRequest creates a new user.

type GetPrivKeyRequest

type GetPrivKeyRequest struct {
	Password string `json:"password"`
}

GetPrivKeyRequest requests a private key.

type ImportCACertRequest

type ImportCACertRequest struct {
	Certificate string `json:"certificate"`
	PrivKey     string `json:"privkey"`
	Comment     string `json:"comment,omitempty"`
}

ImportCACertRequest is the request to import a CA certificate.

type LoginRecord

type LoginRecord struct {
	UUID      string `json:"uuid"`
	Username  string `json:"username"`
	IPAddress string `json:"ipAddress"`
	Region    string `json:"region"`
	Province  string `json:"province"`
	City      string `json:"city"`
	Browser   string `json:"browser"`
	OS        string `json:"os"`
	LoginTime string `json:"loginTime"`
	IsOnline  bool   `json:"isOnline"`
}

LoginRecord represents a user login/session record (LoginRecordDTO).

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

LoginRequest is the request body for login.

type PageDTO

type PageDTO[T any] struct {
	Total int64 `json:"total"`
	List  []T   `json:"list"`
}

PageDTO is a paginated list response.

type PrivKeyAnalysis

type PrivKeyAnalysis struct {
	Algorithm string `json:"algorithm"`
	KeySize   int    `json:"keySize"`
}

PrivKeyAnalysis holds the result of a private key analysis.

type PrivKeyResponse

type PrivKeyResponse struct {
	PrivateKey string `json:"privateKey"`
}

PrivKeyResponse holds an encrypted private key.

type RenewCACertRequest

type RenewCACertRequest struct {
	Expiry int `json:"expiry"`
}

RenewCACertRequest is the request to renew a CA certificate.

type RenewSSLCertRequest

type RenewSSLCertRequest struct {
	Expiry int `json:"expiry"`
}

RenewSSLCertRequest is the request to renew an SSL cert.

type RequestCACertRequest

type RequestCACertRequest struct {
	CaUUID             string `json:"caUuid,omitempty"`
	AllowSubCa         bool   `json:"allowSubCa"`
	Algorithm          string `json:"algorithm,omitempty"`
	KeySize            int    `json:"keySize,omitempty"`
	Country            string `json:"country"`
	Province           string `json:"province"`
	City               string `json:"city"`
	Organization       string `json:"organization"`
	OrganizationalUnit string `json:"organizationalUnit"`
	CommonName         string `json:"commonName"`
	Expiry             int    `json:"expiry"`
	Comment            string `json:"comment,omitempty"`
}

RequestCACertRequest is the request to create a CA certificate.

type RequestSSLCertRequest

type RequestSSLCertRequest struct {
	CaUUID             string           `json:"caUuid"`
	Algorithm          string           `json:"algorithm,omitempty"`
	KeySize            int              `json:"keySize,omitempty"`
	Country            string           `json:"country"`
	Province           string           `json:"province"`
	City               string           `json:"city"`
	Organization       string           `json:"organization"`
	OrganizationalUnit string           `json:"organizationalUnit"`
	CommonName         string           `json:"commonName"`
	Expiry             int              `json:"expiry"`
	SubjectAltNames    []SubjectAltName `json:"subjectAltNames,omitempty"`
	Comment            string           `json:"comment,omitempty"`
}

RequestSSLCertRequest is the request to issue a new SSL cert (matches API DTO).

type ResultVO

type ResultVO[T any] struct {
	Code      int    `json:"code"`
	Msg       string `json:"msg"`
	Data      T      `json:"data"`
	Timestamp string `json:"timestamp"`
}

ResultVO is the generic API response wrapper.

type SSLCert

type SSLCert struct {
	UUID       string `json:"uuid"`
	CaUUID     string `json:"caUuid"`
	Owner      string `json:"owner"`
	Comment    string `json:"comment"`
	NotBefore  string `json:"notBefore"`
	NotAfter   string `json:"notAfter"`
	CreatedAt  string `json:"createdAt"`
	ModifiedAt string `json:"modifiedAt"`
}

SSLCert represents an SSL certificate info DTO (CertInfoDTO from API).

type SubjectAltName

type SubjectAltName struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

SubjectAltName represents a SAN entry.

type ToggleAvailableRequest

type ToggleAvailableRequest struct {
	Available bool `json:"available"`
}

ToggleAvailableRequest toggles CA availability.

type UpdateCommentRequest

type UpdateCommentRequest struct {
	Comment string `json:"comment"`
}

UpdateCommentRequest updates a comment.

type UpdateProfileRequest

type UpdateProfileRequest struct {
	DisplayName string `json:"displayName,omitempty"`
	Email       string `json:"email,omitempty"`
	OldPassword string `json:"oldPassword,omitempty"`
	NewPassword string `json:"newPassword,omitempty"`
}

UpdateProfileRequest for PATCH /api/v1/user/profile

type UpdateSuperadminUserRequest

type UpdateSuperadminUserRequest struct {
	DisplayName string `json:"displayName,omitempty"`
	Email       string `json:"email,omitempty"`
	Password    string `json:"password,omitempty"`
}

UpdateSuperadminUserRequest updates user info (superadmin).

type UpdateUserRoleRequest

type UpdateUserRoleRequest struct {
	Username string `json:"username"`
	Role     int    `json:"role"`
}

UpdateUserRoleRequest updates a user's role.

type UserProfile

type UserProfile struct {
	Username    string `json:"username"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
	Role        int    `json:"role"`
}

UserProfile represents a user's profile.

Jump to

Keyboard shortcuts

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