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
- Variables
- func AssumedUSD(service, region string) (string, error)
- func CheckUpfront(service string, offeredTotal, approved float64) error
- func Currency(service, code string) (string, error)
- func IsChinaRegion(region string) bool
- func NoUpfrontApproved(approved float64) bool
- func PurchaseCount(n int) (int32, error)
- func RequireClientRegion(recRegion, clientRegion string) error
- func UpfrontCeiling(approved float64) float64
- type Charge
- type Input
- type Pricing
Constants ¶
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 ¶
var ErrPurchaseCountOutOfRange = errors.New("purchase count out of range")
ErrPurchaseCountOutOfRange marks a purchase count PurchaseCount refused.
Functions ¶
func AssumedUSD ¶
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 ¶
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 ¶
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 ¶
IsChinaRegion reports whether region is in the aws-cn partition (cn-north-1, cn-northwest-1), which bills in CNY.
func NoUpfrontApproved ¶
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 ¶
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 ¶
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 ¶
UpfrontCeiling is the most a purchase may charge upfront for an approved upfront amount.
Types ¶
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.