Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Http-server & Redis 0.15.0 Updates (#23)
Browse files Browse the repository at this point in the history
* updated http-server to use wasmcloud:httpserver contract

* modified redis provider to use actor interface

* updated path dependencies to git, removed capability descriptors
  • Loading branch information
brooksmtownsend authored Jan 28, 2021
1 parent 504335b commit 20d6c7e
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 1,037 deletions.
17 changes: 9 additions & 8 deletions http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "wascc-httpsrv"
version = "0.9.2"
authors = ["Kevin Hoffman <[email protected]>"]
name = "wasmcloud-httpserver"
version = "0.10.0"
authors = ["wasmCloud Team"]
edition = "2018"
homepage = "https://wascc.dev"
repository = "https://github.com/wascc/http-server-provider"
description = "HTTP Server capability provider for the waSCC wasm host runtime"
homepage = "https://wasmcloud.dev"
repository = "https://github.com/wasmcloud/capability-providers"
description = "HTTP Server capability provider for the wasmCloud host runtime"
license = "Apache-2.0"
documentation = "https://docs.rs/wascc-httpsrv"
documentation = "https://docs.rs/wasmcloud-httpserver"
readme = "README.md"
keywords = ["webassembly", "wasm", "wasi", "wascc", "actix"]
categories = ["wasm", "api-bindings"]
Expand Down Expand Up @@ -35,4 +35,5 @@ env_logger = "0.7.1"
crossbeam-channel = "0.4.2"
crossbeam = "0.7.3"
crossbeam-utils = "^0.7.0"

actor-http-server = { git = "https://github.com/wasmcloud/actor-interfaces", branch = "main" }
actor-core = { git = "https://github.com/wasmcloud/actor-interfaces", branch = "main" }
2 changes: 1 addition & 1 deletion http-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# waSCC HTTP Server Provider

This library is a _native capability provider_ for the `wascc:http_server` capability. Only actors signed with tokens containing this capability privilege will be allowed to use it.
This library is a _native capability provider_ for the `wasmcloud:httpserver` capability. Only actors signed with tokens containing this capability privilege will be allowed to use it.

It should be compiled as a native shared object binary (linux `.so`, mac `.dylib`, windows `.dll`) and made available to the **waSCC** host runtime as a plugin. If you want to statically compile (embed) it into a custom waSCC host, then simply enable the `static_plugin` feature in your dependencies:

Expand Down
11 changes: 0 additions & 11 deletions http-server/codegen.yaml

This file was deleted.

92 changes: 0 additions & 92 deletions http-server/src/generated/core.rs

This file was deleted.

98 changes: 0 additions & 98 deletions http-server/src/generated/http.rs

This file was deleted.

2 changes: 0 additions & 2 deletions http-server/src/generated/mod.rs

This file was deleted.

53 changes: 13 additions & 40 deletions http-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
mod generated;

#[macro_use]
extern crate wascc_codec as codec;

#[macro_use]
extern crate log;

extern crate actix_rt;

use crate::generated::core::{CapabilityConfiguration, HealthResponse};
use actix_web::dev::Body;
use actix_web::dev::Server;
use actix_web::http::{HeaderName, HeaderValue, StatusCode};
use actix_web::web::Bytes;
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
use codec::capabilities::{
CapabilityDescriptor, CapabilityProvider, Dispatcher, NullDispatcher, OperationDirection,
OP_GET_CAPABILITY_DESCRIPTOR,
};

use std::collections::HashMap;
use std::error::Error;
use std::sync::Arc;
use std::sync::RwLock;
use wascc_codec::core::{OP_BIND_ACTOR, OP_REMOVE_ACTOR, OP_HEALTH_REQUEST};
use wascc_codec::{deserialize, serialize};

const CAPABILITY_ID: &str = "wascc:http_server";
use actor_core::{deserialize, serialize, CapabilityConfiguration, HealthCheckResponse};
use codec::capabilities::{CapabilityProvider, Dispatcher, NullDispatcher};
use codec::core::{OP_BIND_ACTOR, OP_HEALTH_REQUEST, OP_REMOVE_ACTOR};

const CAPABILITY_ID: &str = "wasmcloud:httpserver";
const VERSION: &str = env!("CARGO_PKG_VERSION");
const REVISION: u32 = 3; // Increment for each crates publish

Expand All @@ -35,7 +27,7 @@ const OP_HANDLE_REQUEST: &str = "HandleRequest";
#[cfg(not(feature = "static_plugin"))]
capability_provider!(HttpServerProvider, HttpServerProvider::new);

/// An Actix-web implementation of the `wascc:http_server` capability specification
/// An Actix-web implementation of the `wasmcloud:httpserver` capability specification
#[derive(Clone)]
pub struct HttpServerProvider {
dispatcher: Arc<RwLock<Box<dyn Dispatcher>>>,
Expand Down Expand Up @@ -74,8 +66,7 @@ impl HttpServerProvider {
fn spawn_server(&self, cfgvals: &CapabilityConfiguration) {
if self.servers.read().unwrap().contains_key(&cfgvals.module) {
return;
}

}
let bind_addr = match cfgvals.values.get("PORT") {
Some(v) => format!("0.0.0.0:{}", v),
None => "0.0.0.0:8080".to_string(),
Expand Down Expand Up @@ -107,24 +98,6 @@ impl HttpServerProvider {
let _ = sys.run();
});
}

/// Obtains the capability provider descriptor
fn get_descriptor(&self) -> Result<Vec<u8>, Box<dyn Error + Sync + Send>> {
Ok(serialize(
CapabilityDescriptor::builder()
.id(CAPABILITY_ID)
.name("Default waSCC HTTP Server Provider (Actix)")
.long_description("A fast, multi-threaded HTTP server for waSCC actors")
.version(VERSION)
.revision(REVISION)
.with_operation(
OP_HANDLE_REQUEST,
OperationDirection::ToActor,
"Delivers an HTTP request to an actor and expects an HTTP response in return",
)
.build(),
)?)
}
}

impl Default for HttpServerProvider {
Expand Down Expand Up @@ -174,10 +147,10 @@ impl CapabilityProvider for HttpServerProvider {
self.terminate_server(&cfgvals.module);
Ok(vec![])
}
OP_HEALTH_REQUEST if actor == "system" => {
Ok(serialize(HealthResponse{healthy: true, message: "".to_string()})?)
}
OP_GET_CAPABILITY_DESCRIPTOR if actor == "system" => self.get_descriptor(),
OP_HEALTH_REQUEST if actor == "system" => Ok(serialize(HealthCheckResponse {
healthy: true,
message: "".to_string(),
})?),
_ => Err("bad dispatch".into()),
}
}
Expand All @@ -199,7 +172,7 @@ async fn request_handler(
state: web::Data<Arc<RwLock<Box<dyn Dispatcher>>>>,
module: web::Data<String>,
) -> HttpResponse {
let request = crate::generated::http::Request {
let request = actor_http_server::Request {
method: req.method().as_str().to_string(),
path: req.uri().path().to_string(),
query_string: req.query_string().to_string(),
Expand All @@ -214,7 +187,7 @@ async fn request_handler(
};
match resp {
Ok(r) => {
let r = deserialize::<crate::generated::http::Response>(r.as_slice());
let r = deserialize::<actor_http_server::Response>(r.as_slice());
if let Ok(r) = r {
let mut response = HttpResponse::with_body(
StatusCode::from_u16(r.status_code as _).unwrap(),
Expand Down
18 changes: 10 additions & 8 deletions redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "wascc-redis"
version = "0.9.2"
authors = ["Kevin Hoffman <[email protected]>"]
name = "wasmcloud-redis"
version = "0.10.0"
authors = ["wasmCloud Team"]
edition = "2018"
homepage = "https://wascc.dev"
repository = "https://github.com/wascc/redis-provider"
description = "Redis capability provider for the waSCC WebAssembly actor runtime"
homepage = "https://wasmcloud.dev"
repository = "https://github.com/wasmcloud/capability-providers"
description = "Redis capability provider for the wasmCloud WebAssembly actor runtime"
license = "Apache-2.0"
documentation = "https://docs.rs/wascc-redis"
documentation = "https://docs.rs/wasmcloud-redis"
readme = "README.md"
keywords = ["webassembly", "wasm", "keyvalue", "wascc", "redis"]
keywords = ["webassembly", "wasm", "keyvalue", "wasmcloud", "redis"]
categories = ["wasm", "api-bindings"]

[badges]
Expand All @@ -33,3 +33,5 @@ crossbeam-utils = "0.8.1"
log = "0.4.11"
wascc-codec = "0.9.0"
redis = "0.17.0"
actor-core = { git = "https://github.com/wasmcloud/actor-interfaces", branch = "main" }
actor-keyvalue = { git = "https://github.com/wasmcloud/actor-interfaces", branch = "main" }
Loading

0 comments on commit 20d6c7e

Please sign in to comment.