@@ -602,3 +602,83 @@ impl PolicyData {
602
602
} ]
603
603
}
604
604
}
605
+
606
+ /// A registration token
607
+ #[ derive( Serialize , JsonSchema ) ]
608
+ pub struct UserRegistrationToken {
609
+ #[ serde( skip) ]
610
+ id : Ulid ,
611
+
612
+ /// The token string
613
+ token : String ,
614
+
615
+ /// Maximum number of times this token can be used
616
+ usage_limit : Option < u32 > ,
617
+
618
+ /// Number of times this token has been used
619
+ times_used : u32 ,
620
+
621
+ /// When the token was created
622
+ created_at : DateTime < Utc > ,
623
+
624
+ /// When the token was last used. If null, the token has never been used.
625
+ last_used_at : Option < DateTime < Utc > > ,
626
+
627
+ /// When the token expires. If null, the token never expires.
628
+ expires_at : Option < DateTime < Utc > > ,
629
+
630
+ /// When the token was revoked. If null, the token is not revoked.
631
+ revoked_at : Option < DateTime < Utc > > ,
632
+ }
633
+
634
+ impl From < mas_data_model:: UserRegistrationToken > for UserRegistrationToken {
635
+ fn from ( token : mas_data_model:: UserRegistrationToken ) -> Self {
636
+ Self {
637
+ id : token. id ,
638
+ token : token. token ,
639
+ usage_limit : token. usage_limit ,
640
+ times_used : token. times_used ,
641
+ created_at : token. created_at ,
642
+ last_used_at : token. last_used_at ,
643
+ expires_at : token. expires_at ,
644
+ revoked_at : token. revoked_at ,
645
+ }
646
+ }
647
+ }
648
+
649
+ impl Resource for UserRegistrationToken {
650
+ const KIND : & ' static str = "user-registration_token" ;
651
+ const PATH : & ' static str = "/api/admin/v1/user-registration-tokens" ;
652
+
653
+ fn id ( & self ) -> Ulid {
654
+ self . id
655
+ }
656
+ }
657
+
658
+ impl UserRegistrationToken {
659
+ /// Samples of registration tokens
660
+ pub fn samples ( ) -> [ Self ; 2 ] {
661
+ [
662
+ Self {
663
+ id : Ulid :: from_bytes ( [ 0x01 ; 16 ] ) ,
664
+ token : "abc123def456" . to_owned ( ) ,
665
+ usage_limit : Some ( 10 ) ,
666
+ times_used : 5 ,
667
+ created_at : DateTime :: default ( ) ,
668
+ last_used_at : Some ( DateTime :: default ( ) ) ,
669
+ expires_at : Some ( DateTime :: default ( ) + chrono:: Duration :: days ( 30 ) ) ,
670
+ revoked_at : None ,
671
+ } ,
672
+ Self {
673
+ id : Ulid :: from_bytes ( [ 0x02 ; 16 ] ) ,
674
+ token : "xyz789abc012" . to_owned ( ) ,
675
+ usage_limit : None ,
676
+ times_used : 0 ,
677
+ created_at : DateTime :: default ( ) ,
678
+ last_used_at : None ,
679
+ expires_at : None ,
680
+ revoked_at : Some ( DateTime :: default ( ) ) ,
681
+ } ,
682
+ ]
683
+ }
684
+ }
0 commit comments