Skip to content

Commit aebeafc

Browse files
authored
Merge pull request #2630 from golemcloud/code-first-routes-cors
code-first-routes: cors support
2 parents 3347a93 + 212e42c commit aebeafc

File tree

100 files changed

+2951
-6481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2951
-6481
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ combine = "4.6.7"
145145
conditional-trait-gen = "0.4.1"
146146
console-subscriber = "0.4.1"
147147
convert_case = "0.8.0"
148+
cookie = "0.18.1"
148149
criterion = "0.5"
149150
crossterm = "0.28.1"
150151
darling = "0.20.11"

cli/golem-cli/src/command_handler/api/deployment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl ApiDeploymentCommandHandler {
292292
&self,
293293
http_api_deployment: &DeploymentPlanHttpApiDeploymentEntry,
294294
deployable_http_api_deployment: &[HttpApiDefinitionName],
295-
_diff: &diff::DiffForHashOf<diff::HttpApiDeployment>,
295+
_diff: &diff::DiffForHashOf<diff::HttpApiDeploymentLegacy>,
296296
) -> anyhow::Result<()> {
297297
log_action(
298298
"Updating",

cli/golem-cli/src/command_handler/app/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,11 @@ impl AppCommandHandler {
759759

760760
let diffable_local_http_api_deployments = {
761761
let mut diffable_local_http_api_deployments =
762-
BTreeMap::<String, diff::HashOf<diff::HttpApiDeployment>>::new();
762+
BTreeMap::<String, diff::HashOf<diff::HttpApiDeploymentLegacy>>::new();
763763
for (domain, http_api_deployment) in &deployable_manifest_http_api_deployments {
764764
diffable_local_http_api_deployments.insert(
765765
domain.0.clone(),
766-
diff::HttpApiDeployment {
766+
diff::HttpApiDeploymentLegacy {
767767
agent_types: http_api_deployment
768768
.iter()
769769
.map(|def| def.0.clone())

cli/golem/src/launch.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ use golem_worker_executor::services::golem_config::{
4040
KeyValueStorageMultiSqliteConfig, ResourceLimitsConfig, ResourceLimitsGrpcConfig,
4141
ShardManagerServiceConfig, ShardManagerServiceGrpcConfig, WorkerServiceGrpcConfig,
4242
};
43-
use golem_worker_service::config::{RouteResolverConfig, WorkerServiceConfig};
43+
use golem_worker_service::config::{
44+
RouteResolverConfig, SqliteSessionStoreConfig, WorkerServiceConfig,
45+
};
4446
use golem_worker_service::WorkerService;
4547
use opentelemetry::global;
4648
use opentelemetry_sdk::metrics::MeterProviderBuilder;
@@ -325,18 +327,21 @@ fn worker_service_config(
325327
port: 0,
326328
..Default::default()
327329
},
328-
gateway_session_storage: golem_worker_service::config::GatewaySessionStorageConfig::Sqlite(
329-
DbSqliteConfig {
330-
database: args
331-
.data_dir
332-
.join("gateway-sessions.db")
333-
.to_string_lossy()
334-
.to_string(),
335-
max_connections: 4,
336-
foreign_keys: false,
330+
gateway_session_storage: golem_worker_service::config::SessionStoreConfig::Sqlite(
331+
SqliteSessionStoreConfig {
332+
pending_login_expiration: Duration::from_hours(1),
333+
cleanup_interval: Duration::from_mins(5),
334+
sqlite_config: DbSqliteConfig {
335+
database: args
336+
.data_dir
337+
.join("gateway-sessions.db")
338+
.to_string_lossy()
339+
.to_string(),
340+
max_connections: 4,
341+
foreign_keys: false,
342+
},
337343
},
338344
),
339-
blob_storage: blob_storage_config(args),
340345
routing_table: RoutingTableConfig {
341346
host: args.router_addr.clone(),
342347
port: shard_manager_run_details.grpc_port,

golem-api-grpc/proto/golem/customapi/core.proto

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ message CompiledRoute {
163163
RequestBodySchema body = 4;
164164
RouteBehaviour behavior = 5;
165165
optional golem.registry.SecuritySchemeId security_scheme = 6;
166-
golem.component.CorsOptions cors = 7;
166+
CorsOptions cors = 7;
167167
}
168168

169169
message RouteBehaviour {
170170
oneof kind {
171171
CallAgent call_agent = 1;
172+
CorsPreflight cors_preflight = 2;
172173
}
173174

174175
message CallAgent {
@@ -181,6 +182,11 @@ message RouteBehaviour {
181182
repeated MethodParameter method_parameters = 7;
182183
golem.component.DataSchema expected_agent_response = 8;
183184
}
185+
186+
message CorsPreflight {
187+
repeated string allowed_origins = 1;
188+
repeated golem.component.HttpMethod allowed_methods = 2;
189+
}
184190
}
185191

186192
message SecuritySchemeDetails {
@@ -192,3 +198,7 @@ message SecuritySchemeDetails {
192198
string redirect_url = 6;
193199
repeated string scopes = 7;
194200
}
201+
202+
message CorsOptions {
203+
repeated string allowed_patterns = 1;
204+
}

golem-common/src/base_model/agent.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,9 @@ pub struct HttpEndpointDetails {
737737
pub cors_options: CorsOptions,
738738
}
739739

740-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
740+
#[derive(
741+
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, IntoValue, FromValue,
742+
)]
741743
#[cfg_attr(
742744
feature = "full",
743745
derive(desert_rust::BinaryCodec, poem_openapi::Union)
@@ -790,7 +792,9 @@ impl TryFrom<HttpMethod> for http::Method {
790792
}
791793
}
792794

793-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
795+
#[derive(
796+
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, IntoValue, FromValue,
797+
)]
794798
#[cfg_attr(
795799
feature = "full",
796800
derive(desert_rust::BinaryCodec, poem_openapi::Object)

golem-common/src/base_model/http_api_deployment.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,38 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use super::security_scheme::SecuritySchemeName;
1516
use crate::base_model::agent::AgentTypeName;
1617
use crate::base_model::diff;
1718
use crate::base_model::domain_registration::Domain;
1819
use crate::base_model::environment::EnvironmentId;
1920
use crate::{declare_revision, declare_structs, newtype_uuid};
2021
use chrono::DateTime;
21-
use std::collections::BTreeSet;
22+
use std::collections::BTreeMap;
2223

2324
newtype_uuid!(HttpApiDeploymentId);
2425

2526
declare_revision!(HttpApiDeploymentRevision);
2627

2728
declare_structs! {
29+
#[derive(Default)]
30+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
31+
#[cfg_attr(feature = "full", desert(transparent))]
32+
pub struct HttpApiDeploymentAgentOptions {
33+
/// Security scheme to use for all agent methods that require auth.
34+
/// Failure to provide a security scheme for an agent that requires one will lead to a deployment failure.
35+
/// If the requested security scheme does not exist in the environment, the route will be disabled at runtime.
36+
pub security_scheme: Option<SecuritySchemeName>
37+
}
38+
2839
pub struct HttpApiDeploymentCreation {
2940
pub domain: Domain,
30-
pub agent_types: BTreeSet<AgentTypeName>
41+
pub agents: BTreeMap<AgentTypeName, HttpApiDeploymentAgentOptions>
3142
}
3243

3344
pub struct HttpApiDeploymentUpdate {
3445
pub current_revision: HttpApiDeploymentRevision,
35-
pub agent_types: Option<BTreeSet<AgentTypeName>>
46+
pub agents: Option<BTreeMap<AgentTypeName, HttpApiDeploymentAgentOptions>>
3647
}
3748

3849
pub struct HttpApiDeployment {
@@ -41,7 +52,7 @@ declare_structs! {
4152
pub environment_id: EnvironmentId,
4253
pub domain: Domain,
4354
pub hash: diff::Hash,
44-
pub agent_types: BTreeSet<AgentTypeName>,
55+
pub agents: BTreeMap<AgentTypeName, HttpApiDeploymentAgentOptions>,
4556
pub created_at: DateTime<chrono::Utc>,
4657
}
4758
}

golem-common/src/base_model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl FromValue for Timestamp {
157157
}
158158
}
159159

160-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
160+
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, Default)]
161161
#[cfg_attr(
162162
feature = "full",
163163
derive(desert_rust::BinaryCodec, poem_openapi::Object)

golem-common/src/model/diff/deployment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use crate::model::diff::component::Component;
1616
use crate::model::diff::hash::{hash_from_serialized_value, Hash, HashOf, Hashable};
1717
use crate::model::diff::http_api_definition::HttpApiDefinition;
18-
use crate::model::diff::http_api_deployment::HttpApiDeployment;
18+
use crate::model::diff::http_api_deployment::HttpApiDeploymentLegacy;
1919
use crate::model::diff::ser::serialize_with_mode;
2020
use crate::model::diff::{BTreeMapDiff, Diffable};
2121
use serde::Serialize;
@@ -32,7 +32,7 @@ pub struct Deployment {
3232
pub http_api_definitions: BTreeMap<String, HashOf<HttpApiDefinition>>,
3333
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
3434
#[serde(serialize_with = "serialize_with_mode")]
35-
pub http_api_deployments: BTreeMap<String, HashOf<HttpApiDeployment>>,
35+
pub http_api_deployments: BTreeMap<String, HashOf<HttpApiDeploymentLegacy>>,
3636
}
3737

3838
#[derive(Debug, Clone, PartialEq, Serialize)]
@@ -43,7 +43,7 @@ pub struct DeploymentDiff {
4343
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
4444
pub http_api_definitions: BTreeMapDiff<String, HashOf<HttpApiDefinition>>,
4545
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
46-
pub http_api_deployments: BTreeMapDiff<String, HashOf<HttpApiDeployment>>,
46+
pub http_api_deployments: BTreeMapDiff<String, HashOf<HttpApiDeploymentLegacy>>,
4747
}
4848

4949
impl Diffable for Deployment {

0 commit comments

Comments
 (0)