Skip to content

Commit

Permalink
unit test, files merge and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
renatoaguimaraes committed May 20, 2022
1 parent 29e275c commit 2eb6f63
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 103 deletions.
121 changes: 121 additions & 0 deletions Sources/AWSLambdaEvents/CloudFormation.swift
@@ -0,0 +1,121 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2017-2022 Apple Inc. and the SwiftAWSLambdaRuntime project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// CloudFormation custom resource.
public enum CloudFormation {
// Request represents the request body of AWS::CloudFormation::CustomResource.
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html
public struct Request<R: Decodable, O: Decodable>: Decodable {
public enum RequestType: String, Decodable {
case create = "Create"
case update = "Update"
case delete = "Delete"
}

let requestType: RequestType
let requestId: String
let responseURL: String
let physicalResourceId: String?
let logicalResourceId: String
let stackId: String
let resourceProperties: R
let oldResourceProperties: O?

enum CodingKeys : String, CodingKey {
case requestType = "RequestType"
case requestId = "RequestId"
case responseURL = "ResponseURL"
case physicalResourceId = "PhysicalResourceId"
case logicalResourceId = "LogicalResourceId"
case stackId = "StackId"
case resourceProperties = "ResourceProperties"
case oldResourceProperties = "OldResourceProperties"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.requestType = try container.decode(RequestType.self, forKey: .requestType)
self.requestId = try container.decode(String.self, forKey: .requestId)
self.responseURL = try container.decode(String.self, forKey: .responseURL)
self.logicalResourceId = try container.decode(String.self, forKey: .logicalResourceId)
self.stackId = try container.decode(String.self, forKey: .stackId)
self.physicalResourceId = try container.decodeIfPresent(String.self, forKey: .physicalResourceId)
self.resourceProperties = try container.decode(R.self, forKey: .resourceProperties)
self.oldResourceProperties = try container.decodeIfPresent(O.self, forKey: .oldResourceProperties)
}
}

// Response represents the response body of AWS::CloudFormation::CustomResource.
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html
public struct Response<D: Encodable>: Encodable {
public enum StatusType: String, Encodable {
case success = "SUCCESS"
case failed = "FAILED"
}

let status: StatusType
let requestId: String
let logicalResourceId: String
let stackId: String
let physicalResourceId: String?
let reason: String?
let noEcho: Bool?
let data: D?

enum CodingKeys : String, CodingKey {
case status = "Status"
case requestId = "RequestId"
case logicalResourceId = "LogicalResourceId"
case stackId = "StackId"
case physicalResourceId = "PhysicalResourceId"
case reason = "Reason"
case noEcho = "NoEcho"
case data = "Data"
}

public init(
status: StatusType,
requestId: String,
logicalResourceId: String,
stackId: String,
physicalResourceId: String?,
reason: String?,
noEcho: Bool?,
data: D?
) {
self.status = status
self.requestId = requestId
self.logicalResourceId = logicalResourceId
self.stackId = stackId
self.physicalResourceId = physicalResourceId
self.reason = reason
self.noEcho = noEcho
self.data = data
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(status.rawValue, forKey: .status)
try container.encode(requestId, forKey: .requestId)
try container.encode(logicalResourceId, forKey: .logicalResourceId)
try container.encode(stackId, forKey: .stackId)
try container.encodeIfPresent(physicalResourceId, forKey: .physicalResourceId)
try container.encodeIfPresent(reason, forKey: .reason)
try container.encodeIfPresent(noEcho, forKey: .noEcho)
try container.encodeIfPresent(data, forKey: .data)
}
}
}
42 changes: 0 additions & 42 deletions Sources/AWSLambdaEvents/CloudFormationRequest.swift

This file was deleted.

61 changes: 0 additions & 61 deletions Sources/AWSLambdaEvents/CloudFormationResponse.swift

This file was deleted.

0 comments on commit 2eb6f63

Please sign in to comment.