auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 13 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 auth provides authentication utilities for the AhaSend CLI.

This package handles client authentication through multiple methods:

  • Global API key flags (--api-key and --account-id)
  • Profile-based authentication from configuration files
  • Profile switching and validation

The main function GetAuthenticatedClient creates authenticated clients for use by CLI commands, handling the authentication precedence and validation automatically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAuthenticatedClient

func GetAuthenticatedClient(cmd *cobra.Command) (client.AhaSendClient, error)

GetAuthenticatedClient returns an authenticated AhaSend client It checks for global flags first, then falls back to profiles

func IsKeyRefused added in v0.3.0

func IsKeyRefused(err error) bool

IsKeyRefused reports whether err, from CheckKey, is the API refusing the key: a 401, or a 403 for the key's IP address.

func SetAuthenticatedClientResolverForTesting

func SetAuthenticatedClientResolverForTesting(resolver ClientResolver) func()

SetAuthenticatedClientResolverForTesting overrides authenticated client resolution for tests.

func WarnIfUnencryptedAPIKey added in v0.3.0

func WarnIfUnencryptedAPIKey(cmd *cobra.Command, apiURL string)

WarnIfUnencryptedAPIKey writes a warning to stderr, once per run, when apiURL, the API URL of a profile or of auth login, sends the API key over plain HTTP to a host that is not a loopback host.

Types

type ClientResolver

type ClientResolver func(*cobra.Command) (client.AhaSendClient, error)

ClientResolver resolves an authenticated AhaSend client for a command.

type KeyCheck added in v0.3.0

type KeyCheck struct {
	// Account is the key's account, or nil when the key may not read it.
	Account *responses.Account
	// Unreadable is the API's refusal (HTTP 403) to show the account to a
	// key that belongs to it but lacks the scope to read it, or nil.
	Unreadable error
}

KeyCheck is the result of a check of an API key that passed.

func CheckKey added in v0.3.0

func CheckKey(c client.AhaSendClient) (KeyCheck, error)

CheckKey checks that the API key of c belongs to the account ID of c by reading the account. The API answers an account route with 401 when the key belongs to another account; GET /v2/ping does not check the account, so it cannot tell.

A 403 from the account route is either the key's IP allow-list, which the API checks before the account, or the key's scope, which it checks after. Ping comes after the IP check and before the scope check, so CheckKey pings to tell them apart: a 403 from ping means the key may not be used from this IP, and fails the check with the API's 403; a ping that succeeds means the key belongs to the account but may not read it, which passes the check.

A 401 is an auth error that names the account ID; any other failure is returned as it is.

Jump to

Keyboard shortcuts

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