Skip to content

Commit

Permalink
feat: scaffold profile management (#50)
Browse files Browse the repository at this point in the history
* feat: generate profile type

* feat: token manager

* refactor: make allow policy into configurable constant policy

* feat: scaffold token management abstractions

* refactor: flatten core crate
  • Loading branch information
roeap committed May 5, 2024
1 parent 09bb13b commit 47689de
Show file tree
Hide file tree
Showing 20 changed files with 629 additions and 216 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yaml
@@ -1,6 +1,5 @@
name: Report a bug
description: File a bug report
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yaml
@@ -1,6 +1,5 @@
name: Request a new feature
description: File a feature request
title: "[Feature]: "
labels: ["enhancement"]
body:
- type: markdown
Expand Down
14 changes: 9 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion delta-sharing/core/Cargo.toml
Expand Up @@ -18,12 +18,19 @@ pbjson = { version = "0.6" }
prost = { version = "0.12" }
tokio = { version = "1", features = ["rt-multi-thread", "parking_lot"] }

# in-memory handler dependencies (in alphabetical order)
dashmap = { version = "5", optional = true }
uuid = { version = "1.8", optional = true, features = ["v5"] }

# profile management dependencies (in alphabetical order)
hex = { version = "0.4.3", optional = true }
jsonwebtoken = { version = "9.3", optional = true }
ring = { version = "0.17.8", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["full"] }

[features]
default = ["memory"]
default = ["memory", "profiles"]
memory = ["dashmap", "uuid"]
profiles = ["jsonwebtoken", "hex", "ring"]
80 changes: 0 additions & 80 deletions delta-sharing/core/src/discovery/mod.rs

This file was deleted.

22 changes: 22 additions & 0 deletions delta-sharing/core/src/error.rs
@@ -1,3 +1,5 @@
use jsonwebtoken::errors::{Error as JwtError, ErrorKind as JwtErrorKind};

// A convenience type for declaring Results in the Delta Sharing libraries.
pub type Result<T, E = Error> = std::result::Result<T, E>;

Expand All @@ -9,9 +11,29 @@ pub enum Error {
#[error("Entity not found.")]
NotFound,

#[error("No or invalid token provided.")]
Unauthenticated,

#[error("Recipient is not allowed to read the entity.")]
NotAllowed,

#[error("Invalid table location: {0}")]
InvalidTableLocation(String),

#[error("Generic error: {0}")]
Generic(String),
}

impl From<JwtError> for Error {
fn from(e: JwtError) -> Self {
match e.kind() {
JwtErrorKind::InvalidToken
| JwtErrorKind::InvalidIssuer
| JwtErrorKind::InvalidSubject
| JwtErrorKind::ExpiredSignature
| JwtErrorKind::ImmatureSignature
| JwtErrorKind::InvalidSignature => Error::Unauthenticated,
_ => Error::Generic(e.to_string()),
}
}
}
89 changes: 86 additions & 3 deletions delta-sharing/core/src/gen/delta_sharing.v1.rs
Expand Up @@ -209,9 +209,29 @@ pub struct GetTableVersionResponse {
#[prost(int64, tag="1")]
pub version: i64,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Profile {
/// The file format version of the profile file. This version will be increased whenever
/// non-forward-compatible changes are made to the profile format. When a client is running
/// an unsupported profile file format version, it should show an error message instructing
/// the user to upgrade to a newer version of their client.
#[prost(int32, tag="1")]
pub share_credentials_version: i32,
/// The url of the sharing server.
#[prost(string, tag="2")]
pub endpoint: ::prost::alloc::string::String,
/// The bearer token to access the server.
#[prost(string, tag="3")]
pub bearer_token: ::prost::alloc::string::String,
/// The expiration time of the bearer token in ISO 8601 format. This field is optional
/// and if it is not provided, the bearer token can be seen as never expire.
#[prost(string, tag="4")]
pub expiration_time: ::prost::alloc::string::String,
}
/// Encoded file descriptor set for the `delta_sharing.v1` package
pub const FILE_DESCRIPTOR_SET: &[u8] = &[
0x0a, 0xfb, 0x4f, 0x0a, 0x24, 0x64, 0x65, 0x6c, 0x74, 0x61, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x69,
0x0a, 0xe5, 0x57, 0x0a, 0x24, 0x64, 0x65, 0x6c, 0x74, 0x61, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x69,
0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x65, 0x6c, 0x74, 0x61, 0x5f, 0x73, 0x68, 0x61, 0x72,
0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x64, 0x65, 0x6c, 0x74, 0x61,
0x5f, 0x73, 0x68, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66,
Expand Down Expand Up @@ -332,7 +352,18 @@ pub const FILE_DESCRIPTOR_SET: &[u8] = &[
0x0a, 0x17, 0x47, 0x65, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72,
0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x4a, 0xe0, 0x40, 0x0a, 0x07, 0x12, 0x05, 0x00, 0x00, 0xae, 0x01, 0x01, 0x0a,
0x69, 0x6f, 0x6e, 0x22, 0xad, 0x01, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12,
0x3a, 0x0a, 0x19, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5f, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74,
0x69, 0x61, 0x6c, 0x73, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x17, 0x73, 0x68, 0x61, 0x72, 0x65, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74,
0x69, 0x61, 0x6c, 0x73, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x65,
0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65,
0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x65, 0x61, 0x72, 0x65,
0x72, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x62,
0x65, 0x61, 0x72, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x65, 0x78,
0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0e, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54,
0x69, 0x6d, 0x65, 0x4a, 0x9a, 0x47, 0x0a, 0x07, 0x12, 0x05, 0x00, 0x00, 0xc0, 0x01, 0x01, 0x0a,
0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03,
0x02, 0x00, 0x19, 0x0a, 0x09, 0x0a, 0x02, 0x03, 0x00, 0x12, 0x03, 0x04, 0x00, 0x25, 0x0a, 0xd5,
0x01, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x08, 0x00, 0x0d, 0x01, 0x1a, 0xc8, 0x01, 0x20, 0x41,
Expand Down Expand Up @@ -850,7 +881,59 @@ pub const FILE_DESCRIPTOR_SET: &[u8] = &[
0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2e, 0x0a, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0e, 0x02,
0x00, 0x05, 0x12, 0x04, 0xad, 0x01, 0x02, 0x07, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0e, 0x02, 0x00,
0x01, 0x12, 0x04, 0xad, 0x01, 0x08, 0x0f, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0e, 0x02, 0x00, 0x03,
0x12, 0x04, 0xad, 0x01, 0x12, 0x13, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x12, 0x04, 0xad, 0x01, 0x12, 0x13, 0x0a, 0x0c, 0x0a, 0x02, 0x04, 0x0f, 0x12, 0x06, 0xb0, 0x01,
0x00, 0xc0, 0x01, 0x01, 0x0a, 0x0b, 0x0a, 0x03, 0x04, 0x0f, 0x01, 0x12, 0x04, 0xb0, 0x01, 0x08,
0x0f, 0x0a, 0xd0, 0x02, 0x0a, 0x04, 0x04, 0x0f, 0x02, 0x00, 0x12, 0x04, 0xb5, 0x01, 0x02, 0x26,
0x1a, 0xc1, 0x02, 0x20, 0x54, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66, 0x6f, 0x72,
0x6d, 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2e,
0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x69,
0x6c, 0x6c, 0x20, 0x62, 0x65, 0x20, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20,
0x77, 0x68, 0x65, 0x6e, 0x65, 0x76, 0x65, 0x72, 0x0a, 0x20, 0x6e, 0x6f, 0x6e, 0x2d, 0x66, 0x6f,
0x72, 0x77, 0x61, 0x72, 0x64, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65,
0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x6d, 0x61, 0x64,
0x65, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65,
0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x2e, 0x20, 0x57, 0x68, 0x65, 0x6e, 0x20, 0x61, 0x20,
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x69, 0x73, 0x20, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e,
0x67, 0x0a, 0x20, 0x61, 0x6e, 0x20, 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65,
0x64, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x66,
0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x69,
0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x61, 0x6e,
0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x69,
0x6e, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x69, 0x6e, 0x67, 0x0a, 0x20, 0x74, 0x68, 0x65, 0x20,
0x75, 0x73, 0x65, 0x72, 0x20, 0x74, 0x6f, 0x20, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x20,
0x74, 0x6f, 0x20, 0x61, 0x20, 0x6e, 0x65, 0x77, 0x65, 0x72, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69,
0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x69, 0x72, 0x20, 0x63, 0x6c, 0x69, 0x65,
0x6e, 0x74, 0x2e, 0x0a, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x00, 0x05, 0x12, 0x04, 0xb5,
0x01, 0x02, 0x07, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x00, 0x01, 0x12, 0x04, 0xb5, 0x01,
0x08, 0x21, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x00, 0x03, 0x12, 0x04, 0xb5, 0x01, 0x24,
0x25, 0x0a, 0x2e, 0x0a, 0x04, 0x04, 0x0f, 0x02, 0x01, 0x12, 0x04, 0xb8, 0x01, 0x02, 0x16, 0x1a,
0x20, 0x20, 0x54, 0x68, 0x65, 0x20, 0x75, 0x72, 0x6c, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65,
0x20, 0x73, 0x68, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e,
0x0a, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x01, 0x05, 0x12, 0x04, 0xb8, 0x01, 0x02, 0x08,
0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x01, 0x01, 0x12, 0x04, 0xb8, 0x01, 0x09, 0x11, 0x0a,
0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x01, 0x03, 0x12, 0x04, 0xb8, 0x01, 0x14, 0x15, 0x0a, 0x36,
0x0a, 0x04, 0x04, 0x0f, 0x02, 0x02, 0x12, 0x04, 0xbb, 0x01, 0x02, 0x1a, 0x1a, 0x28, 0x20, 0x54,
0x68, 0x65, 0x20, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x20,
0x74, 0x6f, 0x20, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65,
0x72, 0x76, 0x65, 0x72, 0x2e, 0x0a, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x02, 0x05, 0x12,
0x04, 0xbb, 0x01, 0x02, 0x08, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x02, 0x01, 0x12, 0x04,
0xbb, 0x01, 0x09, 0x15, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x02, 0x03, 0x12, 0x04, 0xbb,
0x01, 0x18, 0x19, 0x0a, 0xad, 0x01, 0x0a, 0x04, 0x04, 0x0f, 0x02, 0x03, 0x12, 0x04, 0xbf, 0x01,
0x02, 0x1d, 0x1a, 0x9e, 0x01, 0x20, 0x54, 0x68, 0x65, 0x20, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65,
0x20, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x20, 0x69, 0x6e,
0x20, 0x49, 0x53, 0x4f, 0x20, 0x38, 0x36, 0x30, 0x31, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74,
0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x20, 0x69, 0x73, 0x20,
0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x0a, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x66,
0x20, 0x69, 0x74, 0x20, 0x69, 0x73, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x70, 0x72, 0x6f, 0x76, 0x69,
0x64, 0x65, 0x64, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x65, 0x61, 0x72, 0x65, 0x72, 0x20,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x62, 0x65, 0x20, 0x73, 0x65, 0x65,
0x6e, 0x20, 0x61, 0x73, 0x20, 0x6e, 0x65, 0x76, 0x65, 0x72, 0x20, 0x65, 0x78, 0x70, 0x69, 0x72,
0x65, 0x2e, 0x0a, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x03, 0x05, 0x12, 0x04, 0xbf, 0x01,
0x02, 0x08, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x03, 0x01, 0x12, 0x04, 0xbf, 0x01, 0x09,
0x18, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x0f, 0x02, 0x03, 0x03, 0x12, 0x04, 0xbf, 0x01, 0x1b, 0x1c,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
];
include!("delta_sharing.v1.serde.rs");
// @@protoc_insertion_point(module)

0 comments on commit 47689de

Please sign in to comment.