@@ -104,7 +104,6 @@ def LakeOptions.computeEnv (opts : LakeOptions) : EIO CliError Lake.Env := do
104104 Env.compute (← opts.getLakeInstall) (← opts.getLeanInstall) opts.elanInstall?
105105 opts.noCache |>.adapt fun msg => .invalidEnv msg
106106
107- /-- Make a `LoadConfig` from a `LakeOptions`. -/
108107def LakeOptions.mkLoadConfigCore
109108 (opts : LakeOptions) (wsDir : FilePath) (lakeEnv : Lake.Env) (lakeConfig : LakeConfig)
110109: LoadConfig where
@@ -120,7 +119,6 @@ def LakeOptions.mkLoadConfigCore
120119 updateDeps := opts.updateDeps
121120 updateToolchain := opts.updateToolchain
122121
123- /-- Make a `LoadConfig` from a `LakeOptions`. -/
124122def LakeOptions.mkLoadConfig' (opts : LakeOptions) : LogIO LoadConfig := do
125123 let some wsDir ← resolvePath? opts.rootDir
126124 | error <| toString <| CliError.missingRootDir opts.rootDir
@@ -399,6 +397,14 @@ namespace lake
399397
400398namespace cache
401399
400+ def serviceNotFound (service : String) (configuredServices : Array CacheService) : String :=
401+ let msg := s! "service `{ service} ` not found in system configuration"
402+ if configuredServices.isEmpty then
403+ s! "{ msg} ; no services configured"
404+ else
405+ let msg := s! "{ msg} ; configured services:\n "
406+ configuredServices.foldl (· ++ s! " { ·.name?} " ) msg
407+
402408@[inline] private def cacheToolchain (pkg : Package) (toolchain : String) : String :=
403409 if pkg.bootstrap then "" else toolchain
404410
@@ -431,15 +437,20 @@ protected def get : CliM PUnit := do
431437 let platform := opts.platform?.getD System.Platform.target
432438 let toolchain := opts.toolchain?.getD ws.lakeEnv.toolchain
433439 let service : CacheService ← id do
434- match ws.lakeEnv.cacheArtifactEndpoint?, ws.lakeEnv.cacheRevisionEndpoint? with
435- | some artifactEndpoint, some revisionEndpoint =>
436- return .downloadService artifactEndpoint revisionEndpoint ws.lakeEnv.cacheService?
437- | none, none =>
438- return .reservoirService ws.lakeEnv.reservoirApiUrl
439- | some artifactEndpoint, none =>
440- error (invalidEndpointConfig artifactEndpoint "" )
441- | none, some revisionEndpoint =>
442- error (invalidEndpointConfig "" revisionEndpoint)
440+ if let some service := opts.service? then
441+ let some service := ws.lakeConfig.cache.services.find? (·.name? == some service)
442+ | error (serviceNotFound service ws.lakeConfig.cache.services)
443+ return service
444+ else
445+ match ws.lakeEnv.cacheArtifactEndpoint?, ws.lakeEnv.cacheRevisionEndpoint? with
446+ | some artifactEndpoint, some revisionEndpoint =>
447+ return .downloadService artifactEndpoint revisionEndpoint ws.lakeEnv.cacheService?
448+ | none, none =>
449+ return .reservoirService ws.lakeEnv.reservoirApiUrl
450+ | some artifactEndpoint, none =>
451+ error (invalidEndpointConfig artifactEndpoint "" )
452+ | none, some revisionEndpoint =>
453+ error (invalidEndpointConfig "" revisionEndpoint)
443454 if let some remoteScope := opts.scope? then
444455 if !opts.repoScope && service.isReservoir then
445456 -- `--scope` with Reservoir would imply downloading artifacts for a different package.
@@ -516,11 +527,18 @@ protected def put : CliM PUnit := do
516527 let platform := cachePlatform pkg (opts.platform?.getD System.Platform.target)
517528 let toolchain := cacheToolchain pkg (opts.toolchain?.getD ws.lakeEnv.toolchain)
518529 let service : CacheService ← id do
519- match ws.lakeEnv.cacheKey?, ws.lakeEnv.cacheArtifactEndpoint?, ws.lakeEnv.cacheRevisionEndpoint? with
520- | some key, some artifactEndpoint, some revisionEndpoint =>
521- return .uploadService key artifactEndpoint revisionEndpoint
522- | key?, artifactEndpoint?, revisionEndpoint? =>
523- error (invalidEndpointConfig key? artifactEndpoint? revisionEndpoint?)
530+ if let some service := opts.service? then
531+ let some service := ws.lakeConfig.cache.services.find? (·.name? == some service)
532+ | error (serviceNotFound service ws.lakeConfig.cache.services)
533+ let some key := ws.lakeEnv.cacheKey?
534+ | error "uploads require an authentication key configured through `LAKE_CACHE_KEY`"
535+ return service.withKey key
536+ else
537+ match ws.lakeEnv.cacheKey?, ws.lakeEnv.cacheArtifactEndpoint?, ws.lakeEnv.cacheRevisionEndpoint? with
538+ | some key, some artifactEndpoint, some revisionEndpoint =>
539+ return .uploadService key artifactEndpoint revisionEndpoint
540+ | key?, artifactEndpoint?, revisionEndpoint? =>
541+ error (invalidEndpointConfig key? artifactEndpoint? revisionEndpoint?)
524542 let service := service.withRepoScope opts.repoScope
525543 let repo := GitRepo.mk pkg.dir
526544 if (← repo.hasDiff) then
0 commit comments