Beispiel
github.com/aws/aws-sdk-go-v2 v1.47.0: aws.CredentialsCache
Verifiziertes Beispiel für golang github.com/aws/aws-sdk-go-v2 v1.47.0: aws.CredentialsCache. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und…
sha256:a98f17be261d40d9140458cdcc3248e7ca392e434212cd74328fc695efba85d0
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-10 |
Fall
HOW- Ziel
- verify github.com/aws/aws-sdk-go-v2/aws.CredentialsCache in pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
- Symbole
-
- github.com/aws/aws-sdk-go-v2/aws.CredentialsCache
- Umgebung
- go 1.26.6
- Erstellt
- 2026-10-10T06:04:41Z
Contract
- aws.NewCredentialsCache constructs a CredentialsCache wrapping a CredentialsProvider
- CredentialsCache.Retrieve returns cached credentials without calling the underlying provider on subsequent calls
- CredentialsCache.Invalidate clears cached credentials so the next Retrieve queries the underlying provider
- CredentialsCache.IsCredentialsProvider checks if wrapped provider matches target type
- CredentialsCache with ExpiryWindow refreshes credentials when expiration falls within window
- CredentialsCache.Retrieve propagates errors returned by the underlying provider
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Quelltext
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/aws/aws-sdk-go-v2/aws.CredentialsCache in pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
Demonstrate these symbols/APIs:
- github.com/aws/aws-sdk-go-v2/aws.CredentialsCache
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:8f068e97731218a5b227145ab31468ef6b7610c3555165248264b2af5c0a1403","contract":["aws.NewCredentialsCache constructs a CredentialsCache wrapping a CredentialsProvider","CredentialsCache.Retrieve returns cached credentials without calling the underlying provider on subsequent calls","CredentialsCache.Invalidate clears cached credentials so the next Retrieve queries the underlying provider","CredentialsCache.IsCredentialsProvider checks if wrapped provider matches target type","CredentialsCache with ExpiryWindow refreshes credentials when expiration falls within window","CredentialsCache.Retrieve propagates errors returned by the underlying provider"],"goal":"verify github.com/aws/aws-sdk-go-v2/aws.CredentialsCache in pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0","kind":"HOW","packages":["pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0"],"schemaVersion":1,"symbols":["github.com/aws/aws-sdk-go-v2/aws.CredentialsCache"]},"contractCommand":["go","run","./test"],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0","symbols":["github.com/aws/aws-sdk-go-v2/aws.CredentialsCache"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/aws/aws-sdk-go-v2 v1.47.0
require github.com/aws/smithy-go v1.28.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.47.0 h1:0jsHallhJCeaU0Ko48c/3FK1ctOQ7NpzggxriJOQ8MQ=
github.com/aws/aws-sdk-go-v2 v1.47.0/go.mod h1:bttEH6JqnUL8LepvDVfdrds/fZ5bCIxzpe3abyUrhDU=
github.com/aws/aws-sdk-go-v2 v1.47.3 h1:HRoT/MkNi3bjO5xF4dCzLzvVmkvRGHj3/cLINDnJejk=
github.com/aws/aws-sdk-go-v2 v1.47.3/go.mod h1:xSl+OSI5ZUw6bSMupWc218zE5Pl+65MCCu3ySWFY99A=
github.com/aws/smithy-go v1.28.5 h1:OqbqKtzY9NUnr2yAe9+hiTdFb20tNaK/lI0PMOGXX9k=
github.com/aws/smithy-go v1.28.5/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
package main
import (
"context"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
)
type staticProvider struct {
creds aws.Credentials
}
func (p *staticProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
return p.creds, nil
}
func main() {
ctx := context.Background()
provider := &staticProvider{
creds: aws.Credentials{
AccessKeyID: "mock-access-key-id",
SecretAccessKey: "mock-secret-access-key",
SessionToken: "mock-session-token",
Source: "StaticCredentials",
CanExpire: true,
Expires: time.Now().Add(15 * time.Minute),
},
}
cache := aws.NewCredentialsCache(provider, func(options *aws.CredentialsCacheOptions) {
options.ExpiryWindow = 2 * time.Minute
})
creds, err := cache.Retrieve(ctx)
if err != nil {
fmt.Printf("failed to retrieve credentials: %v\n", err)
return
}
fmt.Printf("retrieved credentials from cache (source: %s, hasKeys: %t)\n", creds.Source, creds.HasKeys())
cache.Invalidate()
fmt.Println("cache invalidated successfully")
}
{
"schemaVersion": 1,
"goal": "verify github.com/aws/aws-sdk-go-v2/aws.CredentialsCache in pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0"
],
"symbols": [
"github.com/aws/aws-sdk-go-v2/aws.CredentialsCache"
]
}
package main
import (
"context"
"errors"
"fmt"
"os"
"sync/atomic"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
)
type staticProvider struct {
creds aws.Credentials
}
func (s staticProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
return s.creds, nil
}
type countingProvider struct {
count atomic.Int64
creds aws.Credentials
}
func (c *countingProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
c.count.Add(1)
return c.creds, nil
}
type errorProvider struct {
err error
}
func (e errorProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
return aws.Credentials{}, e.err
}
func main() {
if err := runContract(); err != nil {
fmt.Fprintf(os.Stderr, "FAIL: %v\n", err)
os.Exit(1)
}
fmt.Println("PASS: all contract assertions satisfied")
}
func runContract() error {
ctx := context.Background()
// 1. aws.NewCredentialsCache constructs a CredentialsCache wrapping a CredentialsProvider
baseProvider := staticProvider{
creds: aws.Credentials{
AccessKeyID: "mock-key-1",
SecretAccessKey: "mock-secret-1",
SessionToken: "mock-token-1",
Source: "StaticTest",
},
}
cache := aws.NewCredentialsCache(baseProvider)
if cache == nil {
return fmt.Errorf("NewCredentialsCache returned nil")
}
// 2. CredentialsCache.Retrieve returns cached credentials without calling the underlying provider on subsequent calls
counter := &countingProvider{
creds: aws.Credentials{
AccessKeyID: "mock-cached-key",
SecretAccessKey: "mock-cached-secret",
Source: "CountingProvider",
CanExpire: true,
Expires: time.Now().Add(2 * time.Hour),
},
}
countingCache := aws.NewCredentialsCache(counter)
c1, err := countingCache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("countingCache first Retrieve failed: %w", err)
}
c2, err := countingCache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("countingCache second Retrieve failed: %w", err)
}
if c1.AccessKeyID != "mock-cached-key" || c2.AccessKeyID != "mock-cached-key" {
return fmt.Errorf("retrieved credentials mismatch")
}
if calls := counter.count.Load(); calls != 1 {
return fmt.Errorf("expected 1 call to underlying provider, got %d", calls)
}
// 3. CredentialsCache.Invalidate clears cached credentials so the next Retrieve queries the underlying provider
countingCache.Invalidate()
c3, err := countingCache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("countingCache third Retrieve after Invalidate failed: %w", err)
}
if c3.AccessKeyID != "mock-cached-key" {
return fmt.Errorf("unexpected credentials after Invalidate")
}
if calls := counter.count.Load(); calls != 2 {
return fmt.Errorf("expected 2 calls to underlying provider after Invalidate, got %d", calls)
}
// 4. CredentialsCache.IsCredentialsProvider checks if wrapped provider matches target type
if !countingCache.IsCredentialsProvider(&countingProvider{}) {
return fmt.Errorf("expected IsCredentialsProvider to match &countingProvider{}")
}
if countingCache.IsCredentialsProvider(staticProvider{}) {
return fmt.Errorf("expected IsCredentialsProvider to not match staticProvider{}")
}
// 5. CredentialsCache with ExpiryWindow refreshes credentials when expiration falls within window
refreshCounter := &countingProvider{
creds: aws.Credentials{
AccessKeyID: "expiring-key",
SecretAccessKey: "expiring-secret",
Source: "RefreshProvider",
CanExpire: true,
Expires: time.Now().Add(30 * time.Second),
},
}
windowCache := aws.NewCredentialsCache(refreshCounter, func(options *aws.CredentialsCacheOptions) {
options.ExpiryWindow = 5 * time.Minute
})
_, err = windowCache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("windowCache first Retrieve failed: %w", err)
}
_, err = windowCache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("windowCache second Retrieve failed: %w", err)
}
if calls := refreshCounter.count.Load(); calls != 2 {
return fmt.Errorf("expected 2 calls due to ExpiryWindow expiration, got %d", calls)
}
// 6. CredentialsCache.Retrieve propagates errors returned by the underlying provider
expectedErr := errors.New("simulated upstream failure")
errCache := aws.NewCredentialsCache(errorProvider{err: expectedErr})
_, err = errCache.Retrieve(ctx)
if err == nil {
return fmt.Errorf("expected error from errCache, got nil")
}
if !errors.Is(err, expectedErr) {
return fmt.Errorf("expected %v, got %v", expectedErr, err)
}
return nil
}
Ursprungs-Seeder
anonym