Unverified Commit 36f67c5f authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add AwsEndpointResolver when constructing operations (#198)

* Add AwsEndpointResolver when constructing operations

This commit adds a customization for AWS-services to allow specifying an EndpointResolver, with a default fallback provided.

* Enforce no doc warnings, fix bug, add cargoCheck to CI
parent e499bbd9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -147,6 +147,8 @@ jobs:
      # docs are not included in the artifact; this step validates that they can be generated
    - name: Generate docs
      run: ./gradlew :aws:sdk:cargoDocs
    - name: Run tests
      run: ./gradlew :aws:sdk:cargoTest
    - name: Get current date
      id: date
      run: echo "name=${GITHUB_REF##*/}-$(date +'%Y-%m-%d')" >> $GITHUB_ENV
+9 −3
Original line number Diff line number Diff line
@@ -26,6 +26,12 @@ pub struct AwsEndpoint {
    signing_region: Option<SigningRegion>,
}

impl AwsEndpoint {
    pub fn set_endpoint(&self, mut uri: &mut http::Uri, endpoint_prefix: Option<&EndpointPrefix>) {
        self.endpoint.set_endpoint(&mut uri, endpoint_prefix);
    }
}

pub type BoxError = Box<dyn Error + Send + Sync + 'static>;

/// Resolve the AWS Endpoint for a given region
@@ -109,7 +115,7 @@ fn get_endpoint_resolver(config: &PropertyBag) -> Option<&AwsEndpointResolver> {
    config.get()
}

pub fn set_endpoint_resolver(provider: AwsEndpointResolver, config: &mut PropertyBag) {
pub fn set_endpoint_resolver(config: &mut PropertyBag, provider: AwsEndpointResolver) {
    config.insert(provider);
}

@@ -117,7 +123,7 @@ pub fn set_endpoint_resolver(provider: AwsEndpointResolver, config: &mut Propert
///
/// AwsEndpointStage implements [`MapRequest`](smithy_http::middleware::MapRequest). It will:
/// 1. Load an endpoint provider from the property bag.
/// 2. Load an endpoint given the [`Region`](aws_types::Region) in the property bag.
/// 2. Load an endpoint given the [`Region`](aws_types::region::Region) in the property bag.
/// 3. Apply the endpoint to the URI in the request
/// 4. Set the `SigningRegion` and `SigningService` in the property bag to drive downstream
/// signing middleware.
@@ -188,7 +194,7 @@ mod test {
        {
            let mut conf = req.config_mut();
            conf.insert(region.clone());
            set_endpoint_resolver(provider, &mut conf);
            set_endpoint_resolver(&mut conf, provider);
        };
        let req = AwsEndpointStage.apply(req).expect("should succeed");
        assert_eq!(
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ mod test {
            .augment(|req, conf| {
                conf.insert(region.clone());
                conf.insert(UNIX_EPOCH + Duration::new(1611160427, 0));
                set_endpoint_resolver(provider, conf);
                set_endpoint_resolver(conf, provider);
                Result::<_, Infallible>::Ok(req)
            })
            .expect("succeeds");
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,12 @@ impl Region {
    }
}

impl From<&str> for Region {
    fn from(region: &str) -> Self {
        Region(Arc::new(region.to_string()))
    }
}

/// Provide a [`Region`](Region) to use with AWS requests
///
/// For most cases [`default_provider`](default_provider) will be the best option, implementing
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ group = "software.amazon.software.amazon.smithy.rust.codegen.smithy"
version = "0.1.0"

val smithyVersion: String by project
val kotestVersion: String by project

dependencies {
    implementation(project(":codegen"))
@@ -24,6 +25,7 @@ dependencies {
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
    testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
    testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
}

tasks.compileKotlin {
Loading