-
Notifications
You must be signed in to change notification settings - Fork 94
Use environment variables to initialize client and server #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
XavierGeerinck
merged 6 commits into
dapr:master
from
shubham1172:shubham1172/use-env-vars-in-client
Feb 22, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9fb9fb
Use environment variables with default for DaprClient
shubham1172 afb3b26
Make GRPCClient and HTTPClient configurable with envvars
shubham1172 1003044
lint constructor args
shubham1172 e0140cc
Make DaprServer configurable with envvars
shubham1172 3728bcc
Add tests
shubham1172 3a46b2c
Refactor based on review comments
shubham1172 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,57 @@ | ||
import CommunicationProtocolEnum from "../enum/CommunicationProtocol.enum"; | ||
|
||
export class Settings { | ||
private static readonly defaultHost: string = "127.0.0.1"; | ||
private static readonly defaultHttpAppPort: string = "3000"; | ||
private static readonly defaultHttpPort: string = "3500"; | ||
private static readonly defaultGrpcAppPort: string = "50000"; | ||
private static readonly defaultGrpcPort: string = "50001"; | ||
|
||
static getDefaultHost(): string { | ||
return Settings.defaultHost; | ||
} | ||
|
||
static getDefaultHttpPort(): string { | ||
return process.env.DAPR_HTTP_PORT ?? Settings.defaultHttpPort; | ||
} | ||
|
||
static getDefaultGrpcPort(): string { | ||
return process.env.DAPR_GRPC_PORT ?? Settings.defaultGrpcPort; | ||
} | ||
|
||
/** | ||
* Gets the default port that the Dapr sidecar is listening to. | ||
* @param communicationProtocolEnum communication protocol | ||
* @returns port number | ||
*/ | ||
static getDefaultPort(communicationProtocolEnum: CommunicationProtocolEnum): string { | ||
switch (communicationProtocolEnum) { | ||
case CommunicationProtocolEnum.GRPC: | ||
return this.getDefaultGrpcPort(); | ||
default: | ||
return this.getDefaultHttpPort(); | ||
} | ||
} | ||
|
||
static getDefaultHttpAppPort(): string { | ||
return process.env.APP_PORT ?? Settings.defaultHttpAppPort; | ||
} | ||
|
||
static getDefaultGrpcAppPort(): string { | ||
return process.env.APP_PORT ?? Settings.defaultGrpcAppPort; | ||
} | ||
|
||
/** | ||
* Gets the default port that the application is listening on. | ||
* @param communicationProtocolEnum communication protocol | ||
* @returns port number | ||
*/ | ||
static getDefaultAppPort(communicationProtocolEnum: CommunicationProtocolEnum): string { | ||
switch (communicationProtocolEnum) { | ||
case CommunicationProtocolEnum.GRPC: | ||
return this.getDefaultGrpcAppPort(); | ||
default: | ||
return this.getDefaultHttpAppPort(); | ||
} | ||
} | ||
} |
This file contains hidden or 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,25 @@ | ||
import { CommunicationProtocolEnum } from "../../../src"; | ||
import { Settings } from "../../../src/utils/Settings.util"; | ||
|
||
describe('Settings', () => { | ||
describe('getDefaultPort returns the correct default when', () => { | ||
it('communication protocol is GRPC', () => { | ||
expect(Settings.getDefaultPort(CommunicationProtocolEnum.GRPC)) | ||
.toEqual(Settings.getDefaultGrpcPort()) | ||
}); | ||
it('communication protocol is HTTP', () => { | ||
expect(Settings.getDefaultPort(CommunicationProtocolEnum.HTTP)) | ||
.toEqual(Settings.getDefaultHttpPort()) | ||
}); | ||
}); | ||
describe('getDefaultAppPort returns the correct default when', () => { | ||
it('communication protocol is GRPC', () => { | ||
expect(Settings.getDefaultAppPort(CommunicationProtocolEnum.GRPC)) | ||
.toEqual(Settings.getDefaultGrpcAppPort()) | ||
}); | ||
it('communication protocol is HTTP', () => { | ||
expect(Settings.getDefaultAppPort(CommunicationProtocolEnum.HTTP)) | ||
.toEqual(Settings.getDefaultHttpAppPort()) | ||
}); | ||
}); | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.