read AWS secret key from stdin instead of command line

This commit is contained in:
Stefan Reitshamer 2017-02-03 17:23:13 -05:00
parent bda692313f
commit 3bd7f247c9
2 changed files with 12 additions and 9 deletions

View file

@ -139,7 +139,7 @@
NSString *oAuth2RedirectURI = nil;
if ([targetType isEqualToString:@"aws"]) {
if ([args count] != 6) {
if ([args count] != 5) {
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid arguments");
return NO;
}
@ -149,7 +149,10 @@
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) {
@ -259,7 +262,7 @@
}
NSString *theComputerUUID = [args objectAtIndex:3];
NSString *theEncryptionPassword = [self readEncryptionPassword:error];
NSString *theEncryptionPassword = [self readPasswordWithPrompt:@"enter encryption password:" error:error];
if (theEncryptionPassword == nil) {
return NO;
}
@ -301,7 +304,7 @@
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;
}
@ -353,7 +356,7 @@
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;
}
@ -441,7 +444,7 @@
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;
}
@ -773,8 +776,8 @@
#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;

View file

@ -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");