Skip to content

Commit 9cf108a

Browse files
authored
Removed auth header w/ writekey; Added context.instanceId (#179)
* Removed auth header w/ writekey; Added context.instanceId * Fixed test.
1 parent 9c4cb9b commit 9cf108a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

Sources/Segment/Plugins/Context.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Context: PlatformPlugin {
1313

1414
internal var staticContext = staticContextData()
1515
internal static var device = VendorSystem.current
16+
internal let instanceId = UUID().uuidString
1617

1718
public func execute<T: RawEvent>(event: T?) -> T? {
1819
guard var workingEvent = event else { return event }
@@ -21,6 +22,9 @@ public class Context: PlatformPlugin {
2122

2223
insertDynamicPlatformContextData(context: &context)
2324

25+
// add instanceId to the context
26+
context["instanceId"] = instanceId
27+
2428
// if this event came in with context data already
2529
// let it take precedence over our values.
2630
if let eventContext = workingEvent.context?.dictionaryValue {
@@ -42,7 +46,7 @@ public class Context: PlatformPlugin {
4246
// library name
4347
staticContext["library"] = [
4448
"name": "analytics-swift",
45-
"version": __segment_version
49+
"version": __segment_version,
4650
]
4751

4852
// app info

Sources/Segment/Utilities/HTTPClient.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ extension HTTPClient {
157157
var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 60)
158158
request.httpMethod = method
159159
request.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
160-
request.addValue("Basic \(apiKey)", forHTTPHeaderField: "Authorization")
161160
request.addValue("analytics-ios/\(Analytics.version())", forHTTPHeaderField: "User-Agent")
162161
request.addValue("gzip", forHTTPHeaderField: "Accept-Encoding")
163162

Tests/Segment-Tests/Analytics_Tests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ final class Analytics_Tests: XCTestCase {
536536
let config = Configuration(writeKey: "testSequential").requestFactory { request in
537537
XCTAssertEqual(request.value(forHTTPHeaderField: "Accept-Encoding"), "gzip")
538538
XCTAssertEqual(request.value(forHTTPHeaderField: "Content-Type"), "application/json; charset=utf-8")
539-
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Basic testSequential")
540539
XCTAssertTrue(request.value(forHTTPHeaderField: "User-Agent")!.contains("analytics-ios/"))
541540
return request
542541
}.errorHandler { error in

0 commit comments

Comments
 (0)