Skip to content

Commit 12c5571

Browse files
Added -[RMQConnection updateSecret:]
1 parent 78de90d commit 12c5571

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

RMQClient/RMQConnection.h

+8
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,12 @@
242242
*/
243243
- (nonnull id<RMQChannel>)createChannel;
244244

245+
/*!
246+
* @brief Update secret.
247+
* This method updates the secret used to authenticate this connection.
248+
* It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.
249+
* @param secret The new secret.
250+
*/
251+
- (void)updateSecret:(NSString *)secret;
252+
245253
@end

RMQClient/RMQConnection.m

+14
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ - (void)start {
608608
return ch;
609609
}
610610

611+
- (void)updateSecret:(NSString *)secret
612+
{
613+
[self.commandQueue enqueue:^{
614+
[self sendFrameset:[[RMQFrameset alloc] initWithChannelNumber:@0 method:[self methodForUpdateSecret:secret]]];
615+
}];
616+
}
617+
611618
- (BOOL)hasCompletedHandshake {
612619
return self.handshakeComplete;
613620
}
@@ -746,6 +753,13 @@ - (void)closeAllUserChannels {
746753
}
747754
}
748755

756+
- (RMQConnectionUpdateSecret *)methodForUpdateSecret:(NSString *)secret {
757+
RMQLongstr *secretLongstr = [[RMQLongstr alloc] init:secret];
758+
RMQShortstr *reason = [[RMQShortstr alloc] init:@"ObjC client needs it"];
759+
return [[RMQConnectionUpdateSecret alloc] initWithSecret:secretLongstr
760+
reason:reason];
761+
}
762+
749763
- (RMQConnectionClose *)amqClose {
750764
return [[RMQConnectionClose alloc] initWithReplyCode:[[RMQShort alloc] init:200]
751765
replyText:[[RMQShortstr alloc] init:@"Goodbye"]

RMQClient/RMQMethodMap.m

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ + (NSDictionary *)methodMap {
5858
@[@(10), @(51)] : [RMQConnectionCloseOk class],
5959
@[@(10), @(60)] : [RMQConnectionBlocked class],
6060
@[@(10), @(61)] : [RMQConnectionUnblocked class],
61+
@[@(10), @(70)] : [RMQConnectionUpdateSecret class],
62+
@[@(10), @(71)] : [RMQConnectionUpdateSecretOk class],
6163
@[@(20), @(10)] : [RMQChannelOpen class],
6264
@[@(20), @(11)] : [RMQChannelOpenOk class],
6365
@[@(20), @(20)] : [RMQChannelFlow class],

RMQClient/RMQMethods.h

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ typedef NS_OPTIONS(NSUInteger, RMQConnectionOpenOptions) {
126126
@end
127127
@interface RMQConnectionUnblocked : RMQValue <RMQMethod>
128128

129+
@end
130+
@interface RMQConnectionUpdateSecret : RMQValue <RMQMethod>
131+
@property (nonnull, copy, nonatomic, readonly) RMQLongstr *secret;
132+
@property (nonnull, copy, nonatomic, readonly) RMQShortstr *reason;
133+
- (nonnull instancetype)initWithSecret:(nonnull RMQLongstr *)secret
134+
reason:(nonnull RMQShortstr *)reason;
135+
@end
136+
@interface RMQConnectionUpdateSecretOk : RMQValue <RMQMethod>
137+
129138
@end
130139
@interface RMQChannelOpen : RMQValue <RMQMethod>
131140
@property (nonnull, copy, nonatomic, readonly) RMQShortstr *reserved1;

RMQClient/RMQMethods.m

+91
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,97 @@ - (NSNumber *)frameTypeID { return @1; }
679679
- (BOOL)hasContent { return NO; }
680680

681681

682+
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
683+
self = [super init];
684+
if (self) {
685+
self.payloadArguments = @[];
686+
}
687+
return self;
688+
}
689+
690+
- (NSData *)amqEncoded {
691+
NSMutableData *encoded = [NSMutableData new];
692+
[encoded appendData:[[RMQShort alloc] init:self.classID.integerValue].amqEncoded];
693+
[encoded appendData:[[RMQShort alloc] init:self.methodID.integerValue].amqEncoded];
694+
for (id<RMQEncodable>arg in self.payloadArguments) {
695+
[encoded appendData:arg.amqEncoded];
696+
}
697+
return encoded;
698+
}
699+
700+
@end
701+
702+
@interface RMQConnectionUpdateSecret ()
703+
@property (nonnull, copy, nonatomic, readwrite) RMQLongstr *secret;
704+
@property (nonnull, copy, nonatomic, readwrite) RMQShortstr *reason;
705+
@property (nonatomic, readwrite) NSArray *payloadArguments;
706+
@property (nonatomic, readwrite) BOOL hasContent;
707+
@end
708+
709+
@implementation RMQConnectionUpdateSecret
710+
711+
+ (NSArray *)propertyClasses {
712+
return @[[RMQLongstr class],
713+
[RMQShortstr class]];
714+
}
715+
- (NSNumber *)classID { return @10; }
716+
- (NSNumber *)methodID { return @70; }
717+
- (Class)syncResponse { return [RMQConnectionUpdateSecretOk class]; }
718+
- (NSNumber *)frameTypeID { return @1; }
719+
- (BOOL)hasContent { return NO; }
720+
721+
- (nonnull instancetype)initWithSecret:(nonnull RMQLongstr *)secret
722+
reason:(nonnull RMQShortstr *)reason {
723+
self = [super init];
724+
if (self) {
725+
self.secret = secret;
726+
self.reason = reason;
727+
self.payloadArguments = @[self.secret,
728+
self.reason];
729+
}
730+
return self;
731+
}
732+
733+
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
734+
self = [super init];
735+
if (self) {
736+
self.secret = ((RMQLongstr *)frame[0]);
737+
self.reason = ((RMQShortstr *)frame[1]);
738+
self.payloadArguments = @[self.secret,
739+
self.reason];
740+
}
741+
return self;
742+
}
743+
744+
- (NSData *)amqEncoded {
745+
NSMutableData *encoded = [NSMutableData new];
746+
[encoded appendData:[[RMQShort alloc] init:self.classID.integerValue].amqEncoded];
747+
[encoded appendData:[[RMQShort alloc] init:self.methodID.integerValue].amqEncoded];
748+
for (id<RMQEncodable>arg in self.payloadArguments) {
749+
[encoded appendData:arg.amqEncoded];
750+
}
751+
return encoded;
752+
}
753+
754+
@end
755+
756+
@interface RMQConnectionUpdateSecretOk ()
757+
@property (nonatomic, readwrite) NSArray *payloadArguments;
758+
@property (nonatomic, readwrite) BOOL hasContent;
759+
@end
760+
761+
@implementation RMQConnectionUpdateSecretOk
762+
763+
+ (NSArray *)propertyClasses {
764+
return @[];
765+
}
766+
- (NSNumber *)classID { return @10; }
767+
- (NSNumber *)methodID { return @71; }
768+
- (Class)syncResponse { return nil; }
769+
- (NSNumber *)frameTypeID { return @1; }
770+
- (BOOL)hasContent { return NO; }
771+
772+
682773
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
683774
self = [super init];
684775
if (self) {

codegen/amqp0-9-1.extended.xml

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
WARNING: Modified from the official 0-9-1 specification XML by
55
the addition of:
66
confirm.select and confirm.select-ok,
7+
connection.update-secret and connection.update-secret-ok,
78
exchange.bind and exchange.bind-ok,
89
exchange.unbind and exchange.unbind-ok,
910
basic.nack,
@@ -914,6 +915,35 @@
914915
<chassis name = "server" implement = "MUST"/>
915916
<chassis name = "client" implement = "MUST"/>
916917
</method>
918+
919+
<method name = "update-secret" synchronous = "1" index = "70" label = "update secret">
920+
<doc>
921+
This method updates the secret used to authenticate this connection. It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.
922+
</doc>
923+
924+
<chassis name = "client" implement = "MUST" />
925+
<response name = "update-secret-ok" />
926+
927+
<field name = "secret" domain = "longstr">
928+
<doc>
929+
The new secret.
930+
</doc>
931+
</field>
932+
933+
<field name = "reason" domain = "shortstr">
934+
<doc>
935+
The reason for the secret update.
936+
</doc>
937+
</field>
938+
</method>
939+
940+
<method name = "update-secret-ok" synchronous = "1" index = "71" label = "update secret response">
941+
<doc>
942+
This method confirms the updated secret is valid.
943+
</doc>
944+
<chassis name = "server" implement = "MUST" />
945+
</method>
946+
917947
</class>
918948

919949
<!-- == CHANNEL ========================================================== -->

0 commit comments

Comments
 (0)