샘플
github.com/aws/aws-sdk-go-v2 v1.47.0: aws.CredentialsCache
검증된 샘플 — golang github.com/aws/aws-sdk-go-v2 v1.47.0: aws.CredentialsCache. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:a98f17be261d40d9140458cdcc3248e7ca392e434212cd74328fc695efba85d0
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify github.com/aws/aws-sdk-go-v2/aws.CredentialsCache in pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.0
- 심벌
-
- github.com/aws/aws-sdk-go-v2/aws.CredentialsCache
- 환경
- go 1.26.6
- 생성일
- 2026-10-10T06:04:41Z
컨트랙트
- 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
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
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
}
오리진 시더
익명