Skip to content

Commit 1c3f5cc

Browse files
committed
further cleanups
1 parent bb440f1 commit 1c3f5cc

14 files changed

Lines changed: 550 additions & 302 deletions

File tree

golem-api-grpc/proto/golem/worker/public_oplog.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ message QueuedCardEventCard {
298298

299299
enum CardInstallFailure {
300300
CARD_INSTALL_FAILURE_UNSPECIFIED = 0;
301-
CARD_INSTALL_FAILURE_CARD_REVOKED = 1;
302301
CARD_INSTALL_FAILURE_NOT_FOUND = 2;
303302
CARD_INSTALL_FAILURE_RECIPIENT_MISMATCH = 3;
304303
CARD_INSTALL_FAILURE_NOT_PERMITTED = 4;

golem-api-grpc/proto/golem/worker/raw_oplog.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ message RawQueuedCardEventCard {
336336

337337
enum RawCardInstallFailure {
338338
RAW_CARD_INSTALL_FAILURE_UNSPECIFIED = 0;
339-
RAW_CARD_INSTALL_FAILURE_CARD_REVOKED = 1;
340339
RAW_CARD_INSTALL_FAILURE_NOT_FOUND = 2;
341340
RAW_CARD_INSTALL_FAILURE_RECIPIENT_MISMATCH = 3;
342341
RAW_CARD_INSTALL_FAILURE_NOT_PERMITTED = 4;

golem-common/src/base_model/card/algebra.rs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,7 @@ impl EffectiveSurface {
141141
&self,
142142
child_lower_positive: &[PermissionPattern],
143143
child_upper_positive: &[PermissionPattern],
144-
) -> Result<(), CardAlgebraError> {
145-
self.validates_derivation_with_witness(child_lower_positive, child_upper_positive)
146-
.map(|_| ())
147-
}
148-
149-
pub fn validates_derivation_with_witness(
150-
&self,
151-
child_lower_positive: &[PermissionPattern],
152-
child_upper_positive: &[PermissionPattern],
153144
) -> Result<Vec<CardId>, CardAlgebraError> {
154-
if self.source_card_ids.len() != self.lower.len()
155-
|| self.source_card_ids.len() != self.upper.len()
156-
{
157-
self.validates_derivation_legacy(child_lower_positive, child_upper_positive)?;
158-
return Ok(self.source_card_ids.clone());
159-
}
160-
161145
let mut witness = Vec::new();
162146

163147
for grant in child_lower_positive {
@@ -174,7 +158,7 @@ impl EffectiveSurface {
174158
grant: Box::new(grant.clone()),
175159
});
176160
};
177-
push_unique(&mut witness, self.source_card_ids[parent_index]);
161+
push_source_if_available(&mut witness, &self.source_card_ids, parent_index);
178162
}
179163

180164
for grant in child_upper_positive {
@@ -186,38 +170,14 @@ impl EffectiveSurface {
186170
});
187171
}
188172
if !surface.is_empty() {
189-
push_unique(&mut witness, self.source_card_ids[parent_index]);
173+
push_source_if_available(&mut witness, &self.source_card_ids, parent_index);
190174
}
191175
}
192176
}
193177

194178
Ok(witness)
195179
}
196180

