サンプル
github.com/aws/aws-sdk-go-v2 v1.47.3: aws.NewConfig, aws.String, aws.ToString
検証済みサンプル — golang github.com/aws/aws-sdk-go-v2 v1.47.3: aws.NewConfig, aws.String, aws.ToString. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.
sha256:4d2a71f3325bdae366408be075e76b53783c6a29ce8f486374019466f5a9d67e
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 go
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3
- シンボル
-
- aws.NewConfig
- aws.String
- aws.ToString
- aws.CredentialsProviderFunc
- aws.NewCredentialsCache
- aws.AnonymousCredentials
- 作成日
- 2026-10-10T02:23:58Z
コントラクト
- aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy
- aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling
- aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials
- aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider
- aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.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 pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3
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:e5373ba857179838f7fe29d621e62b1add462eadecbc270886e56989963aef14","contract":["aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy","aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling","aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials","aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider","aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error"],"goal":"verify pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3","kind":"HOW","packages":["pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3"],"schemaVersion":1,"symbols":["aws.NewConfig","aws.String","aws.ToString","aws.CredentialsProviderFunc","aws.NewCredentialsCache","aws.AnonymousCredentials"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3"],"schemaVersion":1,"subject":"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3","symbols":["aws.NewConfig","aws.String","aws.ToString","aws.CredentialsProviderFunc","aws.NewCredentialsCache","aws.AnonymousCredentials"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/aws/aws-sdk-go-v2 v1.47.3
require github.com/aws/smithy-go v1.28.5 // indirect
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 sample
import (
"context"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
)
// ClientConfigHolder wraps an aws.Config with helper methods.
type ClientConfigHolder struct {
Config aws.Config
}
// NewClientConfigHolder creates a new ClientConfigHolder with specified region and credentials provider.
func NewClientConfigHolder(region string, creds aws.CredentialsProvider) (*ClientConfigHolder, error) {
if region == "" {
return nil, fmt.Errorf("region cannot be empty")
}
cfg := aws.NewConfig()
cfg.Region = region
cfg.Credentials = creds
return &ClientConfigHolder{
Config: cfg.Copy(),
}, nil
}
// CreateStaticCredentialsProvider returns a CredentialsProvider that supplies static credentials.
func CreateStaticCredentialsProvider(accessKey, secretKey, sessionToken string) aws.CredentialsProvider {
return aws.CredentialsProviderFunc(func(ctx context.Context) (aws.Credentials, error) {
return aws.Credentials{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
SessionToken: sessionToken,
Source: "StaticCredentialsProvider",
}, nil
})
}
// CreateCachedCredentialsProvider wraps an underlying provider with a CredentialsCache.
func CreateCachedCredentialsProvider(provider aws.CredentialsProvider, expiryWindow time.Duration) *aws.CredentialsCache {
return aws.NewCredentialsCache(provider, func(options *aws.CredentialsCacheOptions) {
options.ExpiryWindow = expiryWindow
})
}
// SafeStringValue dereferences a string pointer using aws.ToString with a fallback.
func SafeStringValue(val *string, fallback string) string {
res := aws.ToString(val)
if res == "" {
return fallback
}
return res
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/aws/aws-sdk-go-v2@v1.47.3"
]
}
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"sample"
)
func main() {
if err := runTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All AWS SDK Go v2 contract tests passed successfully.")
}
func runTests() error {
ctx := context.Background()
// 1. aws.NewConfig returns an initialized Config and Copy produces an independent shallow copy
{
cfg := aws.NewConfig()
if cfg == nil {
return fmt.Errorf("expected non-nil Config from aws.NewConfig")
}
cfg.Region = "us-east-1"
holder, err := sample.NewClientConfigHolder("us-west-2", nil)
if err != nil {
return fmt.Errorf("unexpected error creating ClientConfigHolder: %w", err)
}
if holder.Config.Region != "us-west-2" {
return fmt.Errorf("expected region us-west-2, got %q", holder.Config.Region)
}
copied := holder.Config.Copy()
if copied.Region != "us-west-2" {
return fmt.Errorf("expected copied region to be us-west-2, got %q", copied.Region)
}
}
// 2. aws.String and aws.ToString correctly convert between string values and pointers with safe nil handling
{
ptr := aws.String("example-endpoint")
if ptr == nil || *ptr != "example-endpoint" {
return fmt.Errorf("expected valid pointer from aws.String")
}
val := aws.ToString(ptr)
if val != "example-endpoint" {
return fmt.Errorf("expected 'example-endpoint' from aws.ToString, got %q", val)
}
nilVal := aws.ToString(nil)
if nilVal != "" {
return fmt.Errorf("expected empty string from aws.ToString(nil), got %q", nilVal)
}
fallback := sample.SafeStringValue(nil, "default-val")
if fallback != "default-val" {
return fmt.Errorf("expected fallback value, got %q", fallback)
}
}
// 3. aws.CredentialsProviderFunc wraps a function satisfying CredentialsProvider interface and retrieves credentials
{
staticProvider := sample.CreateStaticCredentialsProvider("test-access-key", "test-secret-key", "test-session-token")
creds, err := staticProvider.Retrieve(ctx)
if err != nil {
return fmt.Errorf("unexpected error retrieving credentials: %w", err)
}
if creds.AccessKeyID != "test-access-key" || creds.SecretAccessKey != "test-secret-key" {
return fmt.Errorf("credentials fields mismatch: %+v", creds)
}
if !creds.HasKeys() {
return fmt.Errorf("expected creds.HasKeys() to be true")
}
}
// 4. aws.NewCredentialsCache caches credentials and delegates retrieval to underlying provider
{
callCount := 0
customProvider := aws.CredentialsProviderFunc(func(c context.Context) (aws.Credentials, error) {
callCount++
return aws.Credentials{
AccessKeyID: fmt.Sprintf("key-%d", callCount),
SecretAccessKey: "secret-data",
CanExpire: true,
Expires: time.Now().Add(10 * time.Minute),
}, nil
})
cache := sample.CreateCachedCredentialsProvider(customProvider, 10*time.Second)
if cache == nil {
return fmt.Errorf("expected non-nil CredentialsCache")
}
first, err := cache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("error in first Retrieve: %w", err)
}
if callCount != 1 {
return fmt.Errorf("expected callCount 1, got %d", callCount)
}
second, err := cache.Retrieve(ctx)
if err != nil {
return fmt.Errorf("error in second Retrieve: %w", err)
}
if callCount != 1 {
return fmt.Errorf("expected cached callCount to remain 1, got %d", callCount)
}
if second.AccessKeyID != first.AccessKeyID {
return fmt.Errorf("expected cached credentials to match")
}
}
// 5. aws.AnonymousCredentials returns sentinel credentials and reports expected retrieval error
{
anon := aws.AnonymousCredentials{}
creds, err := anon.Retrieve(ctx)
if err == nil {
return fmt.Errorf("expected error from AnonymousCredentials.Retrieve")
}
if creds.Source != "AnonymousCredentials" {
return fmt.Errorf("expected Source AnonymousCredentials, got %q", creds.Source)
}
}
return nil
}
オリジンシーダー
匿名