Skip to content

Commit

Permalink
release 2.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
timzaak committed Jun 25, 2024
1 parent 733d7d4 commit 3a8b683
Show file tree
Hide file tree
Showing 31 changed files with 605 additions and 209 deletions.
19 changes: 2 additions & 17 deletions .github/workflows/spa-client-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- os: macos-latest
name: mac-spa-client
bash: make release-client-mac
- os: windows-latest
- os: windows-latest
name: windows-spa-client
bash: make release-client-win
runs-on: ${{ matrix.settings.os }}
Expand All @@ -29,21 +29,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ matrix.settings.os }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ matrix.settings.os }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- uses: Swatinem/rust-cache@v2
- name: Setup MUSL
if: matrix.settings.os == 'ubuntu-latest'
run: |
Expand All @@ -53,7 +39,6 @@ jobs:
- name: Build Release
run: ${{ matrix.settings.bash }}


- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down
19 changes: 1 addition & 18 deletions .github/workflows/spa-server-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,11 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- uses: Swatinem/rust-cache@v2
- name: Setup MUSL
run: |
rustup target add x86_64-unknown-linux-musl
sudo apt-get -qq install musl-tools
- name: Build Release Linux
run: make release-linux-server-musl

Expand Down
27 changes: 6 additions & 21 deletions .github/workflows/spa-server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,16 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: build all
run: cargo build
- name: run spa-client test
run: cargo test -p spa-client
- name: run spa-client test
run: cargo test -p spa-server
- uses: Swatinem/rust-cache@v2
- name: run integration test
# --show-output
run: cargo test -p tests --test starter -j 1 -- --test-threads 1
- name: run pebble
run: ./run_pebble.sh
working-directory: ./tests/bash/
- name: run acme integration test
run: cargo test -p tests --test acme_test -j 1 -- --test-threads 1
run: cargo test -p tests --test acme_test -j 1 -- --test-threads 1
- name: run spa-client test
run: cargo test -p spa-client
- name: run spa-client test
run: cargo test -p spa-server
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spa-client"
version = "2.2.3"
version = "2.2.4"
edition = "2021"
authors = ["timzaak"]
license = "MIT"
Expand Down
26 changes: 21 additions & 5 deletions client/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::Config;
use anyhow::anyhow;
use reqwest::{header, multipart, StatusCode};
use spa_server::admin_server::request::{
DeleteDomainVersionOption, DomainWithOptVersionOption, GetDomainOption,
UpdateUploadingStatusOption,
};
use spa_server::domain_storage::{DomainInfo, ShortMetaData, UploadDomainPosition};
use spa_server::admin_server::request::{DeleteDomainVersionOption, DomainWithOptVersionOption, DomainWithVersionOption, GetDomainOption, UpdateUploadingStatusOption};
use spa_server::domain_storage::{CertInfo, DomainInfo, ShortMetaData, UploadDomainPosition};
use std::borrow::Cow;
use std::path::PathBuf;

Expand Down Expand Up @@ -129,6 +126,19 @@ impl API {
handle!(resp)
}

pub async fn revoke_version(&self, domain:String, version:u32) -> anyhow::Result<()> {
let resp = self
.async_client
.post(self.url("files/revoke_version"))
.json(&DomainWithVersionOption {
domain,
version,
})
.send()
.await?;
handle!(resp)
}

//TODO: use thiserror instead of anyhow
pub async fn upload_file<T: Into<Cow<'static, str>>>(
&self,
Expand Down Expand Up @@ -185,6 +195,12 @@ impl API {
.await?;
json_resp!(resp, UploadDomainPosition)
}

pub async fn get_acme_cert_info(&self, domain: Option<String>) -> anyhow::Result<Vec<CertInfo>> {
let resp = self.async_client.get(self.url("cert/acme"))
.query(&GetDomainOption{domain}).send().await?;
json_resp!(resp, Vec<CertInfo>)
}
}
#[cfg(test)]
mod test {
Expand Down
15 changes: 15 additions & 0 deletions client/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub enum Commands {
domain: Option<String>,
max_reserve: Option<u32>,
},
Revoke {
domain: String,
version: u32,
}
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -116,4 +120,15 @@ mod test {
unreachable!()
}
}

#[test]
fn revoke_version() {
let c = CliCommand::parse_from(&["test", "revoke", "www.example.com", "1"]);
if let Commands::Revoke {domain, version} = c.commands {
assert_eq!(domain, "www.example.com".to_string());
assert_eq!(version, 1);
} else {
unreachable!()
}
}
}
4 changes: 4 additions & 0 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ async fn run_with_commands(commands: CliCommand) -> anyhow::Result<()> {
api.remove_files(domain, max_reserve).await?;
success("delete success!");
}
Commands::Revoke {domain, version} => {
api.revoke_version(domain, version).await?;
success("revoke success!");
}
};
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion config.release.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ file_dir = "/data"
// # directory to store account and certificate
// # optional, default is ${file_dir}/acme
// // dir = "/data/acme"
// # ci / stage / prod, default is prod
// # ci / stage / prod, default is prod, ci is just for CI test with Pebble, don't use it.
// //type = prod
// }

Expand Down
8 changes: 8 additions & 0 deletions docs/develop/change-log.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Change Log

