Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ offer-service:
cert-path: "/etc/ssl/certs/offer-cert.pem"
# Path to TLS private key file
key-path: "/etc/ssl/certs/offer-key.pem"

# max page size for get all queries
max-page-size: 100
```

#### Authentication Setup
Expand Down
4 changes: 2 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Mitigate overload and certain DOS attacks with rate limiting:
* per-session (ip-based) rate limit per endpoint
* configurable individual max and session limits for each endpoint

#### Paging for Offer GET Endpoint
#### ~~Paging for Offer GET Endpoint~~ DONE

GET endpoints for Discovery and Offer Services that return a list need paging. For REST: `?page={page}` query parameter. The CLI will need a --page parameter.
~~GET endpoints for Discovery and Offer Services that return a list need paging. For REST: `?page={page}` query parameter. The CLI will need a --page parameter.~~

#### ~~PATCH Method for Discovery~~ DONE

Expand Down
28 changes: 28 additions & 0 deletions doc/offer-service-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ paths:
required: true
schema:
type: string
- name: start
in: query
required: false
schema:
type: integer
minimum: 0
default: 0
description: Offset for pagination (starting index)
- name: count
in: query
required: false
schema:
type: integer
description: Maximum number of offers to return (page size)
responses:
'200':
description: List of offers
Expand Down Expand Up @@ -188,6 +202,20 @@ paths:
required: true
schema:
type: string
- name: start
in: query
required: false
schema:
type: integer
minimum: 0
default: 0
description: Offset for pagination (starting index)
- name: count
in: query
required: false
schema:
type: integer
description: Maximum number of metadata entries to return (page size)
responses:
'200':
description: List of metadata
Expand Down
1 change: 1 addition & 0 deletions server/config/memory-basic-no-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ discovery-service:
offer-service:
auth-authority: "${OFFER_SERVICE_AUTH_AUTHORITY_PATH:-/etc/ssl/certs/offer-auth-authority.pem}"
address: "${OFFER_SERVICE_ADDRESS:-127.0.0.1:8082}"
max-page-size: 100

store:
offer:
Expand Down
1 change: 1 addition & 0 deletions server/config/memory-basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ offer-service:
tls:
cert-path: "${OFFER_SERVICE_TLS_CERT_PATH:-/etc/ssl/certs/offer-cert.pem}"
key-path: "${OFFER_SERVICE_TLS_KEY_PATH:-/etc/ssl/certs/offer-key.pem}"
max-page-size: 100

store:
offer:
Expand Down
3 changes: 2 additions & 1 deletion server/config/mixed-persistence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ offer-service:
tls:
cert-path: "${OFFER_SERVICE_TLS_CERT_PATH:-/etc/ssl/certs/offer-cert.pem}"
key-path: "${OFFER_SERVICE_TLS_KEY_PATH:-/etc/ssl/certs/offer-key.pem}"

max-page-size: 100

store:
offer:
type: "database"
Expand Down
3 changes: 2 additions & 1 deletion server/config/offers-standalone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ offer-service:
tls:
cert-path: "${OFFER_SERVICE_TLS_CERT_PATH:-/etc/ssl/certs/offer-cert.pem}"
key-path: "${OFFER_SERVICE_TLS_KEY_PATH:-/etc/ssl/certs/offer-key.pem}"

max-page-size: 100

# Storage configuration
store:
offer:
Expand Down
3 changes: 2 additions & 1 deletion server/config/sqlite-persistent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ offer-service:
tls:
cert-path: "${OFFER_SERVICE_TLS_CERT_PATH:-/etc/ssl/certs/offer-cert.pem}"
key-path: "${OFFER_SERVICE_TLS_KEY_PATH:-/etc/ssl/certs/offer-key.pem}"

max-page-size: 100

store:
offer:
type: "database"
Expand Down
12 changes: 10 additions & 2 deletions server/src/commands/offer/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ pub enum OfferMetadataManagementCommands {
Get {
/// Partition name
partition: String,
/// Optional offer metadata uuid, default returns all offers for partition
/// Optional offer metadata uuid, default returns all metadata for partition
id: Option<Uuid>,
/// Start position when returning multiple metadata
#[arg(short, long, conflicts_with = "id", default_value_t = 0)]
start: usize,
/// Count position when returning multiple metadata
#[arg(short, long, conflicts_with = "id", default_value_t = 100)]
count: usize,
/// Optional output metadata path, defaults to stdout
#[arg(short, long)]
output: Option<PathBuf>,
Expand Down Expand Up @@ -103,6 +109,8 @@ pub fn new_metadata(partition: &str, text: &str, output: Option<&Path>) -> anyho
pub async fn get_metadata(
partition: &str,
id: Option<&Uuid>,
start: usize,
count: usize,
output: Option<&Path>,
client_configuration: &OfferManagementClientConfig,
) -> anyhow::Result<()> {
Expand All @@ -126,7 +134,7 @@ pub async fn get_metadata(
bail!("Metadata {id} not found");
}
} else {
let metadata = client.get_all_metadata(partition).await?;
let metadata = client.get_all_metadata(partition, start, count).await?;
let metadata = metadata
.into_iter()
.map(|metadata| OfferMetadataRest {
Expand Down
10 changes: 9 additions & 1 deletion server/src/commands/offer/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub enum OfferRecordManagementCommands {
partition: String,
/// Optional offer uuid, default returns all offers for partition
id: Option<Uuid>,
/// Start position when returning multiple offers
#[arg(short, long, conflicts_with = "id", default_value_t = 0)]
start: usize,
/// Count when returning multiple offers
#[arg(short, long, conflicts_with = "id", default_value_t = 100)]
count: usize,
/// Optional output path, defaults to stdout
#[arg(short, long)]
output: Option<PathBuf>,
Expand Down Expand Up @@ -107,6 +113,8 @@ pub fn new_offer(partition: &str, metadata_id: &Uuid, output: Option<&Path>) ->
pub async fn get_offer(
partition: &str,
id: Option<&Uuid>,
start: usize,
count: usize,
output: Option<&Path>,
client_configuration: &OfferManagementClientConfig,
) -> anyhow::Result<()> {
Expand All @@ -130,7 +138,7 @@ pub async fn get_offer(
bail!("Offer {id} not found");
}
} else {
let offers = client.get_offers(partition).await?;
let offers = client.get_offers(partition, start, count).await?;
let offers = offers
.into_iter()
.map(|offer| OfferRecordRest {
Expand Down
1 change: 1 addition & 0 deletions server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct OfferServiceConfig {
pub address: SocketAddr,
pub auth_authority: PathBuf,
pub tls: Option<TlsConfig>,
pub max_page_size: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
8 changes: 6 additions & 2 deletions server/src/di/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ impl OfferStore for OfferStoreDelegate {
async fn get_offers(
&self,
partition: &str,
start: usize,
count: usize,
) -> Result<Vec<switchgear_service::api::offer::OfferRecord>, Self::Error> {
delegate_to_offer_store_variants!(self, get_offers, partition).await
delegate_to_offer_store_variants!(self, get_offers, partition, start, count).await
}

async fn post_offer(
Expand Down Expand Up @@ -150,8 +152,10 @@ impl OfferMetadataStore for OfferStoreDelegate {
async fn get_all_metadata(
&self,
partition: &str,
start: usize,
count: usize,
) -> Result<Vec<switchgear_service::api::offer::OfferMetadata>, Self::Error> {
delegate_to_offer_store_variants!(self, get_all_metadata, partition).await
delegate_to_offer_store_variants!(self, get_all_metadata, partition, start, count).await
}

async fn post_metadata(
Expand Down
11 changes: 8 additions & 3 deletions server/src/di/inject/injectors/service/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ impl OfferServiceInjector {
)
})?;

let router = OfferService::router(OfferState::new(store.clone(), store, auth_authority))
.layer(ClfLogger::new("offer"))
.into_make_service_with_connect_info::<SocketAddr>();
let router = OfferService::router(OfferState::new(
store.clone(),
store,
auth_authority,
service_config.max_page_size,
))
.layer(ClfLogger::new("offer"))
.into_make_service_with_connect_info::<SocketAddr>();

let f = async move {
match acceptor {
Expand Down
8 changes: 8 additions & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ async fn _main(args: CliArgs) -> anyhow::Result<()> {
OfferRecordManagementCommands::Get {
partition,
id,
start,
count,
output,
client,
} => {
commands::offer::record::get_offer(
&partition,
id.as_ref(),
start,
count,
output.as_deref(),
&client,
)
Expand Down Expand Up @@ -175,12 +179,16 @@ async fn _main(args: CliArgs) -> anyhow::Result<()> {
OfferMetadataManagementCommands::Get {
partition,
id,
start,
count,
output,
client,
} => {
commands::offer::metadata::get_metadata(
&partition,
id.as_ref(),
start,
count,
output.as_deref(),
&client,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,36 @@ Feature: Offer CLI management
And offer details should be output

@offer-get-all
Scenario: Get all offers
Scenario Outline: Get all offers with parameters
Given the lnurl server is ready to start
When I start the lnurl server with the configuration
Then the server should start successfully
Given a valid offer JSON exists
When I run "swgr offer post" with offer JSON
When I run "swgr offer post" 10 times with offer JSON
Then the command should succeed
When I run "swgr offer get"
When I run "swgr offer get" with parameters "<parameters>"
Then the command should succeed
And all offers should be output

Examples:
| parameters |
| |
| --start 1 |
| --count 5 |
| --start 1 --count 1 |

@offer-get-all-bounds-error
Scenario: Get all offers with count exceeding limit
Given the lnurl server is ready to start
When I start the lnurl server with the configuration
Then the server should start successfully
Given a valid offer JSON exists
When I run "swgr offer post" 10 times with offer JSON
Then the command should succeed
When I run "swgr offer get --count 101"
Then the command should fail
And a user error message should be shown

@offer-put
Scenario: Update an offer
Given the lnurl server is ready to start
Expand Down Expand Up @@ -118,17 +137,36 @@ Feature: Offer CLI management
And offer metadata details should be output

@offer-metadata-get-all
Scenario: Get all offer metadata
Scenario Outline: Get all offer metadata with parameters
Given the lnurl server is ready to start
When I start the lnurl server with the configuration
Then the server should start successfully
Given a valid offer metadata JSON exists
When I run "swgr offer metadata post" with metadata JSON
When I run "swgr offer metadata post" 10 times with metadata JSON
Then the command should succeed
When I run "swgr offer metadata get"
When I run "swgr offer metadata get" with parameters "<parameters>"
Then the command should succeed
And all offer metadata should be output

Examples:
| parameters |
| |
| --start 1 |
| --count 5 |
| --start 1 --count 1 |

@offer-metadata-get-all-bounds-error
Scenario: Get all offer metadata with count exceeding limit
Given the lnurl server is ready to start
When I start the lnurl server with the configuration
Then the server should start successfully
Given a valid offer metadata JSON exists
When I run "swgr offer metadata post" 10 times with metadata JSON
Then the command should succeed
When I run "swgr offer metadata get --count 101"
Then the command should fail
And a user error message should be shown

@offer-metadata-put
Scenario: Update offer metadata
Given the lnurl server is ready to start
Expand Down
Loading