mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
👌 Improved nginx file parsing
This commit is contained in:
@ -1520,7 +1520,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 785;
|
CURRENT_PROJECT_VERSION = 786;
|
||||||
DEBUG = YES;
|
DEBUG = YES;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@ -1546,7 +1546,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 785;
|
CURRENT_PROJECT_VERSION = 786;
|
||||||
DEBUG = NO;
|
DEBUG = NO;
|
||||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
@ -37,43 +37,43 @@ class NginxConfigurationTest: XCTestCase {
|
|||||||
func testCanDetermineSiteNameAndTld() throws {
|
func testCanDetermineSiteNameAndTld() throws {
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
"nginx-site",
|
"nginx-site",
|
||||||
NginxConfiguration(filePath: NginxConfigurationTest.regularUrl.path).domain
|
NginxConfiguration.from(filePath: NginxConfigurationTest.regularUrl.path)?.domain
|
||||||
)
|
)
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
"test",
|
"test",
|
||||||
NginxConfiguration(filePath: NginxConfigurationTest.regularUrl.path).tld
|
NginxConfiguration.from(filePath: NginxConfigurationTest.regularUrl.path)?.tld
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCanDetermineIsolation() throws {
|
func testCanDetermineIsolation() throws {
|
||||||
XCTAssertNil(
|
XCTAssertNil(
|
||||||
NginxConfiguration(filePath: NginxConfigurationTest.regularUrl.path).isolatedVersion
|
NginxConfiguration.from(filePath: NginxConfigurationTest.regularUrl.path)?.isolatedVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
"8.1",
|
"8.1",
|
||||||
NginxConfiguration(filePath: NginxConfigurationTest.isolatedUrl.path).isolatedVersion
|
NginxConfiguration.from(filePath: NginxConfigurationTest.isolatedUrl.path)?.isolatedVersion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCanDetermineProxy() throws {
|
func testCanDetermineProxy() throws {
|
||||||
let proxied = NginxConfiguration(filePath: NginxConfigurationTest.proxyUrl.path)
|
let proxied = NginxConfiguration.from(filePath: NginxConfigurationTest.proxyUrl.path)!
|
||||||
XCTAssertTrue(proxied.contents.contains("# valet stub: proxy.valet.conf"))
|
XCTAssertTrue(proxied.contents.contains("# valet stub: proxy.valet.conf"))
|
||||||
XCTAssertEqual("http://127.0.0.1:90", proxied.proxy)
|
XCTAssertEqual("http://127.0.0.1:90", proxied.proxy)
|
||||||
|
|
||||||
let normal = NginxConfiguration(filePath: NginxConfigurationTest.regularUrl.path)
|
let normal = NginxConfiguration.from(filePath: NginxConfigurationTest.regularUrl.path)!
|
||||||
XCTAssertFalse(normal.contents.contains("# valet stub: proxy.valet.conf"))
|
XCTAssertFalse(normal.contents.contains("# valet stub: proxy.valet.conf"))
|
||||||
XCTAssertEqual(nil, normal.proxy)
|
XCTAssertEqual(nil, normal.proxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCanDetermineSecuredProxy() throws {
|
func testCanDetermineSecuredProxy() throws {
|
||||||
let proxied = NginxConfiguration(filePath: NginxConfigurationTest.secureProxyUrl.path)
|
let proxied = NginxConfiguration.from(filePath: NginxConfigurationTest.secureProxyUrl.path)!
|
||||||
XCTAssertTrue(proxied.contents.contains("# valet stub: secure.proxy.valet.conf"))
|
XCTAssertTrue(proxied.contents.contains("# valet stub: secure.proxy.valet.conf"))
|
||||||
XCTAssertEqual("http://127.0.0.1:90", proxied.proxy)
|
XCTAssertEqual("http://127.0.0.1:90", proxied.proxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCanDetermineProxyWithCustomTld() throws {
|
func testCanDetermineProxyWithCustomTld() throws {
|
||||||
let proxied = NginxConfiguration(filePath: NginxConfigurationTest.customTldProxyUrl.path)
|
let proxied = NginxConfiguration.from(filePath: NginxConfigurationTest.customTldProxyUrl.path)!
|
||||||
XCTAssertTrue(proxied.contents.contains("# valet stub: secure.proxy.valet.conf"))
|
XCTAssertTrue(proxied.contents.contains("# valet stub: secure.proxy.valet.conf"))
|
||||||
XCTAssertEqual("http://localhost:8080", proxied.proxy)
|
XCTAssertEqual("http://localhost:8080", proxied.proxy)
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,30 @@ class NginxConfiguration {
|
|||||||
/** The TLD of the domain, usually derived from the name of the file. */
|
/** The TLD of the domain, usually derived from the name of the file. */
|
||||||
var tld: String
|
var tld: String
|
||||||
|
|
||||||
init(filePath: String) {
|
static func from(filePath: String) -> NginxConfiguration? {
|
||||||
let path = filePath.replacingOccurrences(
|
let path = filePath.replacingOccurrences(
|
||||||
of: "~",
|
of: "~",
|
||||||
with: "/Users/\(Paths.whoami)"
|
with: "/Users/\(Paths.whoami)"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.contents = try! String(contentsOfFile: path)
|
do {
|
||||||
|
let fileContents = try String(contentsOfFile: path)
|
||||||
|
return NginxConfiguration.init(
|
||||||
|
path: path,
|
||||||
|
contents: fileContents
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
Log.warn("Could not read the nginx configuration file at: `\(filePath)`")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(path: String, contents: String) {
|
||||||
let domain = String(path.split(separator: "/").last!)
|
let domain = String(path.split(separator: "/").last!)
|
||||||
let tld = String(domain.split(separator: ".").last!)
|
let tld = String(domain.split(separator: ".").last!)
|
||||||
|
|
||||||
self.domain = domain
|
self.contents = contents
|
||||||
.replacingOccurrences(of: ".\(tld)", with: "")
|
self.domain = domain.replacingOccurrences(of: ".\(tld)", with: "")
|
||||||
self.tld = tld
|
self.tld = tld
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,8 @@ class ValetProxyScanner: ProxyScanner {
|
|||||||
return try! FileManager
|
return try! FileManager
|
||||||
.default
|
.default
|
||||||
.contentsOfDirectory(atPath: directoryPath)
|
.contentsOfDirectory(atPath: directoryPath)
|
||||||
.filter {
|
.compactMap {
|
||||||
// Skip .DS_Store files
|
return NginxConfiguration.from(filePath: "\(directoryPath)/\($0)")
|
||||||
return $0 != ".DS_Store"
|
|
||||||
}
|
|
||||||
.map {
|
|
||||||
return NginxConfiguration.init(filePath: "\(directoryPath)/\($0)")
|
|
||||||
}
|
}
|
||||||
.filter {
|
.filter {
|
||||||
return $0.proxy != nil
|
return $0.proxy != nil
|
||||||
|
@ -226,8 +226,8 @@ class ValetSite: DomainListable {
|
|||||||
public static func isolatedVersion(_ filePath: String) -> String? {
|
public static func isolatedVersion(_ filePath: String) -> String? {
|
||||||
if Filesystem.fileExists(filePath) {
|
if Filesystem.fileExists(filePath) {
|
||||||
return NginxConfiguration
|
return NginxConfiguration
|
||||||
.init(filePath: filePath)
|
.from(filePath: filePath)?
|
||||||
.isolatedVersion
|
.isolatedVersion ?? nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user