Add FLIPPER_PORTS env var to iOS SDK

Summary:
Part 2 of changing flipper to use customizable ports: iOS SDK.
Still to go: JS app.

env var should be of the format:

`FLIPPER_PORTS=1111,2222` for insecure port: 1111 and secure port: 2222.

Reviewed By: danielbuechele

Differential Revision: D13800988

fbshipit-source-id: 3560ba850389964f4b784551b803c45c6524e6f0
This commit is contained in:
John Knox
2019-01-24 06:46:49 -08:00
committed by Facebook Github Bot
parent 823f9cac63
commit 74d0ecac1b
3 changed files with 51 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
#include "SKStateUpdateCPPWrapper.h" #include "SKStateUpdateCPPWrapper.h"
#import "FlipperDiagnosticsViewController.h" #import "FlipperDiagnosticsViewController.h"
#import "FlipperClient+Testing.h" #import "FlipperClient+Testing.h"
#import "SKEnvironmentVariables.h"
#if !TARGET_OS_SIMULATOR #if !TARGET_OS_SIMULATOR
#import <FKPortForwarding/FKPortForwardingServer.h> #import <FKPortForwarding/FKPortForwardingServer.h>
@@ -82,7 +83,9 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
[privateAppDirectory UTF8String], [privateAppDirectory UTF8String],
}, },
sonarThread.getEventBase(), sonarThread.getEventBase(),
connectionThread.getEventBase() connectionThread.getEventBase(),
[SKEnvironmentVariables getInsecurePort],
[SKEnvironmentVariables getSecurePort]
}); });
_cppClient = facebook::flipper::FlipperClient::instance(); _cppClient = facebook::flipper::FlipperClient::instance();
} catch (const std::system_error &e) { } catch (const std::system_error &e) {

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#ifdef FB_SONARKIT_ENABLED
/*
* This class exists to retreive configuration values stored in environment variables.
*/
@interface SKEnvironmentVariables : NSObject
+ (int)getInsecurePort;
+ (int)getSecurePort;
@end
#endif

View File

@@ -0,0 +1,30 @@
#ifdef FB_SONARKIT_ENABLED
#import "SKEnvironmentVariables.h"
static int const DEFAULT_INSECURE_PORT = 8089;
static int const DEFAULT_SECURE_PORT = 8088;
@implementation SKEnvironmentVariables
+ (int)getInsecurePort {
NSString *envVar = [self getFlipperPortsVariable];
return [self extractIntFromPropValue:envVar atIndex:0 withDefault:DEFAULT_INSECURE_PORT];
}
+ (int)getSecurePort {
NSString *envVar = [self getFlipperPortsVariable];
return [self extractIntFromPropValue:envVar atIndex:1 withDefault:DEFAULT_SECURE_PORT];
}
+ (int)extractIntFromPropValue:(NSString *)propValue atIndex:(int)index withDefault:(int)fallback {
NSArray<NSString *> *components = [propValue componentsSeparatedByString:@","];
NSString *component = [components objectAtIndex:index];
int envInt = [component intValue];
return envInt > 0 ? envInt : fallback;
}
+ (NSString *)getFlipperPortsVariable {
NSString *value = NSProcessInfo.processInfo.environment[@"FLIPPER_PORTS"];
return value;
}
@end
#endif