From 035ce7e64dc0d1987dc0a55315c701492f32662d Mon Sep 17 00:00:00 2001 From: Konrad Markus Date: Mon, 24 Aug 2020 15:25:15 +0300 Subject: [PATCH] WIP --- maas-schemas-ts/package.json | 7 +- maas-schemas-ts/src/aws/s3/event.ts | 158 ++++++++++++++++++ maas-schemas-ts/src/aws/sns/notification.ts | 71 ++++++++ maas-schemas-ts/src/core/components/units.ts | 14 ++ maas-schemas-ts/translation.log | 54 ++++++ maas-schemas/package.json | 10 +- maas-schemas/schemas/aws/s3/s3-event.json | 130 ++++++++++++++ .../schemas/aws/sns/sns-notification.json | 40 +++++ .../schemas/core/components/units.json | 5 + 9 files changed, 484 insertions(+), 5 deletions(-) create mode 100644 maas-schemas-ts/src/aws/s3/event.ts create mode 100644 maas-schemas-ts/src/aws/sns/notification.ts create mode 100644 maas-schemas/schemas/aws/s3/s3-event.json create mode 100644 maas-schemas/schemas/aws/sns/sns-notification.json diff --git a/maas-schemas-ts/package.json b/maas-schemas-ts/package.json index 5a05cde70..3ae4da57e 100644 --- a/maas-schemas-ts/package.json +++ b/maas-schemas-ts/package.json @@ -1,6 +1,9 @@ { - "name": "maas-schemas-ts", - "version": "14.5.3", + "name": "@maasglobal/maas-schemas-ts", + "publishConfig": { + "registry": "https://npm.deployment.maas.global/repository/npm-maas/" + }, + "version": "14.6.0-rc2", "description": "TypeScript types and io-ts validators for maas-schemas", "main": "index.js", "files": [ diff --git a/maas-schemas-ts/src/aws/s3/event.ts b/maas-schemas-ts/src/aws/s3/event.ts new file mode 100644 index 000000000..e0f5f7c3d --- /dev/null +++ b/maas-schemas-ts/src/aws/s3/event.ts @@ -0,0 +1,158 @@ +/* + +undefined +AWS S3 Event JSON Payload + +!!! AUTO GENERATED BY IOTSFJS REFRAIN FROM MANUAL EDITING !!! +See https://www.npmjs.com/package/io-ts-from-json-schema + +*/ + +import * as t from 'io-ts'; +import * as Units_ from '../../core/components/units'; + +export const schemaId = 'http://maasglobal.com/aws/s3/event.json'; + +// S3Event +// The default export. More information at the top. +export type S3Event = t.Branded< + { + eventVersion?: number; + eventSource?: string & 'aws:s3'; + awsRegion?: string; + eventTime?: Units_.IsoDateTime; + eventName?: unknown; + userIdentity?: { + principalId?: string; + }; + requestParameters?: { + sourceIPAddress?: string; + }; + responseElements?: { + 'x-amz-request-id'?: string; + 'x-amz-id-2'?: string; + }; + s3?: { + s3SchemaVersion?: number; + configurationId?: string; + bucket?: { + name?: string; + ownerIdentity?: { + principalId?: string; + }; + arn?: Units_.Arn; + }; + object?: { + key?: string; + size?: number; + eTag?: string; + versionId?: string; + sequencer?: string; + }; + }; + glacierEventData?: { + restoreEventData?: { + lifecycleRestorationExpiryTime?: Units_.IsoDateTime; + lifecycleRestoreStorageClass?: string; + }; + }; + }, + S3EventBrand +>; +export const S3Event = t.brand( + t.partial({ + eventVersion: t.number, + eventSource: t.intersection([t.string, t.literal('aws:s3')]), + awsRegion: t.string, + eventTime: Units_.IsoDateTime, + eventName: t.unknown, + userIdentity: t.partial({ + principalId: t.string, + }), + requestParameters: t.partial({ + sourceIPAddress: t.string, + }), + responseElements: t.partial({ + 'x-amz-request-id': t.string, + 'x-amz-id-2': t.string, + }), + s3: t.partial({ + s3SchemaVersion: t.number, + configurationId: t.string, + bucket: t.partial({ + name: t.string, + ownerIdentity: t.partial({ + principalId: t.string, + }), + arn: Units_.Arn, + }), + object: t.partial({ + key: t.string, + size: t.number, + eTag: t.string, + versionId: t.string, + sequencer: t.string, + }), + }), + glacierEventData: t.partial({ + restoreEventData: t.partial({ + lifecycleRestorationExpiryTime: Units_.IsoDateTime, + lifecycleRestoreStorageClass: t.string, + }), + }), + }), + ( + x, + ): x is t.Branded< + { + eventVersion?: number; + eventSource?: string & 'aws:s3'; + awsRegion?: string; + eventTime?: Units_.IsoDateTime; + eventName?: unknown; + userIdentity?: { + principalId?: string; + }; + requestParameters?: { + sourceIPAddress?: string; + }; + responseElements?: { + 'x-amz-request-id'?: string; + 'x-amz-id-2'?: string; + }; + s3?: { + s3SchemaVersion?: number; + configurationId?: string; + bucket?: { + name?: string; + ownerIdentity?: { + principalId?: string; + }; + arn?: Units_.Arn; + }; + object?: { + key?: string; + size?: number; + eTag?: string; + versionId?: string; + sequencer?: string; + }; + }; + glacierEventData?: { + restoreEventData?: { + lifecycleRestorationExpiryTime?: Units_.IsoDateTime; + lifecycleRestoreStorageClass?: string; + }; + }; + }, + S3EventBrand + > => true, + 'S3Event', +); +export interface S3EventBrand { + readonly S3Event: unique symbol; +} + +export default S3Event; + +// Success diff --git a/maas-schemas-ts/src/aws/sns/notification.ts b/maas-schemas-ts/src/aws/sns/notification.ts new file mode 100644 index 000000000..987b324f6 --- /dev/null +++ b/maas-schemas-ts/src/aws/sns/notification.ts @@ -0,0 +1,71 @@ +/* + +undefined +AWS SNS Notification JSON Payload + +!!! AUTO GENERATED BY IOTSFJS REFRAIN FROM MANUAL EDITING !!! +See https://www.npmjs.com/package/io-ts-from-json-schema + +*/ + +import * as t from 'io-ts'; +import * as Units_ from '../../core/components/units'; + +export const schemaId = 'http://maasglobal.com/aws/sns/notification.json'; + +// SnsNotification +// The default export. More information at the top. +export type SnsNotification = t.Branded< + { + Type?: string & 'Notification'; + MessageId?: Units_.Uuid; + TopicArn?: Units_.Arn; + Subject?: string; + Message?: string; + Timestamp?: Units_.IsoDateTime; + SignatureVersion?: number; + Signature?: string; + SigningCertURL?: Units_.Url; + UnsubscribeURL?: Units_.Url; + }, + SnsNotificationBrand +>; +export const SnsNotification = t.brand( + t.partial({ + Type: t.intersection([t.string, t.literal('Notification')]), + MessageId: Units_.Uuid, + TopicArn: Units_.Arn, + Subject: t.string, + Message: t.string, + Timestamp: Units_.IsoDateTime, + SignatureVersion: t.number, + Signature: t.string, + SigningCertURL: Units_.Url, + UnsubscribeURL: Units_.Url, + }), + ( + x, + ): x is t.Branded< + { + Type?: string & 'Notification'; + MessageId?: Units_.Uuid; + TopicArn?: Units_.Arn; + Subject?: string; + Message?: string; + Timestamp?: Units_.IsoDateTime; + SignatureVersion?: number; + Signature?: string; + SigningCertURL?: Units_.Url; + UnsubscribeURL?: Units_.Url; + }, + SnsNotificationBrand + > => true, + 'SnsNotification', +); +export interface SnsNotificationBrand { + readonly SnsNotification: unique symbol; +} + +export default SnsNotification; + +// Success diff --git a/maas-schemas-ts/src/core/components/units.ts b/maas-schemas-ts/src/core/components/units.ts index fb0b14fd9..79987ae31 100644 --- a/maas-schemas-ts/src/core/components/units.ts +++ b/maas-schemas-ts/src/core/components/units.ts @@ -219,6 +219,20 @@ export interface IsoDateBrand { readonly IsoDate: unique symbol; } +// IsoDateTime +// A date in the form YYYY-MM-DDTHH:MM:SS.mmmZ +export type IsoDateTime = t.Branded; +export const IsoDateTime = t.brand( + t.string, + (x): x is t.Branded => + typeof x !== 'string' || + x.match(RegExp('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z')) !== null, + 'IsoDateTime', +); +export interface IsoDateTimeBrand { + readonly IsoDateTime: unique symbol; +} + // Units // The default export. More information at the top. export type Units = t.Branded; diff --git a/maas-schemas-ts/translation.log b/maas-schemas-ts/translation.log index 9f9f247ce..ffc41eec6 100644 --- a/maas-schemas-ts/translation.log +++ b/maas-schemas-ts/translation.log @@ -1,3 +1,57 @@ +INFO: primitive type "number" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +WARNING: pattern field not supported outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +WARNING: pattern field not supported outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "number" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +WARNING: pattern field not supported outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +WARNING: pattern field not supported outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "number" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/s3/s3-event.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json +INFO: primitive type "integer" used outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json +WARNING: minimum field not supported outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json +INFO: primitive type "string" used outside top-level definitions + in ../maas-schemas/schemas/aws/sns/sns-notification.json WARNING: skipping examples handling for $ref object in ../maas-schemas/schemas/core/booking.json WARNING: skipping default value handling for $ref object diff --git a/maas-schemas/package.json b/maas-schemas/package.json index 26e076b71..300826bcf 100644 --- a/maas-schemas/package.json +++ b/maas-schemas/package.json @@ -1,6 +1,9 @@ { - "name": "maas-schemas", - "version": "14.5.3", + "name": "@maasglobal/maas-schemas", + "publishConfig": { + "registry": "https://npm.deployment.maas.global/repository/npm-maas/" + }, + "version": "14.6.0-rc2", "description": "Schemas for MaaS infrastructure", "main": "index.js", "engine": { @@ -19,7 +22,8 @@ "contributors": [ "James Nguyen", "Klaus Dahlen", - "Lauri Svan" + "Lauri Svan", + "Konrad Markus" ], "license": "MIT", "bugs": { diff --git a/maas-schemas/schemas/aws/s3/s3-event.json b/maas-schemas/schemas/aws/s3/s3-event.json new file mode 100644 index 000000000..911630667 --- /dev/null +++ b/maas-schemas/schemas/aws/s3/s3-event.json @@ -0,0 +1,130 @@ +{ + "$id": "http://maasglobal.com/aws/s3/event.json", + "description": "AWS S3 Event JSON Payload", + "type": "object", + "properties": { + "eventVersion": { + "type": "number" + }, + "eventSource": { + "type": "string", + "const": "aws:s3" + }, + "awsRegion": { + "type": "string", + "pattern": "[\\w\\-]+" + }, + "eventTime": { + "description": "The time when Amazon S3 finished processing the request", + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/isoDateTime" + }, + "eventName": { + "description": "Event type, see: https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations" + }, + "userIdentity": { + "type": "object", + "properties": { + "principalId": { + "type": "string", + "description": "Amazon customer ID of the user who caused the event", + "pattern": "\\w+" + } + } + }, + "requestParameters": { + "type": "object", + "properties": { + "sourceIPAddress": { + "description": "IP address where request came from", + "type": "string" + } + } + }, + "responseElements": { + "type": "object", + "properties": { + "x-amz-request-id": { + "description": "Amazon S3 generated request ID", + "type": "string" + }, + "x-amz-id-2": { + "description": "Amazon S3 host that processed the request", + "type": "string" + } + } + }, + "s3": { + "type": "object", + "properties": { + "s3SchemaVersion": { + "type": "number" + }, + "configurationId": { + "description": "ID found in the bucket notification configuration", + "type": "string" + }, + "bucket": { + "type": "object", + "properties": { + "name": { + "type": "string", + "pattern": "[\\w-]+" + }, + "ownerIdentity": { + "type": "object", + "properties": { + "principalId": { + "description": "Amazon customer ID of the bucket owner", + "type": "string", + "pattern": "\\w+" + } + } + }, + "arn": { + "description": "bucket ARN", + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/arn" + } + } + }, + "object": { + "type": "object", + "properties": { + "key": { + "type": "string" + }, + "size": { + "type": "number" + }, + "eTag": { "description": "object eTag", "type": "string" }, + "versionId": { + "description": "object version if bucket is versioning-enabled, otherwise null", + "type": "string" + }, + "sequencer": { + "description": "a string representation of a hexadecimal value used to determine event sequence, only used with PUTs and DELETEs", + "type": "string" + } + } + } + } + }, + "glacierEventData": { + "type": "object", + "properties": { + "restoreEventData": { + "type": "object", + "properties": { + "lifecycleRestorationExpiryTime": { + "description": "The time of Restore Expiry", + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/isoDateTime" + }, + "lifecycleRestoreStorageClass": { + "description": "Source storage class for restore", + "type": "string" + } + } + } + } + } + } +} diff --git a/maas-schemas/schemas/aws/sns/sns-notification.json b/maas-schemas/schemas/aws/sns/sns-notification.json new file mode 100644 index 000000000..00ea8d96a --- /dev/null +++ b/maas-schemas/schemas/aws/sns/sns-notification.json @@ -0,0 +1,40 @@ +{ + "$id": "http://maasglobal.com/aws/sns/notification.json", + "description": "AWS SNS Notification JSON Payload", + "type": "object", + "properties": { + "Type": { + "type": "string", + "const": "Notification" + }, + "MessageId": { + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/uuid" + }, + "TopicArn": { + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/arn" + }, + "Subject": { + "type": "string" + }, + "Message": { + "type": "string" + }, + "Timestamp": { + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/isoDateTime" + }, + "SignatureVersion": { + "type": "integer", + "minimum": 1 + }, + "Signature": { + "type": "string", + "description": "base64" + }, + "SigningCertURL": { + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/url" + }, + "UnsubscribeURL": { + "$ref": "http://maasglobal.com/core/components/units.json#/definitions/url" + } + } +} diff --git a/maas-schemas/schemas/core/components/units.json b/maas-schemas/schemas/core/components/units.json index 8f9ec51ce..e12a7dbf5 100644 --- a/maas-schemas/schemas/core/components/units.json +++ b/maas-schemas/schemas/core/components/units.json @@ -72,6 +72,11 @@ "description": "A date in the form YYYY-MM-DD without a time component", "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}" + }, + "isoDateTime": { + "description": "A date in the form YYYY-MM-DDTHH:MM:SS.mmmZ", + "type": "string", + "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z" } } }