197-
fn validates_derivation_legacy(
198-
&self,
199-
child_lower_positive: &[PermissionPattern],
200-
child_upper_positive: &[PermissionPattern],
201-
) -> Result<(), CardAlgebraError> {
202-
for grant in child_lower_positive {
203-
if !self.allows_lower(&grant.to_target())? {
204-
return Err(CardAlgebraError::DerivationNotSubsumed {
205-
grant: Box::new(grant.clone()),
206-
});
207-
}
208-
}
209-
210-
for grant in child_upper_positive {
211-
if !self.allows_upper(&grant.to_target())? {
212-
return Err(CardAlgebraError::DerivationNotSubsumed {
213-
grant: Box::new(grant.clone()),
214-
});
215-
}
216-
}
217-
218-
Ok(())
219-
}
220-
221181
fn allows_lower(&self, request: &PermissionTarget) -> Result<bool, CardAlgebraError> {
222182
for surface in &self.lower {
223183
if surface.allows(request)? {
@@ -239,6 +199,12 @@ impl EffectiveSurface {
239199
}
240200
}
241201

202+
fn push_source_if_available(values: &mut Vec<CardId>, source_card_ids: &[CardId], index: usize) {
203+
if let Some(card_id) = source_card_ids.get(index) {
204+
push_unique(values, *card_id);
205+
}
206+
}
207+
242208
fn push_unique(values: &mut Vec<CardId>, value: CardId) {
243209
if !values.contains(&value) {
244210
values.push(value);

golem-common/src/base_model/card/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn derivation_witness_excludes_unrelated_parent() {
327327
EffectiveSurface::from_cards(&[needed_parent, unrelated_parent], &recipient).unwrap();
328328

329329
let witness = surface
330-
.validates_derivation_with_witness(std::slice::from_ref(&read_tmp), &[])
330+
.validates_derivation(std::slice::from_ref(&read_tmp), &[])
331331
.unwrap();
332332

333333
assert_eq!(witness, vec![needed_parent_id]);
@@ -357,7 +357,7 @@ fn derivation_witness_includes_multiple_needed_parents() {
357357
EffectiveSurface::from_cards(&[filesystem_parent, secret_parent], &recipient).unwrap();
358358

359359
let witness = surface
360-
.validates_derivation_with_witness(&[read_tmp, reveal_secret], &[])
360+
.validates_derivation(&[read_tmp, reveal_secret], &[])
361361
.unwrap();
362362

363363
assert_eq!(witness, vec![filesystem_parent_id, secret_parent_id]);

golem-common/src/base_model/mod.rs

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,225 @@ impl FromStr for ScanCursor {
797797
Err("Invalid cursor, must have 'layer/cursor' format".to_string())
798798
}
799799
}
800+
<<<<<<< HEAD
801+
||||||| parent of f66678cfc (further cleanups)
802+
}
803+
804+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
805+
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
806+
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
807+
#[serde(rename_all = "camelCase")]
808+
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
809+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
810+
#[cfg_attr(feature = "full", desert(evolution()))]
811+
pub struct QueuedCardEventCard {
812+
pub card_id: CardId,
813+
#[cfg_attr(feature = "full", oai(skip))]
814+
pub card: Option<StoredCard>,
815+
}
816+
817+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
818+
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
819+
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
820+
#[serde(rename_all = "camelCase")]
821+
#[wit(
822+
name = "public-queued-card-event-card",
823+
owner = "golem:api@1.5.0/oplog"
824+
)]
825+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
826+
#[cfg_attr(feature = "full", desert(evolution()))]
827+
pub struct PublicQueuedCardEventCard {
828+
pub card_id: CardId,
829+
}
830+
831+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
832+
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
833+
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
834+
#[serde(tag = "type")]
835+
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
836+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
837+
#[cfg_attr(feature = "full", desert(evolution()))]
838+
pub enum QueuedCardEvent {
839+
Install(QueuedCardEventCard),
840+
Revoke(QueuedCardEventCard),
841+
}
842+
843+
impl QueuedCardEvent {
844+
pub fn card_id(&self) -> CardId {
845+
match self {
846+
Self::Install(event) | Self::Revoke(event) => event.card_id,
847+
}
848+
}
849+
850+
pub fn install(card: impl Into<StoredCard>) -> Self {
851+
let card = card.into();
852+
Self::Install(QueuedCardEventCard {
853+
card_id: card.card_id(),
854+
card: Some(card),
855+
})
856+
}
857+
858+
pub fn revoke(card_id: CardId) -> Self {
859+
Self::Revoke(QueuedCardEventCard {
860+
card_id,
861+
card: None,
862+
})
863+
}
864+
}
865+
866+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
867+
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
868+
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
869+
#[serde(tag = "type")]
870+
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
871+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
872+
#[cfg_attr(feature = "full", desert(evolution()))]
873+
pub enum PublicQueuedCardEvent {
874+
Install(PublicQueuedCardEventCard),
875+
Revoke(PublicQueuedCardEventCard),
876+
}
877+
878+
impl PublicQueuedCardEvent {
879+
pub fn card_id(&self) -> CardId {
880+
match self {
881+
Self::Install(event) | Self::Revoke(event) => event.card_id,
882+
}
883+
}
884+
}
885+
886+
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
887+
fn from(value: QueuedCardEvent) -> Self {
888+
match value {
889+
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
890+
card_id: event.card_id,
891+
}),
892+
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
893+
card_id: event.card_id,
894+
}),
895+
}
896+
}
897+
}
898+
899+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
900+
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
901+
#[serde(rename_all = "camelCase")]
902+
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
903+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
904+
#[cfg_attr(feature = "full", desert(evolution()))]
905+
pub enum CardInstallFailure {
906+
CardRevoked,
907+
NotFound,
908+
RecipientMismatch,
909+
NotPermitted,
910+
=======
911+
}
912+
913+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
914+
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
915+
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
916+
#[serde(rename_all = "camelCase")]
917+
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
918+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
919+
#[cfg_attr(feature = "full", desert(evolution()))]
920+
pub struct QueuedCardEventCard {
921+
pub card_id: CardId,
922+
#[cfg_attr(feature = "full", oai(skip))]
923+
pub card: Option<StoredCard>,
924+
}
925+
926+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
927+
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
928+
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
929+
#[serde(rename_all = "camelCase")]
930+
#[wit(
931+
name = "public-queued-card-event-card",
932+
owner = "golem:api@1.5.0/oplog"
933+
)]
934+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
935+
#[cfg_attr(feature = "full", desert(evolution()))]
936+
pub struct PublicQueuedCardEventCard {
937+
pub card_id: CardId,
938+
}
939+
940+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
941+
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
942+
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
943+
#[serde(tag = "type")]
944+
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
945+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
946+
#[cfg_attr(feature = "full", desert(evolution()))]
947+
pub enum QueuedCardEvent {
948+
Install(QueuedCardEventCard),
949+
Revoke(QueuedCardEventCard),
950+
}
951+
952+
impl QueuedCardEvent {
953+
pub fn card_id(&self) -> CardId {
954+
match self {
955+
Self::Install(event) | Self::Revoke(event) => event.card_id,
956+
}
957+
}
958+
959+
pub fn install(card: impl Into<StoredCard>) -> Self {
960+
let card = card.into();
961+
Self::Install(QueuedCardEventCard {
962+
card_id: card.card_id(),
963+
card: Some(card),
964+
})
965+
}
966+
967+
pub fn revoke(card_id: CardId) -> Self {
968+
Self::Revoke(QueuedCardEventCard {
969+
card_id,
970+
card: None,
971+
})
972+
}
973+
}
974+
975+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
976+
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
977+
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
978+
#[serde(tag = "type")]
979+
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
980+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
981+
#[cfg_attr(feature = "full", desert(evolution()))]
982+
pub enum PublicQueuedCardEvent {
983+
Install(PublicQueuedCardEventCard),
984+
Revoke(PublicQueuedCardEventCard),
985+
}
986+
987+
impl PublicQueuedCardEvent {
988+
pub fn card_id(&self) -> CardId {
989+
match self {
990+
Self::Install(event) | Self::Revoke(event) => event.card_id,
991+
}
992+
}
993+
}
994+
995+
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
996+
fn from(value: QueuedCardEvent) -> Self {
997+
match value {
998+
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
999+
card_id: event.card_id,
1000+
}),
1001+
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
1002+
card_id: event.card_id,
1003+
}),
1004+
}
1005+
}
1006+
}
1007+
1008+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
1009+
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
1010+
#[serde(rename_all = "camelCase")]
1011+
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
1012+
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
1013+
#[cfg_attr(feature = "full", desert(evolution()))]
1014+
pub enum CardInstallFailure {
1015+
NotFound,
1016+
RecipientMismatch,
1017+
NotPermitted,
1018+
>>>>>>> f66678cfc (further cleanups)
8001019
}
8011020