### Version 2.2.4

- feat: add cert query API (no doc, no client SDK support)
- improve: add check when upload of multiple/single domain
- ci: improve GitHub Action speed
- feat: add revoke version API (release JS SDK 2.2.4)

### Version 2.2.3
- fix: sub_path '' => '/', like GitHub pages
- fix: redirect with no querystring
Expand Down
29 changes: 24 additions & 5 deletions docs/guide/spa-server-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ number of files.

```shell

curl "http://$ADMIN_SERVER/files/metadata?domain=$DOMAIN&version=$VERSION" -H "Authorization: Bearer $TOKEN"
curl "$ADMIN_SERVER/files/metadata?domain=$DOMAIN&version=$VERSION" -H "Authorization: Bearer $TOKEN"
# return [{path:$path_string,md5:$md5_string, length: $file_length_integer}]
```

Expand All @@ -105,7 +105,7 @@ curl "http://$ADMIN_SERVER/files/metadata?domain=$DOMAIN&version=$VERSION" -H "A
```shell
UPLOADING_STATUS=0 # Uploading:0, Finish:1

curl --location --request POST "http://$ADMIN_SERVER/files/upload_status" \
curl --location --request POST "$ADMIN_SERVER/files/upload_status" \
--header "Authorization: Bearer $TOKEN" \
--header 'Content-Type: application/json' \
--data-raw `{
Expand All @@ -122,7 +122,7 @@ The http body is `multipart/form-data` format.

```shell
PATH="/upload/file/path"
curl -X POST "http://$ADMIN_SERVER/file/upload?domain=$domain&version=$version&path=$PATH" \
curl -X POST "$ADMIN_SERVER/file/upload?domain=$domain&version=$version&path=$PATH" \
-F "file=@$PATH" -H "Authorization: Bearer $TOKEN"
# return status code:200 if success
```
Expand All @@ -131,11 +131,30 @@ curl -X POST "http://$ADMIN_SERVER/file/upload?domain=$domain&version=$version&p

```shell
# keep 2 versions.
MAX_RESERVE = 1
MAX_RESERVE_OPT = 1
curl -X POST "http://$ADMIN_SERVER/files/delete" \
-H "Authorization: Bearer $TOKEN" \
--data-raw `{
"domain":$DOMAIN,
"max_reserve": $MAX_RESERVE
"max_reserve": $MAX_RESERVE_OPT
}`
# return status code:200 if success
```

### Revoke version
**Attention: revoke version now is temp, when you reload or restart server, then It would use the max version.**
```shell
TARGET_VERSION=1
curl -X POST "$ADMIN_SERVER/files/revoke_version" \
-H "Authorization: Bearer $TOKEN" \
--data-raw `{
"domain":$DOMAIN,
"version": $TARGET_VERSION
}`
```

### Get Cert version
```shell
curl -X POST "$ADMIN_SERVER/cert?domain=$DOMAIN_OPT" \
- H "Authorization: Bearer $TOKEN"
```
2 changes: 1 addition & 1 deletion docs/guide/spa-server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ file_dir = "/data"
// # directory to store account and certificate
// # optional, default is ${file_dir}/acme
// // dir = "/data/acme"
// # ci / stage / prod, default is prod
// # ci / stage / prod, default is prod, ci is just for CI test with Pebble, don't use it.
// //type = prod
// }
Expand Down
2 changes: 1 addition & 1 deletion jsclient/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spa-client",
"version": "2.2.2",
"version": "2.2.4",
"description": "js sdk for spa-server",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
19 changes: 17 additions & 2 deletions jsclient/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,29 @@ const deleteCmd = command({
})
}
})
const revokeVersionCmd = command({
name: 'revoke',
args: {
domain,
version,
config: configDirOption
},
handler({domain, version, config}) {
writeResult(async() => {
const client = await getClient(config)
await client.revokeVersion(domain, version)
return "revoke successful"
})
}
})


export const cmd = subcommands({
name: 'spa-client',
description: 'js command line for spa-server',
version: Version,
cmds: {info, upload, release, reload, delete: deleteCmd}
cmds: {info, upload, release, reload, delete: deleteCmd, revoke: revokeVersionCmd}
})
export default function runCommand() {
run(binary(cmd), process.argv)
}
}
12 changes: 12 additions & 0 deletions jsclient/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export interface UploadDomainPositionResp {
status: GetDomainPositionStatus
}

export interface CertInfoResp {
begin: string,
end: string,
host: string,
}

export interface ShortMetaData {
path: string
md5: string
Expand Down Expand Up @@ -202,6 +208,12 @@ export default class SPAClient {
params: {domain, format: 'Json'}
}).then(resp<UploadDomainPositionResp>)
}
public revokeVersion(domain:String, version: number) {
return this.http.post(`/files/revoke_version`, {domain, version}).then(emptyResp)
}
public getCertInfo(domain?:string) {
return this.http.get('/cert/acme', {params: {domain}}).then(resp<CertInfoResp[]>)
}
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spa-server-doc",
"version": "2.2.3",
"version": "2.2.4",
"description": "This is for docs powered by VitePress",
"private": true,
"type": "module",
Expand Down
Loading

0 comments on commit 3a8b683

Please sign in to comment.