the-sett / elm-aws-codegen

A code generator for AWS service stubs in Elm.
Apache License 2.0
1 stars 1 forks source link

Fix date type decoder #5

Open rupertlssmith opened 3 years ago

rupertlssmith commented 3 years ago

Based on the cognito service file the DateType is a timestamp which is internally represented as int (Unix secons) for AWSCognito, specifcally the expiration field of identity credentials

As per the the sdk code here, the timestamp can be iso string , date object or a unix timestamp

rupertlssmith commented 3 years ago

How can the result from AWS be a Date object? Is that just to cover some case where the sdk code has a Date object internally somehow? I am guessing that AWS services can either use ISO string timestamps, or int unix epoch timestamps.

A parser to be written that will parse ISO or Int, and convert to Inx or Posix.

What about when making requests to AWS? Do different services use different formats, or can all use ISO or int? In which case should I standardize on using int for all?

rupertlssmith commented 3 years ago

The possible values of the timestampFormat field are: iso8601, rfc822 and unixTimestamp, on the shape definition.

Most 'timestamp' shapes seem to no have a format field. Not sure yet if this means they default to a particular format.

rupertlssmith commented 3 years ago

This API call takes a timestamp as input:

https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#API_GetShardIterator_RequestSyntax

Shape is a "timestamp" but no "timestampFormat" is specified in the Spec. The actual value seems to be a number with the integer part giving the unix epoch, and milliseconds in the decimal places.

rupertlssmith commented 3 years ago

This one takes timestamps as the unix epoch in milliseconds, as an integer:

https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_FilterLogEvents.html

In this case the shape is not "timestamp" but "long".

rupertlssmith commented 3 years ago

I think these tests here give some information about what the various timestamp formats should be:

https://github.com/aws/aws-sdk-js/blob/307e82673b48577fce4389e4ce03f95064e8fe0d/test/model/shape.spec.js#L310

it('converts all header shapes to rfc822', function() {
it('converts all timestamps in JSON protocol to unixTimestamp', function() {
it('converts all timestamps in XML/query protocol to iso8601', function() {
aszenz commented 3 years ago

So as u said the aws api's use different time stamp formats, for encoding to wire a set of defaults are used depending on the wire protocol, similarly for decoding if the timestamp format is not present in the response then a default format is used depending on the wire data format.

Taking go sdk as example

XML

For xml it seems to be iso8601 as indicated by

JSON

For json it seems to be unix time as indicated by

Headers

For headers it's rfc822

Query parameters

iso8601

Timestamp tests: