1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
use activitystreams_vocabulary::{LinkItems, create_actor, field_access};
use crate::ActorTypes;
create_actor! {
/// A service actor that creates resource actors (such as `Repository`), exists to allow access control on creation of remote resources.
///
/// # Example
///
/// ```rust
/// use activityforge::{ActorType, Factory, context};
/// use activitystreams_vocabulary::{
/// Iri, MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name,
/// };
///
/// # fn main() {
/// let id = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ").unwrap();
/// let name = Name::try_from("final-factory").unwrap();
/// let summary = ".";
///
/// let ticket_tracker = ActorType::TicketTracker;
/// let project = ActorType::Project;
/// let team = ActorType::Team;
/// let repository = ActorType::Repository;
///
/// let controller = Iri::try_from("https://grape.fr33domlover.site/actor").unwrap();
///
/// let key_id1 = Iri::try_from("https://grape.fr33domlover.site/actor#akey1").unwrap();
/// let encoded_multibase1 = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
///
/// let key_id2 = Iri::try_from("https://grape.fr33domlover.site/actor#akey1").unwrap();
/// let encoded_multibase2 = "uhiQj9TRPf10ZYPnPPo4SYrANjZOOf3c9UVZarTamDqKBDxE";
///
/// let collaborators = Iri::try_from("https://grape.fr33domlover.site/factories/YGQotiZ/collabs").unwrap();
/// let followers = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/followers").unwrap();
/// let inbox = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/inbox").unwrap();
/// let outbox = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/outbox").unwrap();
/// let teams = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/teams").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Factory",
/// "id": "{id}",
/// "name": "{name}",
/// "summary": "{summary}",
/// "inbox": "{inbox}",
/// "outbox": "{outbox}",
/// "followers": "{followers}",
/// "assertionMethod": [
/// {{
/// "type": "Multikey",
/// "id": "{key_id1}",
/// "controller": "{controller}",
/// "publicKeyMultibase": "{encoded_multibase1}"
/// }},
/// {{
/// "type": "Multikey",
/// "id": "{key_id2}",
/// "controller": "{controller}",
/// "publicKeyMultibase": "{encoded_multibase2}"
/// }}
/// ],
/// "availableActorTypes": [
/// "{ticket_tracker}",
/// "{project}",
/// "{team}",
/// "{repository}"
/// ],
/// "collaborators": "{collaborators}",
/// "teams": "{teams}"
/// }}"#
/// );
///
/// let context = context::forgefed_context();
///
/// let multibase1 = MultibasePublicKey::new()
/// .with_header(MultibaseHeader::Base64UrlNoPad)
/// .with_key(MultikeyPublicKey::Ed25519([
/// 0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
/// 0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
/// 0x1e, 0xa2, 0x81, 0x1f,
/// ]));
///
/// let multibase2 = MultibasePublicKey::new()
/// .with_header(MultibaseHeader::Base64UrlNoPad)
/// .with_key(MultikeyPublicKey::Sm2([
/// 0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
/// 0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
/// 0x0e, 0xa2, 0x81, 0x0f, 0x11,
/// ]));
///
/// let multikey1 = Multikey::new_inner()
/// .with_id(key_id1)
/// .with_controller(controller.clone())
/// .with_public_key_multibase(multibase1);
///
/// let multikey2 = Multikey::new_inner()
/// .with_id(key_id2)
/// .with_controller(controller.clone())
/// .with_public_key_multibase(multibase2);
///
/// let factory = Factory::new()
/// .with_context_property(context)
/// .with_id(id)
/// .with_name(name)
/// .with_summary(summary)
/// .with_available_actor_types([ticket_tracker, project, team, repository])
/// .with_assertion_method([multikey1, multikey2])
/// .with_collaborators(collaborators)
/// .with_followers(followers)
/// .with_inbox(inbox)
/// .with_outbox(outbox)
/// .with_teams(teams);
///
/// assert_eq!(serde_json::to_string_pretty(&factory).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Factory>(json_str.as_str()).unwrap(),
/// factory
/// );
/// # }
/// ```
Factory: crate::ActorType::Factory {
#[serde(skip_serializing_if = "Option::is_none")]
available_actor_types: Option<ActorTypes>,
#[serde(skip_serializing_if = "Option::is_none")]
collaborators: Option<LinkItems>,
#[serde(skip_serializing_if = "Option::is_none")]
teams: Option<LinkItems>,
}
}
field_access! {
Factory {
/// Specifies the actor types that can be created via this [Factory].
available_actor_types: option_ref { ActorTypes },
/// A collection of the direct collaborators of the actor, i.e. actors that have been given a direct-Grant to it.
collaborators: option_ref { LinkItems },
/// Identifies a collection of the resources this `Team` has access to, and that it is delegating to its members and subteams.
teams: option_ref { LinkItems },
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{ActorType, context};
use activitystreams_vocabulary::{
Iri, MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name,
};
#[test]
fn test_valid() {
let id = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ").unwrap();
let name = Name::try_from("final-factory").unwrap();
let summary = ".";
let ticket_tracker = ActorType::TicketTracker;
let project = ActorType::Project;
let team = ActorType::Team;
let repository = ActorType::Repository;
let controller = Iri::try_from("https://grape.fr33domlover.site/actor").unwrap();
let key_id1 = Iri::try_from("https://grape.fr33domlover.site/actor#akey1").unwrap();
let encoded_multibase1 = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
let key_id2 = Iri::try_from("https://grape.fr33domlover.site/actor#akey1").unwrap();
let encoded_multibase2 = "uhiQj9TRPf10ZYPnPPo4SYrANjZOOf3c9UVZarTamDqKBDxE";
let collaborators =
Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/collabs").unwrap();
let followers =
Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/followers").unwrap();
let inbox = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/inbox").unwrap();
let outbox =
Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/outbox").unwrap();
let teams = Iri::try_from("https://grape.fr33domlover.site/factories/YGQoZ/teams").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Factory",
"id": "{id}",
"name": "{name}",
"summary": "{summary}",
"inbox": "{inbox}",
"outbox": "{outbox}",
"followers": "{followers}",
"assertionMethod": [
{{
"type": "Multikey",
"id": "{key_id1}",
"controller": "{controller}",
"publicKeyMultibase": "{encoded_multibase1}"
}},
{{
"type": "Multikey",
"id": "{key_id2}",
"controller": "{controller}",
"publicKeyMultibase": "{encoded_multibase2}"
}}
],
"availableActorTypes": [
"{ticket_tracker}",
"{project}",
"{team}",
"{repository}"
],
"collaborators": "{collaborators}",
"teams": "{teams}"
}}"#
);
let context = context::forgefed_context();
let multibase1 = MultibasePublicKey::new()
.with_header(MultibaseHeader::Base64UrlNoPad)
.with_key(MultikeyPublicKey::Ed25519([
0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
0x1e, 0xa2, 0x81, 0x1f,
]));
let multibase2 = MultibasePublicKey::new()
.with_header(MultibaseHeader::Base64UrlNoPad)
.with_key(MultikeyPublicKey::Sm2([
0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
0x0e, 0xa2, 0x81, 0x0f, 0x11,
]));
let multikey1 = Multikey::new_inner()
.with_id(key_id1)
.with_controller(controller.clone())
.with_public_key_multibase(multibase1);
let multikey2 = Multikey::new_inner()
.with_id(key_id2)
.with_controller(controller.clone())
.with_public_key_multibase(multibase2);
let factory = Factory::new()
.with_context_property(context)
.with_id(id)
.with_name(name)
.with_summary(summary)
.with_available_actor_types([ticket_tracker, project, team, repository])
.with_assertion_method([multikey1, multikey2])
.with_collaborators(collaborators)
.with_followers(followers)
.with_inbox(inbox)
.with_outbox(outbox)
.with_teams(teams);
assert_eq!(serde_json::to_string_pretty(&factory).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Factory>(json_str.as_str()).unwrap(),
factory
);
}
}