-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backport: some fixes for the deployer (#2782)
- Loading branch information
1 parent
f0c2d72
commit 1df3b0e
Showing
16 changed files
with
95 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import "jest-extended"; | ||
|
||
import { isWhitelisted } from "../../../packages/core-utils/src"; | ||
|
||
describe("isWhitelisted", () => { | ||
it("should allow everyone", () => { | ||
expect(isWhitelisted(["*"], "127.0.0.1")).toBeTrue(); | ||
expect(isWhitelisted(["*"], "192.168.1.1")).toBeTrue(); | ||
expect(isWhitelisted(["*"], "168.1.1.1")).toBeTrue(); | ||
}); | ||
|
||
it("should allow addresses with prefixes", () => { | ||
expect(isWhitelisted(["127.*"], "127.0.0.1")).toBeTrue(); | ||
expect(isWhitelisted(["127.*"], "127.0.0.2")).toBeTrue(); | ||
expect(isWhitelisted(["127.*"], "128.0.0.1")).toBeFalse(); | ||
}); | ||
|
||
it("should allow addresses with suffixes", () => { | ||
expect(isWhitelisted(["*.127"], "1.1.1.127")).toBeTrue(); | ||
expect(isWhitelisted(["*.127"], "1.1.1.127")).toBeTrue(); | ||
expect(isWhitelisted(["*.127"], "1.1.1.128")).toBeFalse(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import nm from "nanomatch"; | ||
|
||
export const isWhitelisted = (whitelist: string[], remoteAddress: string): boolean => { | ||
if (!Array.isArray(whitelist) || !whitelist.length) { | ||
return true; | ||
} | ||
|
||
if (Array.isArray(whitelist)) { | ||
for (const ip of whitelist) { | ||
try { | ||
if (nm.isMatch(remoteAddress, ip)) { | ||
return true; | ||
} | ||
} catch { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import { Container, Logger } from "@arkecosystem/core-interfaces"; | ||
import { isWhitelisted } from "@arkecosystem/core-utils"; | ||
import ip from "ip"; | ||
import { defaults } from "./defaults"; | ||
import { startServer } from "./server"; | ||
|
||
export const plugin: Container.IPluginDescriptor = { | ||
pkg: require("../package.json"), | ||
defaults, | ||
alias: "wallet-api", | ||
depends: "@arkecosystem/core-api", | ||
async register(container: Container.IContainer, options) { | ||
if (!options.enabled) { | ||
if (!isWhitelisted(container.resolveOptions("api").whitelist, ip.address())) { | ||
container.resolvePlugin<Logger.ILogger>("logger").info("Wallet API is disabled"); | ||
|
||
return undefined; | ||
} | ||
|
||
container.resolvePlugin<Logger.ILogger>("logger").info("Starting Wallet API"); | ||
return startServer(options.server); | ||
}, | ||
async deregister(container: Container.IContainer, options) { | ||
if (options.enabled) { | ||
try { | ||
container.resolvePlugin<Logger.ILogger>("logger").info("Stopping Wallet API"); | ||
|
||
await container.resolvePlugin("wallet-api").stop(); | ||
} catch (error) { | ||
// do nothing... | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters