Skip to content

Commit

Permalink
v4-sign: Extract service mod
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 30, 2024
1 parent 371466e commit ff23de0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions v4-sign/src/lib.rs
@@ -1,4 +1,5 @@
mod request_type;
mod service;
mod signing_algorithm;

use std::{
Expand All @@ -9,6 +10,8 @@ use std::{
use request_type::RequestType;
use signing_algorithm::SigningAlgorithm;

use crate::service::Service;

#[derive(Debug, thiserror::Error)]
enum Error {
#[error("FIXME: {0}")]
Expand Down Expand Up @@ -41,7 +44,7 @@ fn construct_credential_scope(
) -> String {
let date = request_timestamp.format("%Y%m%d").to_string();
let location = region; // e.g. "us-central1";
let service = "storage";
let service = Service::Storage.as_str();
let request_type = RequestType::Goog4Request.as_str();
format!("{date}/{location}/{service}/{request_type}")
}
Expand Down Expand Up @@ -344,7 +347,7 @@ UNSIGNED-PAYLOAD
let credential_scope = {
let date = date_time.format("%Y%m%d").to_string();
let location = "us-central1";
let service = "storage";
let service = Service::Storage.as_str();
let request_type = RequestType::Goog4Request.as_str();
format!("{date}/{location}/{service}/{request_type}")
};
Expand Down
27 changes: 27 additions & 0 deletions v4-sign/src/service.rs
@@ -0,0 +1,27 @@
/// <https://cloud.google.com/storage/docs/authentication/signatures?hl=ja#credential-scope>
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum Service {
Storage,
S3,
}

impl Service {
pub(crate) fn as_str(&self) -> &'static str {
match self {
Self::Storage => "storage",
Self::S3 => "s3",
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test() {
use Service::*;
assert_eq!(Storage.as_str(), "storage");
assert_eq!(S3.as_str(), "s3");
}
}

0 comments on commit ff23de0

Please sign in to comment.