fn build()

in core/src/services/ghac/backend.rs [144:228]


    fn build(self) -> Result<impl Access> {
        debug!("backend build started: {:?}", self);

        let root = normalize_root(&self.config.root.unwrap_or_default());
        debug!("backend use root {}", root);

        let service_version = get_cache_service_version();
        debug!("backend use service version {:?}", service_version);

        let mut version = self
            .config
            .version
            .clone()
            .unwrap_or_else(|| "opendal".to_string());
        debug!("backend use version {version}");
        // ghac requires to use hex digest of Sha256 as version.
        if matches!(service_version, GhacVersion::V2) {
            let hash = sha2::Sha256::digest(&version);
            version = format!("{:x}", hash);
        }

        let cache_url = self
            .config
            .endpoint
            .unwrap_or_else(|| get_cache_service_url(service_version));
        if cache_url.is_empty() {
            return Err(Error::new(
                ErrorKind::ConfigInvalid,
                "cache url for ghac not found, maybe not in github action environment?".to_string(),
            ));
        }

        let core = GhacCore {
            info: {
                let am = AccessorInfo::default();
                am.set_scheme(Scheme::Ghac)
                    .set_root(&root)
                    .set_name(&version)
                    .set_native_capability(Capability {
                        stat: true,
                        stat_has_cache_control: true,
                        stat_has_content_length: true,
                        stat_has_content_type: true,
                        stat_has_content_encoding: true,
                        stat_has_content_range: true,
                        stat_has_etag: true,
                        stat_has_content_md5: true,
                        stat_has_last_modified: true,
                        stat_has_content_disposition: true,

                        read: true,

                        write: true,
                        write_can_multi: true,

                        shared: true,

                        ..Default::default()
                    });

                // allow deprecated api here for compatibility
                #[allow(deprecated)]
                if let Some(client) = self.http_client {
                    am.update_http_client(|_| client);
                }

                am.into()
            },
            root,

            cache_url,
            catch_token: value_or_env(
                self.config.runtime_token,
                ACTIONS_RUNTIME_TOKEN,
                "Builder::build",
            )?,
            version,

            service_version,
        };

        Ok(GhacBackend {
            core: Arc::new(core),
        })
    }