-
Notifications
You must be signed in to change notification settings - Fork 564
redefine IoT Core custom authorizer request and response structs #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56107fd
389713b
e518605
6e68d8a
ac94a86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package events | ||
|
||
// IAMPolicyDocument represents an IAM policy document. | ||
type IAMPolicyDocument struct { | ||
Version string | ||
Statement []IAMPolicyStatement | ||
} | ||
|
||
// IAMPolicyStatement represents one statement from IAM policy with action, effect and resource. | ||
type IAMPolicyStatement struct { | ||
Action []string | ||
Effect string | ||
Resource []string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
package events | ||
|
||
// IoTCustomAuthorizerRequest contains data coming in to a custom IoT device gateway authorizer function. | ||
type IoTCustomAuthorizerRequest struct { | ||
HTTPContext *IoTHTTPContext `json:"httpContext,omitempty"` | ||
MQTTContext *IoTMQTTContext `json:"mqttContext,omitempty"` | ||
TLSContext *IoTTLSContext `json:"tlsContext,omitempty"` | ||
AuthorizationToken string `json:"token"` | ||
TokenSignature string `json:"tokenSignature"` | ||
// IoTCoreCustomAuthorizerRequest represents the request to an IoT Core custom authorizer. | ||
// See https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html | ||
type IoTCoreCustomAuthorizerRequest struct { | ||
Token string `json:"token"` | ||
SignatureVerified bool `json:"signatureVerified"` | ||
Protocols []string `json:"protocols"` | ||
ProtocolData *IoTCoreProtocolData `json:"protocolData,omitempty"` | ||
ConnectionMetadata *IoTCoreConnectionMetadata `json:"connectionMetadata,omitempty"` | ||
} | ||
|
||
type IoTHTTPContext struct { | ||
type IoTCoreProtocolData struct { | ||
TLS *IoTCoreTLSContext `json:"tls,omitempty"` | ||
HTTP *IoTCoreHTTPContext `json:"http,omitempty"` | ||
MQTT *IoTCoreMQTTContext `json:"mqtt,omitempty"` | ||
} | ||
|
||
type IoTCoreTLSContext struct { | ||
ServerName string `json:"serverName"` | ||
} | ||
|
||
type IoTCoreHTTPContext struct { | ||
Headers map[string]string `json:"headers,omitempty"` | ||
QueryString string `json:"queryString"` | ||
} | ||
|
||
type IoTMQTTContext struct { | ||
type IoTCoreMQTTContext struct { | ||
ClientID string `json:"clientId"` | ||
Password []byte `json:"password"` | ||
Username string `json:"username"` | ||
} | ||
|
||
type IoTTLSContext struct { | ||
ServerName string `json:"serverName"` | ||
type IoTCoreConnectionMetadata struct { | ||
ID string `json:"id"` | ||
} | ||
|
||
// IoTCustomAuthorizerResponse represents the expected format of an IoT device gateway authorization response. | ||
type IoTCustomAuthorizerResponse struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the rename. To keep strict compile time backwards compatibility, I'd like for the old types to be left in the project too. They can have a comment like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not put loadbearing invariants in comments please, as they are easy to overlook. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bmoffatt Is it really necessary to keep the original struct? No one could be using it in practice since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I wanna keep the old ones, type changes and deletions are breaking changes. This isn't the first time things have been gotten wrong, and so far this project has not respond to that by deleting code. I'm not satisfied with incorrect models hanging around either, and i'd like to try and solve that holistically rather than making possibly inconsistent actions on a case-by-case basis
The guidance comes from https://go.dev/blog/godoc
My IDE renders these with a helpful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Really I think this library should have made a separate module for each service. That way clients can just include the events they need rather than using a single ever-growing events package. This would also reduce some of the repetition in the typedefs (e.g., For example in this situation we could have just made a new major rev of the IoT Core events module rather than having to (ultimately pointlessly) maintain backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I think it highlights some obvious shortcomings of the approach this library went with. I'll forward this on to the product team. The approach you described is actually how it was just before the initial public release. The monolithic |
||
IsAuthenticated bool `json:"isAuthenticated"` | ||
PrincipalID string `json:"principalId"` | ||
DisconnectAfterInSeconds int32 `json:"disconnectAfterInSeconds"` | ||
RefreshAfterInSeconds int32 `json:"refreshAfterInSeconds"` | ||
PolicyDocuments []string `json:"policyDocuments"` | ||
// IoTCoreCustomAuthorizerResponse represents the response from an IoT Core custom authorizer. | ||
// See https://docs.aws.amazon.com/iot/latest/developerguide/config-custom-auth.html | ||
type IoTCoreCustomAuthorizerResponse struct { | ||
IsAuthenticated bool `json:"isAuthenticated"` | ||
PrincipalID string `json:"principalId"` | ||
DisconnectAfterInSeconds uint32 `json:"disconnectAfterInSeconds"` | ||
RefreshAfterInSeconds uint32 `json:"refreshAfterInSeconds"` | ||
PolicyDocuments []*IAMPolicyDocument `json:"policyDocuments"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package events | ||
|
||
// IoTCustomAuthorizerRequest contains data coming in to a custom IoT device gateway authorizer function. | ||
// Deprecated: Use IoTCoreCustomAuthorizerRequest instead. IoTCustomAuthorizerRequest does not correctly model the request schema | ||
type IoTCustomAuthorizerRequest struct { | ||
HTTPContext *IoTHTTPContext `json:"httpContext,omitempty"` | ||
MQTTContext *IoTMQTTContext `json:"mqttContext,omitempty"` | ||
TLSContext *IoTTLSContext `json:"tlsContext,omitempty"` | ||
AuthorizationToken string `json:"token"` | ||
TokenSignature string `json:"tokenSignature"` | ||
} | ||
|
||
// Deprecated: Use IoTCoreHTTPContext | ||
type IoTHTTPContext IoTCoreHTTPContext | ||
|
||
// Deprecated: Use IoTCoreMQTTContext | ||
type IoTMQTTContext IoTCoreMQTTContext | ||
|
||
// Deprecated: Use IotCoreTLSContext | ||
type IoTTLSContext IoTCoreTLSContext | ||
|
||
// IoTCustomAuthorizerResponse represents the expected format of an IoT device gateway authorization response. | ||
// Deprecated: Use IoTCoreCustomAuthorizerResponse. IoTCustomAuthorizerResponse does not correctly model the response schema. | ||
type IoTCustomAuthorizerResponse struct { | ||
IsAuthenticated bool `json:"isAuthenticated"` | ||
PrincipalID string `json:"principalId"` | ||
DisconnectAfterInSeconds int32 `json:"disconnectAfterInSeconds"` | ||
RefreshAfterInSeconds int32 `json:"refreshAfterInSeconds"` | ||
PolicyDocuments []string `json:"policyDocuments"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
{ | ||
"httpContext": { | ||
"headers": { | ||
"Accept-Language" : "en" | ||
"token" :"aToken", | ||
"signatureVerified": true, | ||
"protocols": ["tls", "http", "mqtt"], | ||
"protocolData": { | ||
"tls" : { | ||
"serverName": "serverName" | ||
}, | ||
"queryString": "abc" | ||
}, | ||
"mqttContext": { | ||
"clientId": "someclient", | ||
"password": "aslkfjwoeiuwekrujwlrueowieurowieurowiuerwleuroiwueroiwueroiuweoriuweoriuwoeiruwoeiur", | ||
"username": "thebestuser" | ||
}, | ||
"tlsContext": { | ||
"serverName": "server.stuff.com" | ||
"http": { | ||
"headers": { | ||
"X-Request-ID": "abc123" | ||
}, | ||
"queryString": "?foo=bar" | ||
}, | ||
"mqtt": { | ||
"username": "myUserName", | ||
"password": "bXlQYXNzd29yZA==", | ||
"clientId": "myClientId" | ||
} | ||
}, | ||
"token": "someToken", | ||
"tokenSignature": "somelongtokensignature" | ||
} | ||
"connectionMetadata": { | ||
"id": "e56f08c3-c559-490f-aa9f-7e8427d0f57b" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep backcompat, I believe this would need to be a type alias. eg: write as
type APIGatewayCustomAuthorizerPolicy = IAMPolicyDocument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not necessary for backwards compatibility.
type A B
makes A a copy of B (same struct fields), they just are not equivalent/interchangeable.type A = B
makes A an alias of B, meaning they are interchangeable (e.g.,type byte = uint8
). Unless you want clients to be able to use anAPIGatewayCustomAuthorizerPolicy
wherever anIAMPolicyDocument
is expected without casting, there is no need for an alias.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my brain read the diff as having
APIGatewayCustomAuthorizerResponse
also being updated to use IAMPolicyDocument for it'sPolicyDocument
field, which would have broken something likex.PolicyDocument = APIGatewayCustomAuthorizerPolicy{}
(see: https://play.golang.org/p/_OXhN9ebJ1K). I see now thatAPIGatewayCustomAuthorizerResponse
wasn't updated. I can't tell if that was intentional or not?If you think that
APIGatewayCustomAuthorizerResponse
shouldn't be updated, then lets remove the//Deprecated:
comment, as it's use ofAPIGatewayCustomAuthorizerPolicy
would still be correct in that contextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "deprecated" comment was directed more at API developers (to tell them not to use it in new structs), not API clients.
I had not intended to make changes to
APIGatewayCustomAuthorizerResponse
but I can do that if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to just drop the comment so that no one's linter freaks out. DRYing the rest api gateway type feels out of scope to me for this PR