Skip to content

Commit

Permalink
Merge pull request #3 from jakewilkins/arch_dependent_dependencies
Browse files Browse the repository at this point in the history
Architecture dependent dependencies
  • Loading branch information
jakewilkins authored Jan 26, 2024
2 parents 5a9dff5 + 31bc126 commit 63dc6d3
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ jobs:
create_release:
runs-on: ubuntu-latest
needs: [build_arm, build_armv7, build_macos, build_x86_64]
if: github.ref == 'refs/heads/main'
steps:
- name: Create release
id: create_release
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "github-device-flow"
version = "0.1.4"
version = "0.2.0"
edition = "2021"
description = "Binary and library for performing the GitHub Device Flow"
license = "MIT"
Expand All @@ -16,4 +16,3 @@ serde = "1.0.143"
serde_derive = "1.0.143"
serde_json = "1.0"
clap = { version = "3.2.17", features = ["derive"] }
openssl = { version = "0.10.41", features = ["vendored"] }
19 changes: 19 additions & 0 deletions Cargo.vendored_tls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "github-device-flow"
version = "0.1.4"
edition = "2021"
description = "Binary and library for performing the GitHub Device Flow"
license = "MIT"
exclude = ["/script"]
repository = "https://github.com/jakewilkins/gh-device-flow"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json", "native-tls-vendored"] }
chrono = "0.4.26"
serde = "1.0.143"
serde_derive = "1.0.143"
serde_json = "1.0"
clap = { version = "3.2.17", features = ["derive"] }

6 changes: 6 additions & 0 deletions script/build-arm
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

source ./script/openssl-dep-tools.sh

trap reset EXIT

setup

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:arm-musleabihf cargo build --release

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:arm-musleabihf musl-strip /home/rust/src/target/arm-unknown-linux-musleabihf/release/github-device-flow
6 changes: 6 additions & 0 deletions script/build-armv7
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

source ./script/openssl-dep-tools.sh

trap reset EXIT

setup

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf cargo build --release

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf musl-strip /home/rust/src/target/armv7-unknown-linux-musleabihf/release/github-device-flow
6 changes: 6 additions & 0 deletions script/build-x86_64
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

source ./script/openssl-dep-tools.sh

trap reset EXIT

setup

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:x86_64-musl cargo build --release

docker run --rm -v "$(pwd)":/home/rust/src messense/rust-musl-cross:x86_64-musl musl-strip /home/rust/src/target/x86_64-unknown-linux-musl/release/github-device-flow
22 changes: 22 additions & 0 deletions script/openssl-dep-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function swp() {
local tmp=${1##*/}
mv "$1" "${tmp%.*}$2"
}

function reset() {
echo "Exiting"
if [ -f ./Cargo.bak ]; then
echo "Resetting Cargo.toml"
swp Cargo.toml .vendored_tls
swp Cargo.bak .toml
else
echo "Not resetting Cargo.toml"
fi
}

function setup() {
echo "Setting up Cargo.toml for arm build"
swp Cargo.toml .bak
swp Cargo.vendored_tls .toml
}

41 changes: 41 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,44 @@ fn refresh_access_token(client_id: &str, refresh_token: &str, maybe_host: Option
Ok(credential.clone())
}
}

#[cfg(test)]
mod tests {
use crate::{Credential};
use chrono::offset::Utc;
use chrono::{DateTime, Duration};

#[test]
fn credential_expiry_is_expired_returns_false_when_expiry_is_in_the_future() {
let expires_in = Duration::seconds(28800);
let mut expiry: DateTime<Utc> = Utc::now();
expiry = expiry + expires_in;
let calculated_expiry = expiry.to_rfc3339();

let credential = Credential {
token: String::from("irrelevant"),
expiry: calculated_expiry,
refresh_token: String::from("irrelevant"),
};

eprintln!("{:?}", credential);

assert_eq!(true, credential.is_expired());
}

#[test]
fn credential_expiry_is_expired_returns_true_when_expiry_is_in_the_past() {
let expires_in = Duration::seconds(42);
let mut expiry: DateTime<Utc> = Utc::now();
expiry = expiry - expires_in;
let calculated_expiry = expiry.to_rfc3339();

let credential = Credential {
token: String::from("irrelevant"),
expiry: calculated_expiry,
refresh_token: String::from("irrelevant"),
};

assert_eq!(true, credential.is_expired());
}
}

0 comments on commit 63dc6d3

Please sign in to comment.