offeringprice

package
v0.0.0-...-36f5383 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: OSL-3.0 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 offeringprice turns the price fields of an AWS reserved-capacity offering into the figures common.OfferingDetails reports. All amounts are per ONE reservation in the offering's currency; callers multiply by the purchase count.

Index

Constants

View Source
const UpfrontTolerance = 0.05

UpfrontTolerance is the fraction by which a resolved offering's upfront may exceed the approved recommendation's upfront before a purchase is refused. It absorbs Cost Explorer rounding; anything beyond it means the offering was repriced or a differently-priced variant matched, so the approval no longer covers it.

Variables

View Source
var ErrPurchaseCountOutOfRange = errors.New("purchase count out of range")

ErrPurchaseCountOutOfRange marks a purchase count PurchaseCount refused.

Functions

func AssumedUSD

func AssumedUSD(service, region string) (string, error)

AssumedUSD is for offering types whose SDK struct has no currency field (ElastiCache, MemoryDB). Commercial and GovCloud AWS bill those in USD; the China partitions do not, so they fail instead of being labeled USD.

func CheckUpfront

func CheckUpfront(service string, offeredTotal, approved float64) error

CheckUpfront fails when offeredTotal exceeds UpfrontCeiling(approved), both compared in whole cents, and when approved is NaN or infinite (every comparison against those is false, so they would pass). Callers skip the call when NoUpfrontApproved(approved).

func Currency

func Currency(service, code string) (string, error)

Currency returns the currency AWS reported, and fails when it is empty because a price without a currency cannot be compared to a USD ceiling.

func IsChinaRegion

func IsChinaRegion(region string) bool

IsChinaRegion reports whether region is in the aws-cn partition (cn-north-1, cn-northwest-1), which bills in CNY.

func NoUpfrontApproved

func NoUpfrontApproved(approved float64) bool

NoUpfrontApproved reports whether approved gives no ceiling to check: zero or negative means a no-upfront option or a missing figure. NaN and +-Inf are not "no figure" (a corrupt one), so they return false and CheckUpfront refuses them.

func PurchaseCount

func PurchaseCount(n int) (int32, error)

PurchaseCount returns n as the int32 the AWS purchase inputs take. It refuses a count outside [1, math.MaxInt32] instead of letting int32(n) wrap into a wrong, possibly positive, quantity. Call it before any AWS call.

func RequireClientRegion

func RequireClientRegion(recRegion, clientRegion string) error

RequireClientRegion refuses a recommendation for another region than the client's: lookup and purchase run in the client's region, so a mismatch would buy there instead. An empty recRegion means "the client's region" and passes. The error wraps common.ErrRefusedBeforePurchase. Call it before any AWS call.

func UpfrontCeiling

func UpfrontCeiling(approved float64) float64

UpfrontCeiling is the most a purchase may charge upfront for an approved upfront amount.

Types

type Charge

type Charge struct {
	Frequency string
	Amount    float64
}

Charge is one recurring charge of an offering.

type Input

type Input struct {
	// Service names the AWS service in error messages and term parsing.
	Service string

	// Term is the requested term (rec.Term); it must match the offering.
	Term common.Term

	Charges []Charge

	// FixedPrice is the upfront price per reservation.
	FixedPrice float64

	// UsagePrice is the legacy per-hour price per reservation. It is used
	// only when the recurring charges sum to zero.
	UsagePrice float64

	// DurationSeconds is the offering's own duration; 0 means missing.
	DurationSeconds int64
}

Input is the price data of one offering.

type Pricing

type Pricing struct {
	// Upfront is the one-time price.
	Upfront float64
	// Hourly is the recurring price per hour.
	Hourly float64
	// Total is Upfront + Hourly * term hours, in the offering's currency.
	Total float64
	// EffectiveHourly is Total / term hours.
	EffectiveHourly float64
}

Pricing is the priced offering, per one reservation.

func Price

func Price(in Input) (Pricing, error)

Price computes the pricing of an offering. It fails on a missing or mismatched duration, a negative or non-finite amount, a recurring charge that is not hourly, and an offering with both a nonzero recurring charge and a nonzero UsagePrice (ambiguous, so not guessed).

Jump to

Keyboard shortcuts

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