Skip to content

Commit

Permalink
read AWS secret key from stdin instead of command line
Browse files Browse the repository at this point in the history
  • Loading branch information
sreitshamer committed Feb 3, 2017
1 parent bda6923 commit 3bd7f24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions ArqRestoreCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (BOOL)addTarget:(NSArray *)args error:(NSError **)error {
NSString *oAuth2RedirectURI = nil;

if ([targetType isEqualToString:@"aws"]) {
if ([args count] != 6) {
if ([args count] != 5) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid arguments");
return NO;
}
Expand All @@ -149,7 +149,10 @@ - (BOOL)addTarget:(NSArray *)args error:(NSError **)error {
NSString *urlString = [NSString stringWithFormat:@"https://%@@%@/any_bucket", accessKeyId, [[usEast1 s3EndpointWithSSL:NO] host]];

endpoint = [NSURL URLWithString:urlString];
secret = [args objectAtIndex:5];
secret = [self readPasswordWithPrompt:@"enter AWS secret key:" error:error];
if (secret == nil) {
return NO;
}

} else if ([targetType isEqualToString:@"local"]) {
if ([args count] != 5) {
Expand Down Expand Up @@ -259,7 +262,7 @@ - (BOOL)listFolders:(NSArray *)args error:(NSError **)error {
}

NSString *theComputerUUID = [args objectAtIndex:3];
NSString *theEncryptionPassword = [self readEncryptionPassword:error];
NSString *theEncryptionPassword = [self readPasswordWithPrompt:@"enter encryption password:" error:error];
if (theEncryptionPassword == nil) {
return NO;
}
Expand Down Expand Up @@ -301,7 +304,7 @@ - (BOOL)printPlist:(NSArray *)args error:(NSError **)error {
NSString *theComputerUUID = [args objectAtIndex:3];
NSString *theBucketUUID = [args objectAtIndex:4];

NSString *theEncryptionPassword = [self readEncryptionPassword:error];
NSString *theEncryptionPassword = [self readPasswordWithPrompt:@"enter encryption password:" error:error];
if (theEncryptionPassword == nil) {
return NO;
}
Expand Down Expand Up @@ -353,7 +356,7 @@ - (BOOL)listTree:(NSArray *)args error:(NSError **)error {
NSString *theComputerUUID = [args objectAtIndex:3];
NSString *theBucketUUID = [args objectAtIndex:4];

NSString *theEncryptionPassword = [self readEncryptionPassword:error];
NSString *theEncryptionPassword = [self readPasswordWithPrompt:@"enter encryption password:" error:error];
if (theEncryptionPassword == nil) {
return NO;
}
Expand Down Expand Up @@ -441,7 +444,7 @@ - (BOOL)restore:(NSArray *)args error:(NSError **)error {
NSString *theComputerUUID = [args objectAtIndex:3];
NSString *theBucketUUID = [args objectAtIndex:4];

NSString *theEncryptionPassword = [self readEncryptionPassword:error];
NSString *theEncryptionPassword = [self readPasswordWithPrompt:@"enter encryption password:" error:error];
if (theEncryptionPassword == nil) {
return NO;
}
Expand Down Expand Up @@ -773,8 +776,8 @@ - (BOOL)glacierRestorerDidFail:(NSError *)error {


#pragma mark internal
- (NSString *)readEncryptionPassword:(NSError **)error {
printf("enter encryption password: ");
- (NSString *)readPasswordWithPrompt:(NSString *)thePrompt error:(NSError **)error {
printf("%s ", [thePrompt UTF8String]);
fflush(stdout);

struct termios oldTermios;
Expand Down
2 changes: 1 addition & 1 deletion arq_restore.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
static void printUsage(const char *exeName) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s [-l loglevel] listtargets\n", exeName);
fprintf(stderr, "\t%s [-l loglevel] addtarget <nickname> aws <access_key> <secret_key> \n", exeName);
fprintf(stderr, "\t%s [-l loglevel] addtarget <nickname> aws <access_key>\n", exeName);
fprintf(stderr, "\t%s [-l loglevel] addtarget <nickname> local <path>\n", exeName);
fprintf(stderr, "\t%s [-l loglevel] deletetarget <nickname>\n", exeName);
fprintf(stderr, "\n");
Expand Down

0 comments on commit 3bd7f24

Please sign in to comment.