Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onetime headers #136

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/Momento/internal/ControlClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Logging
@available(macOS 10.15, iOS 13, *)
protocol ControlClientProtocol {
func createCache(cacheName: String) async -> CreateCacheResponse

func deleteCache(cacheName: String) async -> DeleteCacheResponse

func listCaches() async -> ListCachesResponse

func close()
Expand All @@ -23,15 +23,15 @@ class ControlClient: ControlClientProtocol {
private let eventLoopGroup = PlatformSupport.makeEventLoopGroup(loopCount: 1)
private let client: ControlClient_ScsControlNIOClient
private var firstRequest = true

init(
configuration: CacheClientConfigurationProtocol,
credentialProvider: CredentialProviderProtocol
) {
self.configuration = configuration
self.credentialProvider = credentialProvider
self.logger = Logger(label: "CacheControlClient")

do {
self.grpcChannel = try GRPCChannelPool.with(
target: .host(credentialProvider.controlEndpoint, port: 443),
Expand All @@ -50,7 +50,7 @@ class ControlClient: ControlClientProtocol {
} catch {
fatalError("Failed to open GRPC channel")
}

self.client = ControlClient_ScsControlNIOClient(
channel: self.grpcChannel,
defaultCallOptions: .init(
Expand All @@ -59,15 +59,15 @@ class ControlClient: ControlClientProtocol {
interceptors: ControlClientInterceptorFactory(apiKey: credentialProvider.apiKey)
)
}

func makeHeaders() -> [String:String] {
let headers = constructHeaders(firstRequest: self.firstRequest)
let headers = constructHeaders(firstRequest: self.firstRequest, clientType: "cache")
if self.firstRequest {
self.firstRequest = false
}
return headers
}

func createCache(cacheName: String) async -> CreateCacheResponse {
var request = ControlClient__CreateCacheRequest()
request.cacheName = cacheName
Expand Down Expand Up @@ -95,7 +95,7 @@ class ControlClient: ControlClientProtocol {
)
}
}

func deleteCache(cacheName: String) async -> DeleteCacheResponse {
var request = ControlClient__DeleteCacheRequest()
request.cacheName = cacheName
Expand All @@ -120,7 +120,7 @@ class ControlClient: ControlClientProtocol {
)
}
}

func listCaches() async -> ListCachesResponse {
let call = self.client.listCaches(ControlClient__ListCachesRequest(), callOptions: .init(
customMetadata: .init(makeHeaders().map { ($0, $1) })
Expand Down
Loading
Loading