From e94afdc0aa31e98b900a9cb333631391c90834b6 Mon Sep 17 00:00:00 2001 From: Carlos McEvilly <12955+carlosmcevilly@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:39:49 -0800 Subject: [PATCH] Feature/demrum 863 custom data module skeleton (#240) * DEMRUM-863: adding MRUMCustomData (will be: SplunkCustomData) module skeleton * DEMRUM-863: fix swiftlint issues other than TODOs * DEMRUM-863: Update naming to SplunkCustomData --- Splunk.xcworkspace/contents.xcworkspacedata | 3 + SplunkCustomData/.gitignore | 8 +++ .../xcschemes/SplunkCustomData.xcscheme | 66 +++++++++++++++++++ SplunkCustomData/Package.swift | 33 ++++++++++ .../SplunkCustomData/CustomData+Module.swift | 64 ++++++++++++++++++ .../Sources/SplunkCustomData/CustomData.swift | 46 +++++++++++++ .../CustomDataConfiguration.swift | 36 ++++++++++ .../CustomDataRemoteConfiguration.swift | 34 ++++++++++ .../EventMetadataCustomData.swift | 31 +++++++++ .../SplunkCustomDataTests.swift | 29 ++++++++ 10 files changed, 350 insertions(+) create mode 100644 SplunkCustomData/.gitignore create mode 100644 SplunkCustomData/.swiftpm/xcode/xcshareddata/xcschemes/SplunkCustomData.xcscheme create mode 100644 SplunkCustomData/Package.swift create mode 100644 SplunkCustomData/Sources/SplunkCustomData/CustomData+Module.swift create mode 100644 SplunkCustomData/Sources/SplunkCustomData/CustomData.swift create mode 100644 SplunkCustomData/Sources/SplunkCustomData/CustomDataConfiguration.swift create mode 100644 SplunkCustomData/Sources/SplunkCustomData/CustomDataRemoteConfiguration.swift create mode 100644 SplunkCustomData/Sources/SplunkCustomData/EventMetadataCustomData.swift create mode 100644 SplunkCustomData/Tests/SplunkCustomDataTests/SplunkCustomDataTests.swift diff --git a/Splunk.xcworkspace/contents.xcworkspacedata b/Splunk.xcworkspace/contents.xcworkspacedata index 90c549bd..467ef177 100644 --- a/Splunk.xcworkspace/contents.xcworkspacedata +++ b/Splunk.xcworkspace/contents.xcworkspacedata @@ -43,6 +43,9 @@ + + diff --git a/SplunkCustomData/.gitignore b/SplunkCustomData/.gitignore new file mode 100644 index 00000000..0023a534 --- /dev/null +++ b/SplunkCustomData/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/SplunkCustomData/.swiftpm/xcode/xcshareddata/xcschemes/SplunkCustomData.xcscheme b/SplunkCustomData/.swiftpm/xcode/xcshareddata/xcschemes/SplunkCustomData.xcscheme new file mode 100644 index 00000000..f92b1bca --- /dev/null +++ b/SplunkCustomData/.swiftpm/xcode/xcshareddata/xcschemes/SplunkCustomData.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SplunkCustomData/Package.swift b/SplunkCustomData/Package.swift new file mode 100644 index 00000000..80d26c52 --- /dev/null +++ b/SplunkCustomData/Package.swift @@ -0,0 +1,33 @@ +// swift-tools-version: 5.9 + +import PackageDescription + +let package = Package( + name: "SplunkCustomData", + platforms: [ + .iOS(.v13), + .tvOS(.v13), + .visionOS(.v1) + ], + products: [ + .library( + name: "SplunkCustomData", + targets: ["SplunkCustomData"] + ) + ], + dependencies: [ + .package(name: "SplunkSharedProtocols", path: "../SplunkSharedProtocols") + ], + targets: [ + .target( + name: "SplunkCustomData", + dependencies: [ + "SplunkSharedProtocols" + ] + ), + .testTarget( + name: "SplunkCustomDataTests", + dependencies: ["SplunkCustomData"] + ) + ] +) diff --git a/SplunkCustomData/Sources/SplunkCustomData/CustomData+Module.swift b/SplunkCustomData/Sources/SplunkCustomData/CustomData+Module.swift new file mode 100644 index 00000000..b2e709bd --- /dev/null +++ b/SplunkCustomData/Sources/SplunkCustomData/CustomData+Module.swift @@ -0,0 +1,64 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkSharedProtocols + +// `Data` can be used as an event type that the module produces. +extension Data: ModuleEventData {} + +// Struct `EventMetadataCustomData` describes event metadata. +// This type must be unique in the module/agent space. +extension EventMetadataCustomData: ModuleEventMetadata { + public static func == (lhs: EventMetadataCustomData, rhs: EventMetadataCustomData) -> Bool { + lhs.id == rhs.id + } +} + +// Defines CustomData conformance to `Module` protocol +// and implements methods that are missing in the original `CustomData`. +extension CustomData: Module { + + + // MARK: - Module types + + public typealias Configuration = CustomDataConfiguration + public typealias RemoteConfiguration = CustomDataRemoteConfiguration + + public typealias EventData = Data + + + // MARK: - Module methods + + public func install(with configuration: (any ModuleConfiguration)?, remoteConfiguration: (any RemoteModuleConfiguration)?) { + if let configuration = configuration as? CustomDataConfiguration { + print("known configuration") + print(configuration) + } + } + + + // MARK: - Type transparency helpers + + public func deleteData(for metadata: any ModuleEventMetadata) { + // TODO: Code TBD + } + + public func onPublish(data: @escaping (EventMetadataCustomData, EventData) -> Void) { + // TODO: Code TBD + } +} diff --git a/SplunkCustomData/Sources/SplunkCustomData/CustomData.swift b/SplunkCustomData/Sources/SplunkCustomData/CustomData.swift new file mode 100644 index 00000000..9bc5aa7b --- /dev/null +++ b/SplunkCustomData/Sources/SplunkCustomData/CustomData.swift @@ -0,0 +1,46 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkSharedProtocols + +protocol CustomDataRepresentable: PropertyList {} + +public final class CustomData { + + + // MARK: - Private properties + + private var config = CustomDataConfiguration(enabled: true) + + + // MARK: - CustomData lifecycle + + public required init() {} // see install() in Module extension for startup tasks + + + // MARK: - CustomData helper functions + + + // MARK: - CustomData Reporting + + // This is a placeholder for temporary use only. Will be replaced by + // real data population and output. + private func reportCustom(data: CustomDataRepresentable) { + print(String(describing: data)) + } +} diff --git a/SplunkCustomData/Sources/SplunkCustomData/CustomDataConfiguration.swift b/SplunkCustomData/Sources/SplunkCustomData/CustomDataConfiguration.swift new file mode 100644 index 00000000..9eda24f7 --- /dev/null +++ b/SplunkCustomData/Sources/SplunkCustomData/CustomDataConfiguration.swift @@ -0,0 +1,36 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkSharedProtocols + +public struct CustomDataConfiguration: ModuleConfiguration { + + + // MARK: - Public + + public var enabled: Bool + public var threshold: CFTimeInterval + + + // MARK: init() + + public init(enabled: Bool, threshold: CFTimeInterval = 2.0) { + self.enabled = enabled + self.threshold = threshold + } +} diff --git a/SplunkCustomData/Sources/SplunkCustomData/CustomDataRemoteConfiguration.swift b/SplunkCustomData/Sources/SplunkCustomData/CustomDataRemoteConfiguration.swift new file mode 100644 index 00000000..ef469cd3 --- /dev/null +++ b/SplunkCustomData/Sources/SplunkCustomData/CustomDataRemoteConfiguration.swift @@ -0,0 +1,34 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation +import SplunkSharedProtocols + +public struct CustomDataRemoteConfiguration: RemoteModuleConfiguration { + + + // MARK: - Public + + public var enabled: Bool + + + // MARK: init() + + public init?(from data: Data) { + enabled = true + } +} diff --git a/SplunkCustomData/Sources/SplunkCustomData/EventMetadataCustomData.swift b/SplunkCustomData/Sources/SplunkCustomData/EventMetadataCustomData.swift new file mode 100644 index 00000000..105a5525 --- /dev/null +++ b/SplunkCustomData/Sources/SplunkCustomData/EventMetadataCustomData.swift @@ -0,0 +1,31 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import Foundation + +public struct EventMetadataCustomData { + + + // MARK: - Public + + public var timestamp = Date() + + + // MARK: - Internal + + let id: String +} diff --git a/SplunkCustomData/Tests/SplunkCustomDataTests/SplunkCustomDataTests.swift b/SplunkCustomData/Tests/SplunkCustomDataTests/SplunkCustomDataTests.swift new file mode 100644 index 00000000..3b84bd8b --- /dev/null +++ b/SplunkCustomData/Tests/SplunkCustomDataTests/SplunkCustomDataTests.swift @@ -0,0 +1,29 @@ +// +/* +Copyright 2025 Splunk Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +@testable import SplunkCustomData +import XCTest + +final class SplunkCustomDataTests: XCTestCase { + func testExample() throws { + // XCTest Documentation + // https://developer.apple.com/documentation/xctest + + // Defining Test Cases and Test Methods + // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods + } +}