-
Notifications
You must be signed in to change notification settings - Fork 66
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
simple config, env and cli #247
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fbd21d2
simple config, env and cli
aniketfuryrocks a2697b5
fix comp
aniketfuryrocks 056b760
init env first
aniketfuryrocks 119f0e6
added env override
aniketfuryrocks 1df1b4b
postgres config
aniketfuryrocks c4a85db
fmt
aniketfuryrocks 60fd282
updated env in readme
aniketfuryrocks a0f9101
examples
aniketfuryrocks a880a53
a
aniketfuryrocks 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 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,34 @@ | ||
## LiteRpc | ||
LITE_RPC_HTTP_ADDR=http://0.0.0.0:8890 | ||
LITE_RPC_WS_ADDR=[::]:8891 | ||
|
||
## RPC | ||
RPC_ADDR=http://0.0.0.0:8899 | ||
WS_ADDR=ws://0.0.0.0:8900 | ||
# IDENTITY=your_identity_keypair_here | ||
|
||
## Prometheus | ||
# PROMETHEUS_ADDR=your_prometheus_address_here | ||
|
||
## Fanout size and retries configuration | ||
FANOUT_SIZE=18 | ||
MAX_RETRIES=40 | ||
RETRY_TIMEOUT=3 | ||
|
||
## Quic Proxy | ||
# QUIC_PROXY_ADDR=your_quic_proxy_address_here | ||
|
||
## gRPC Configuration | ||
USE_GRPC=false | ||
GRPC_ADDR=http://127.0.0.0:10000 | ||
# GRPC_X_TOKEN=your_grpc_token_here | ||
|
||
## Postgres Configuration | ||
# PG_ENABLED=true | ||
# PG_CONFIG=your_postgres_config_here | ||
# CA_PEM_B64=your_base64_encoded_ca_pem_here | ||
# CLIENT_PKS_B64=your_base64_encoded_client_pks_here | ||
# CLIENT_PKS_PASS=your_client_pks_password_here | ||
|
||
## Gso | ||
# DISABLE_GSO=your_disable_gso_setting_here |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
{ | ||
"rpc_addr": "http://0.0.0.0:8899", | ||
"ws_addr": "ws://0.0.0.0:8900", | ||
"lite_rpc_http_addr": "http://0.0.0.0:8890", | ||
"lite_rpc_ws_addr": "[::]:8891", | ||
"fanout_size": 18, | ||
"identity_keypair": null, | ||
"prometheus_addr": "[::]:9091", | ||
"maximum_retries_per_tx": 40, | ||
"transaction_retry_after_secs": 3, | ||
"quic_proxy_addr": null, | ||
"use_grpc": false, | ||
"grpc_addr": "http://127.0.0.0:10000", | ||
"grpc_x_token": null, | ||
"postgres": { | ||
"pg_config": "your_postgres_config", | ||
"ssl": { | ||
"ca_pem_b64": "your_base64_encoded_ca_pem", | ||
"client_pks_b64": "your_base64_encoded_client_pks", | ||
"client_pks_pass": "your_client_pks_password" | ||
} | ||
} | ||
} |
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,26 +1,25 @@ | ||
use anyhow::Context; | ||
use solana_sdk::signature::Keypair; | ||
use std::env; | ||
|
||
// note this is duplicated from lite-rpc module | ||
pub async fn load_identity_keypair(identity_from_cli: &String) -> Option<Keypair> { | ||
if let Ok(identity_env_var) = env::var("IDENTITY") { | ||
if let Ok(identity_bytes) = serde_json::from_str::<Vec<u8>>(identity_env_var.as_str()) { | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} else { | ||
// must be a file | ||
let identity_file = tokio::fs::read_to_string(identity_env_var.as_str()) | ||
.await | ||
.expect("Cannot find the identity file provided"); | ||
let identity_bytes: Vec<u8> = serde_json::from_str(&identity_file).unwrap(); | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} | ||
} else if identity_from_cli.is_empty() { | ||
None | ||
} else { | ||
let identity_file = tokio::fs::read_to_string(identity_from_cli.as_str()) | ||
pub async fn load_identity_keypair( | ||
identity_from_cli: Option<String>, | ||
) -> anyhow::Result<Option<Keypair>> { | ||
let identity_str = if let Some(identity_from_cli) = identity_from_cli { | ||
tokio::fs::read_to_string(identity_from_cli) | ||
.await | ||
.expect("Cannot find the identity file provided"); | ||
let identity_bytes: Vec<u8> = serde_json::from_str(&identity_file).unwrap(); | ||
Some(Keypair::from_bytes(identity_bytes.as_slice()).unwrap()) | ||
} | ||
.context("Cannot find the identity file provided")? | ||
} else if let Ok(identity_env_var) = env::var("IDENTITY") { | ||
identity_env_var | ||
} else { | ||
return Ok(None); | ||
}; | ||
|
||
let identity_bytes: Vec<u8> = | ||
serde_json::from_str(&identity_str).context("Invalid identity format expected Vec<u8>")?; | ||
|
||
Ok(Some( | ||
Keypair::from_bytes(identity_bytes.as_slice()).context("Invalid identity")?, | ||
)) | ||
} |
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,3 +1,4 @@ | ||
pub mod postgres_block; | ||
pub mod postgres_config; | ||
pub mod postgres_session; | ||
pub mod postgres_transaction; |
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,52 @@ | ||
use anyhow::Context; | ||
use std::env; | ||
use tokio_postgres::config::SslMode; | ||
|
||
#[derive(serde::Deserialize, Debug, Clone)] | ||
pub struct PostgresSessionConfig { | ||
pub pg_config: String, | ||
pub ssl: Option<PostgresSessionSslConfig>, | ||
} | ||
|
||
#[derive(serde::Deserialize, Debug, Clone)] | ||
pub struct PostgresSessionSslConfig { | ||
pub ca_pem_b64: String, | ||
pub client_pks_b64: String, | ||
pub client_pks_pass: String, | ||
} | ||
|
||
impl PostgresSessionConfig { | ||
pub fn new_from_env() -> anyhow::Result<Option<Self>> { | ||
// pg not enabled | ||
if env::var("PG_ENABLED").is_err() { | ||
return Ok(None); | ||
} | ||
|
||
let env_pg_config = env::var("PG_CONFIG").context("PG_CONFIG not found")?; | ||
|
||
let ssl_config = if env_pg_config | ||
.parse::<tokio_postgres::Config>()? | ||
.get_ssl_mode() | ||
.eq(&SslMode::Disable) | ||
{ | ||
None | ||
} else { | ||
let env_ca_pem_b64 = env::var("CA_PEM_B64").context("CA_PEM_B64 not found")?; | ||
let env_client_pks_b64 = | ||
env::var("CLIENT_PKS_B64").context("CLIENT_PKS_B64 not found")?; | ||
let env_client_pks_pass = | ||
env::var("CLIENT_PKS_PASS").context("CLIENT_PKS_PASS not found")?; | ||
|
||
Some(PostgresSessionSslConfig { | ||
ca_pem_b64: env_ca_pem_b64, | ||
client_pks_b64: env_client_pks_b64, | ||
client_pks_pass: env_client_pks_pass, | ||
}) | ||
}; | ||
|
||
Ok(Some(Self { | ||
pg_config: env_pg_config, | ||
ssl: ssl_config, | ||
})) | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should provide a config file example instead of environment variables.