Skip to content

Commit

Permalink
rsc: Add client-server compatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
V-FEXrt committed Apr 26, 2024
1 parent ebc2d51 commit f2f6727
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
15 changes: 15 additions & 0 deletions rust/rsc/src/rsc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ async fn activate_stores(
return active_stores;
}

#[derive(serde::Deserialize)]
struct VersionCheck {
version: String,
}

async fn check_version(check: axum::extract::Query<VersionCheck>) -> axum::http::StatusCode {
println!("{:?}", check.version);
if check.version != "sifive/wake/41.1.1" {
return axum::http::StatusCode::FORBIDDEN;
}

return axum::http::StatusCode::OK;
}

fn create_router(
conn: Arc<DatabaseConnection>,
config: Arc<config::RSCConfig>,
Expand Down Expand Up @@ -186,6 +200,7 @@ fn create_router(
move || blob::get_upload_url(config.server_addr.clone())
}),
)
.route("/version/check", get(check_version))
}

async fn create_standalone_db() -> Result<DatabaseConnection, sea_orm::DbErr> {
Expand Down
36 changes: 35 additions & 1 deletion share/wake/lib/system/remote_cache_api.wake
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,24 @@ export def makeRemoteCacheApi (config: String): Result RemoteCacheApi Error =
def auth = if authStr ==* "" then None else Some authStr
def api = RemoteCacheApi domain port auth

# TODO: check for compatable wake version
# When in debug mode, allow server incompatible version.
def overrideOnDebugCache check =
require Fail err = check
else check

require Some _ = getenv "DEBUG_WAKE_SHARED_CACHE"
else check

printlnLevel
logWarning
"RSC client is incompatable with server but continuing due to DEBUG enabled. Reason: {format err}"
| Pass

# If the client isn't compatiable with the server then give up on the cache
require Pass Unit =
api
| rscApiCheckClientVersion "sifive/wake/{version}"
| overrideOnDebugCache

# If auth is not set we are done. Just return the api
require Some _ = auth
Expand Down Expand Up @@ -334,6 +351,23 @@ export def rscApiFindMatchingJob (req: CacheSearchRequest) (api: RemoteCacheApi)

mkCacheSearchResponse json

# rscApiCheckClientVersion: Checks if the client version is compatiable with the server.
#
# ```
# api | rscApiCheckClientVersion "sifive/wake/1.2.3 = Pass Unit
# ```
export def rscApiCheckClientVersion (version: String) (api: RemoteCacheApi): Result Unit Error =
require Pass response =
makeRoute api "version/check?version={version}"
| buildHttpRequest
| setMethod HttpMethodGet
| makeRequest

match response.getHttpResponseStatusCode
Some 200 -> Pass Unit
Some x -> failWithError "Incompatiable client. Status code: {str x}"
None -> failWithError "Incompatiable client. Unable to determine status code"

# rscApiCheckAuthorization: Checks if the provided authorization key is valid.
#
# ```
Expand Down

0 comments on commit f2f6727

Please sign in to comment.