Skip to content

Commit ee046fa

Browse files
committed
add instance identity endpoint
1 parent 3e2df8f commit ee046fa

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

server.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ func (app *App) NewServer() {
3232
n.Handle("/macs", appHandler(app.macHandler))
3333
n.Handle("/macs/"+app.Hostname+"/vpc-id", appHandler(app.vpcHandler))
3434

35+
d := r.PathPrefix("/latest/dynamic/instance-identity").Subrouter()
36+
d.Handle("/document", appHandler(app.instanceIdentityHandler))
37+
3538
r.Handle("/{path:.*}", appHandler(app.notFoundHandler))
3639
s.Handle("/{path:.*}", appHandler(app.notFoundHandler))
3740
p.Handle("/{path:.*}", appHandler(app.notFoundHandler))
@@ -112,6 +115,46 @@ type Credentials struct {
112115
Expiration string
113116
}
114117

118+
type InstanceIdentityDocument struct {
119+
AvailabilityZone string `json:"availabilityZone"`
120+
Region string `json:"region"`
121+
DevpayProductCodes *string `json:"devpayProductCodes"`
122+
PrivateIp string `json:"privateIp"`
123+
Version string `json:"version"`
124+
InstanceId string `json:"instanceId"`
125+
BillingProducts *string `json:"billingProducts"`
126+
InstanceType string `json:"instanceType"`
127+
AccountId string `json:"accountId"`
128+
ImageId string `json:"imageId"`
129+
PendingTime string `json:"pendingTime"`
130+
Architecture string `json:"architecture"`
131+
KernelId *string `json:"kernelId"`
132+
RamdiskId *string `json:"ramdiskId"`
133+
}
134+
135+
func (app *App) instanceIdentityHandler(w http.ResponseWriter, r *http.Request) {
136+
document := InstanceIdentityDocument{
137+
AvailabilityZone: app.AvailabilityZone,
138+
Region: app.AvailabilityZone[:len(app.AvailabilityZone)-1],
139+
DevpayProductCodes: nil,
140+
PrivateIp: "127.0.0.1",
141+
Version: "2010-08-31",
142+
InstanceId: "i-wxyz1234",
143+
BillingProducts: nil,
144+
InstanceType: "t2.micro",
145+
AccountId: "1234567890",
146+
ImageId: "ami-123456",
147+
PendingTime: "2016-04-15T12:14:15Z",
148+
Architecture: "x86_64",
149+
KernelId: nil,
150+
RamdiskId: nil,
151+
}
152+
if err := json.NewEncoder(w).Encode(document); err != nil {
153+
log.Errorf("Error sending json %+v", err)
154+
http.Error(w, err.Error(), 500)
155+
}
156+
}
157+
115158
func (app *App) roleHandler(w http.ResponseWriter, r *http.Request) {
116159
svc := sts.New(session.New(), &aws.Config{LogLevel: aws.LogLevel(2)})
117160
resp, err := svc.AssumeRole(&sts.AssumeRoleInput{

0 commit comments

Comments
 (0)