8021021
#[cfg(feature = "full")]

golem-common/src/model/oplog/protobuf.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ fn card_install_failure_from_proto(
187187
golem_api_grpc::proto::golem::worker::CardInstallFailure::Unspecified => {
188188
Err("Unspecified card install failure".to_string())
189189
}
190-
golem_api_grpc::proto::golem::worker::CardInstallFailure::CardRevoked => {
191-
Ok(CardInstallFailure::CardRevoked)
192-
}
193190
golem_api_grpc::proto::golem::worker::CardInstallFailure::NotFound => {
194191
Ok(CardInstallFailure::NotFound)
195192
}
@@ -206,9 +203,6 @@ fn card_install_failure_to_proto(
206203
value: CardInstallFailure,
207204
) -> golem_api_grpc::proto::golem::worker::CardInstallFailure {
208205
match value {
209-
CardInstallFailure::CardRevoked => {
210-
golem_api_grpc::proto::golem::worker::CardInstallFailure::CardRevoked
211-
}
212206
CardInstallFailure::NotFound => {
213207
golem_api_grpc::proto::golem::worker::CardInstallFailure::NotFound
214208
}
@@ -228,9 +222,6 @@ fn raw_card_install_failure_from_proto(
228222
golem_api_grpc::proto::golem::worker::RawCardInstallFailure::Unspecified => {
229223
Err("Unspecified raw card install failure".to_string())
230224
}
231-
golem_api_grpc::proto::golem::worker::RawCardInstallFailure::CardRevoked => {
232-
Ok(CardInstallFailure::CardRevoked)
233-
}
234225
golem_api_grpc::proto::golem::worker::RawCardInstallFailure::NotFound => {
235226
Ok(CardInstallFailure::NotFound)
236227
}
@@ -247,9 +238,6 @@ fn raw_card_install_failure_to_proto(
247238
value: CardInstallFailure,
248239
) -> golem_api_grpc::proto::golem::worker::RawCardInstallFailure {
249240
match value {
250-
CardInstallFailure::CardRevoked => {
251-
golem_api_grpc::proto::golem::worker::RawCardInstallFailure::CardRevoked
252-
}
253241
CardInstallFailure::NotFound => {
254242
golem_api_grpc::proto::golem::worker::RawCardInstallFailure::NotFound
255243
}

golem-registry-service/src/services/component/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ fn prepare_agent_initial_card_for_minting(
930930
},
931931
)?;
932932
effective_surface
933-
.validates_derivation_with_witness(&lower_positive, &upper_positive)
933+
.validates_derivation(&lower_positive, &upper_positive)
934934
.map_err(|error| ComponentError::InvalidAgentInitialPermissionCard {
935935
agent_type: agent_type_name.clone(),
936936
message: format!("card derivation is not allowed by the creator's cards: {error:?}"),

0 commit comments

Comments
 (0)