Skip to content

Commit 7597008

Browse files
Merge corrections.Adapted AccountHandle branch
1 parent b166e85 commit 7597008

11 files changed

Lines changed: 54 additions & 55 deletions

File tree

resources/schema.gql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ type AccountFlowsMut {
198198
triggers: AccountFlowTriggersMut!
199199
}
200200

201+
input AccountHandleInput {
202+
id: AccountID!
203+
name: AccountName!
204+
}
205+
201206
scalar AccountID
202207

203208
input AccountLookupFilter {
@@ -3862,15 +3867,10 @@ type Resource {
38623867
status: ResourceStatus
38633868
}
38643869

3865-
input ResourceAccountByIdAndNameInput {
3866-
id: AccountID!
3867-
name: AccountName!
3868-
}
3869-
38703870
input ResourceAccountSelectorInput @oneOf {
38713871
byId: AccountID
38723872
byName: AccountName
3873-
both: ResourceAccountByIdAndNameInput
3873+
handle: AccountHandleInput
38743874
}
38753875

38763876
scalar ResourceAnnotations
@@ -4201,7 +4201,7 @@ type ResourceStatus {
42014201
Detailed conditions describing the state of the resource that are added
42024202
by controllers.
42034203
"""
4204-
conditions: ResourceConditions
4204+
conditions: ResourceConditions!
42054205
}
42064206

42074207
type ResourceStatusSummary {

src/adapter/graphql/src/queries/resources/models.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,35 @@ impl ResourceTypeSelectorInput {
5858
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5959

6060
#[derive(InputObject, Debug, Clone)]
61-
pub struct ResourceAccountByIdAndNameInput {
61+
pub struct AccountHandleInput {
6262
pub id: AccountID<'static>,
6363
pub name: AccountName<'static>,
6464
}
6565

66+
impl From<AccountHandleInput> for odf::metadata::auth::AccountHandle {
67+
fn from(value: AccountHandleInput) -> Self {
68+
Self {
69+
id: value.id.into(),
70+
name: value.name.into(),
71+
}
72+
}
73+
}
74+
75+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76+
6677
#[derive(OneofObject, Debug, Clone)]
6778
pub enum ResourceAccountSelectorInput {
6879
ById(AccountID<'static>),
6980
ByName(AccountName<'static>),
70-
Both(ResourceAccountByIdAndNameInput),
81+
Handle(AccountHandleInput),
7182
}
7283

7384
impl ResourceAccountSelectorInput {
7485
pub fn into_manifest_account(self) -> kamu_resources::ResourceAccountRef {
7586
match self {
7687
Self::ById(id) => kamu_resources::ResourceAccountRef::Id(id.into()),
7788
Self::ByName(name) => kamu_resources::ResourceAccountRef::Name(name.into()),
78-
Self::Both(ResourceAccountByIdAndNameInput { id, name }) => {
79-
kamu_resources::ResourceAccountRef::Both {
80-
id: id.into(),
81-
name: name.into(),
82-
}
83-
}
89+
Self::Handle(h) => kamu_resources::ResourceAccountRef::Handle(h.into()),
8490
}
8591
}
8692
}
@@ -676,10 +682,12 @@ pub struct ResourceHeaders {
676682
impl From<kamu_resources::ResourceView> for ResourceHeaders {
677683
fn from(value: kamu_resources::ResourceView) -> Self {
678684
let account = match value.headers.account.name {
679-
Some(name) => kamu_resources::ResourceAccountRef::Both {
680-
id: value.headers.account.id,
681-
name,
682-
},
685+
Some(name) => {
686+
kamu_resources::ResourceAccountRef::Handle(odf::metadata::auth::AccountHandle {
687+
id: value.headers.account.id,
688+
name,
689+
})
690+
}
683691
None => kamu_resources::ResourceAccountRef::Id(value.headers.account.id),
684692
};
685693

src/domain/resources/domain/src/state/resource_status.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn new_pending_resource_status() -> ResourceStatus {
2828
phase: ResourcePhase::Pending,
2929
observed_generation: None,
3030
reconciled_at: None,
31-
conditions: None,
31+
conditions: empty_resource_conditions(),
3232
}
3333
}
3434

@@ -72,11 +72,8 @@ impl ResourceStatusExt for ResourceStatus {
7272

7373
fn mark_reconciling(&mut self, now: DateTime<Utc>) {
7474
self.phase = ResourcePhase::Reconciling;
75-
let conditions = self
76-
.conditions
77-
.get_or_insert_with(empty_resource_conditions);
7875
ResourceConditionValue::set_condition(
79-
&mut conditions.entries,
76+
&mut self.conditions.entries,
8077
ResourceConditionValue::reconciling_true(now),
8178
);
8279
}
@@ -86,19 +83,16 @@ impl ResourceStatusExt for ResourceStatus {
8683
self.observed_generation = Some(observed_generation);
8784
self.reconciled_at = Some(now);
8885

89-
let conditions = self
90-
.conditions
91-
.get_or_insert_with(empty_resource_conditions);
9286
ResourceConditionValue::set_condition(
93-
&mut conditions.entries,
87+
&mut self.conditions.entries,
9488
ResourceConditionValue::accepted_true(now),
9589
);
9690
ResourceConditionValue::set_condition(
97-
&mut conditions.entries,
91+
&mut self.conditions.entries,
9892
ResourceConditionValue::ready_true(now),
9993
);
10094
ResourceConditionValue::set_condition(
101-
&mut conditions.entries,
95+
&mut self.conditions.entries,
10296
ResourceConditionValue::reconciling_false(now),
10397
);
10498
}
@@ -114,26 +108,23 @@ impl ResourceStatusExt for ResourceStatus {
114108
self.observed_generation = Some(observed_generation);
115109
self.reconciled_at = Some(now);
116110

117-
let conditions = self
118-
.conditions
119-
.get_or_insert_with(empty_resource_conditions);
120111
ResourceConditionValue::set_condition(
121-
&mut conditions.entries,
112+
&mut self.conditions.entries,
122113
ResourceConditionValue::accepted_true(now),
123114
);
124115
ResourceConditionValue::set_condition(
125-
&mut conditions.entries,
116+
&mut self.conditions.entries,
126117
ResourceConditionValue::ready_false(now, reason, message),
127118
);
128119
ResourceConditionValue::set_condition(
129-
&mut conditions.entries,
120+
&mut self.conditions.entries,
130121
ResourceConditionValue::reconciling_false(now),
131122
);
132123
}
133124

134125
fn mark_pending_for_new_generation(&mut self) {
135126
self.phase = ResourcePhase::Pending;
136-
self.conditions = None;
127+
self.conditions = empty_resource_conditions();
137128
}
138129
}
139130

@@ -142,7 +133,6 @@ impl ResourceStatusExt for ResourceStatus {
142133
fn ready_condition(status: &ResourceStatus) -> Option<ResourceConditionValue> {
143134
status
144135
.conditions
145-
.as_ref()?
146136
.entries
147137
.get(&ready_condition_type_ref())
148138
.and_then(|value| serde_json::from_value(value.clone()).ok())

src/domain/resources/facade-tests/tests/contract/account_scoping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ fn account_by_id(id: odf::AccountID) -> ResourceAccountRef {
105105
}
106106

107107
fn account_by_name_and_id(name: &odf::AccountName, id: odf::AccountID) -> ResourceAccountRef {
108-
ResourceAccountRef::Both {
108+
ResourceAccountRef::Handle(odf::metadata::auth::AccountHandle {
109109
id,
110110
name: name.clone(),
111-
}
111+
})
112112
}
113113

114114
fn unknown_account_by_name() -> ResourceAccountRef {

src/domain/resources/facade/src/facade/graphql/cynic_api/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl From<fragments::ResourceStatus> for domain::ResourceStatus {
8484
phase: value.phase.into(),
8585
observed_generation: value.observed_generation.map(Into::into),
8686
reconciled_at: value.reconciled_at,
87-
conditions: value.conditions.map(|conditions| conditions.0),
87+
conditions: value.conditions.0,
8888
}
8989
}
9090
}

src/domain/resources/facade/src/facade/graphql/cynic_api/fragments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub(crate) struct ResourceStatus {
218218
pub phase: ResourcePhase,
219219
pub observed_generation: Option<Uint64>,
220220
pub reconciled_at: Option<DateTime<Utc>>,
221-
pub conditions: Option<ResourceConditions>,
221+
pub conditions: ResourceConditions,
222222
}
223223

224224
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/domain/resources/facade/src/facade/graphql/cynic_api/inputs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ impl ResourceTypeSelectorInput {
3737
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3838

3939
#[derive(cynic::InputObject, Debug, Clone)]
40-
#[cynic(graphql_type = "ResourceAccountByIdAndNameInput")]
41-
pub(crate) struct ResourceAccountByIdAndNameInput {
40+
#[cynic(graphql_type = "AccountHandleInput")]
41+
pub(crate) struct AccountHandleInput {
4242
pub id: odf::AccountID,
4343
pub name: AccountName,
4444
}
@@ -48,16 +48,16 @@ pub(crate) struct ResourceAccountByIdAndNameInput {
4848
pub(crate) enum ResourceAccountSelectorInput {
4949
ById(odf::AccountID),
5050
ByName(AccountName),
51-
Both(ResourceAccountByIdAndNameInput),
51+
Handle(AccountHandleInput),
5252
}
5353

5454
impl From<&domain::ResourceAccountRef> for ResourceAccountSelectorInput {
5555
fn from(value: &domain::ResourceAccountRef) -> Self {
5656
match value {
5757
domain::ResourceAccountRef::Id(id) => Self::ById(id.clone()),
5858
domain::ResourceAccountRef::Name(name) => Self::ByName(AccountName(name.to_string())),
59-
domain::ResourceAccountRef::Both { id, name } => {
60-
Self::Both(ResourceAccountByIdAndNameInput {
59+
domain::ResourceAccountRef::Handle(odf::metadata::auth::AccountHandle { id, name }) => {
60+
Self::Handle(AccountHandleInput {
6161
id: id.clone(),
6262
name: AccountName(name.to_string()),
6363
})

src/domain/resources/facade/src/facade/local/helpers/manifest_support.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ pub(crate) fn resource_view_to_manifest(
9898
let schema = kamu_resources::ResourceSchemaId::parse(schema.as_str()).int_err()?;
9999

100100
let account = Some(match headers.account.name {
101-
Some(name) => kamu_resources::ResourceAccountRef::Both {
102-
id: headers.account.id,
103-
name,
104-
},
101+
Some(name) => {
102+
kamu_resources::ResourceAccountRef::Handle(odf::metadata::auth::AccountHandle {
103+
id: headers.account.id,
104+
name,
105+
})
106+
}
105107
None => kamu_resources::ResourceAccountRef::Id(headers.account.id),
106108
});
107109

src/domain/resources/facade/src/facade/local/resource_account_resolver_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use internal_error::ResultIntoInternal;
1313
use kamu_accounts::{AccountService, CurrentAccountSubject};
1414
use kamu_auth_rebac::{RebacService, RebacServiceExt};
1515
use kamu_resources::ResourceAccountRef;
16+
use odf::metadata::auth::AccountHandle;
1617

1718
use crate::{ResolveManifestAccountError, ResolvedAccount, ResourceAccountResolver};
1819

@@ -77,7 +78,7 @@ impl ResourceAccountResolverImpl {
7778
name: account.account_name,
7879
})
7980
}
80-
ResourceAccountRef::Both { id, name } => {
81+
ResourceAccountRef::Handle(AccountHandle { id, name }) => {
8182
let account = self
8283
.account_service
8384
.get_account_by_id(id)

src/domain/resources/services/src/testing/base_resource_service_harness.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ impl BaseResourceServiceHarness {
245245
let condition_name = condition_key.to_string();
246246
let cond_value = resource_status
247247
.conditions
248-
.as_ref()
249-
.unwrap_or_else(|| panic!("status conditions must be present"))
250248
.entries
251249
.get(condition_key)
252250
.unwrap_or_else(|| panic!("{condition_name} condition must be present in status"));

0 commit comments

Comments
 (0)