roctogen 0.50.0

Github API and models generated from the official swagger OpenAPI specification
Documentation
//! Method, error and parameter types for the Oidc endpoint.
#![allow(
    clippy::all
)]
/* 
 * GitHub v3 REST API
 *
 * GitHub's v3 REST API.
 *
 * OpenAPI spec version: 1.1.4
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 */

use serde::Deserialize;

use roctokit::adapters::{AdapterError, Client, GitHubRequest, GitHubResponseExt};
use crate::models::*;

use super::PerPage;

use std::collections::HashMap;
use serde_json::value::Value;

pub struct Oidc<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
    client: &'api C
}

pub fn new<C: Client>(client: &C) -> Oidc<C> where AdapterError: From<<C as Client>::Err> {
    Oidc { client }
}

/// Errors for the [Get the customization template for an OIDC subject claim for an organization](Oidc::get_oidc_custom_sub_template_for_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum OidcGetOidcCustomSubTemplateForOrgError {
    #[error("Status code: {}", code)]
    Generic { code: u16 },
}

impl From<OidcGetOidcCustomSubTemplateForOrgError> for AdapterError {
    fn from(err: OidcGetOidcCustomSubTemplateForOrgError) -> Self {
        let (description, status_code) = match err {
            OidcGetOidcCustomSubTemplateForOrgError::Generic { code } => (String::from("Generic"), code)
        };

        Self::Endpoint {
            description,
            status_code,
            source: Some(Box::new(err))
        }
    }
}

/// Errors for the [Set the customization template for an OIDC subject claim for an organization](Oidc::update_oidc_custom_sub_template_for_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum OidcUpdateOidcCustomSubTemplateForOrgError {
    #[error("Resource not found")]
    Status404(BasicError),
    #[error("Forbidden")]
    Status403(BasicError),
    #[error("Status code: {}", code)]
    Generic { code: u16 },
}

impl From<OidcUpdateOidcCustomSubTemplateForOrgError> for AdapterError {
    fn from(err: OidcUpdateOidcCustomSubTemplateForOrgError) -> Self {
        let (description, status_code) = match err {
            OidcUpdateOidcCustomSubTemplateForOrgError::Status404(_) => (String::from("Resource not found"), 404),
            OidcUpdateOidcCustomSubTemplateForOrgError::Status403(_) => (String::from("Forbidden"), 403),
            OidcUpdateOidcCustomSubTemplateForOrgError::Generic { code } => (String::from("Generic"), code)
        };

        Self::Endpoint {
            description,
            status_code,
            source: Some(Box::new(err))
        }
    }
}



impl<'api, C: Client> Oidc<'api, C> where AdapterError: From<<C as Client>::Err> {
    /// ---
    ///
    /// # Get the customization template for an OIDC subject claim for an organization
    ///
    /// Gets the customization template for an OpenID Connect (OIDC) subject claim.
    /// 
    /// OAuth app tokens and personal access tokens (classic) need the `read:org` scope to use this endpoint.
    ///
    /// [GitHub API docs for get_oidc_custom_sub_template_for_org](https://docs.github.com/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-an-organization)
    ///
    /// ---
    pub async fn get_oidc_custom_sub_template_for_org_async(&self, org: &str) -> Result<OidcCustomSub, AdapterError> {

        let request_uri = format!("{}/orgs/{}/actions/oidc/customization/sub", super::GITHUB_BASE_API_URL, org);


        let req = GitHubRequest {
            uri: request_uri,
            body: None::<C::Body>,
            method: "GET",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch_async(request).await?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json_async().await?)
        } else {
            match github_response.status_code() {
                code => Err(OidcGetOidcCustomSubTemplateForOrgError::Generic { code }.into()),
            }
        }
    }

    /// ---
    ///
    /// # Get the customization template for an OIDC subject claim for an organization
    ///
    /// Gets the customization template for an OpenID Connect (OIDC) subject claim.
    /// 
    /// OAuth app tokens and personal access tokens (classic) need the `read:org` scope to use this endpoint.
    ///
    /// [GitHub API docs for get_oidc_custom_sub_template_for_org](https://docs.github.com/rest/actions/oidc#get-the-customization-template-for-an-oidc-subject-claim-for-an-organization)
    ///
    /// ---
    #[cfg(not(target_arch = "wasm32"))]
    pub fn get_oidc_custom_sub_template_for_org(&self, org: &str) -> Result<OidcCustomSub, AdapterError> {

        let request_uri = format!("{}/orgs/{}/actions/oidc/customization/sub", super::GITHUB_BASE_API_URL, org);


        let req = GitHubRequest {
            uri: request_uri,
            body: None,
            method: "GET",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch(request)?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json()?)
        } else {
            match github_response.status_code() {
                code => Err(OidcGetOidcCustomSubTemplateForOrgError::Generic { code }.into()),
            }
        }
    }

    /// ---
    ///
    /// # Set the customization template for an OIDC subject claim for an organization
    ///
    /// Creates or updates the customization template for an OpenID Connect (OIDC) subject claim.
    /// 
    /// OAuth app tokens and personal access tokens (classic) need the `write:org` scope to use this endpoint.
    ///
    /// [GitHub API docs for update_oidc_custom_sub_template_for_org](https://docs.github.com/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-an-organization)
    ///
    /// ---
    pub async fn update_oidc_custom_sub_template_for_org_async(&self, org: &str, body: OidcCustomSub) -> Result<EmptyObject, AdapterError> {

        let request_uri = format!("{}/orgs/{}/actions/oidc/customization/sub", super::GITHUB_BASE_API_URL, org);


        let req = GitHubRequest {
            uri: request_uri,
            body: Some(C::from_json::<OidcCustomSub>(body)?),
            method: "PUT",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch_async(request).await?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json_async().await?)
        } else {
            match github_response.status_code() {
                404 => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Status404(github_response.to_json_async().await?).into()),
                403 => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Status403(github_response.to_json_async().await?).into()),
                code => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Generic { code }.into()),
            }
        }
    }

    /// ---
    ///
    /// # Set the customization template for an OIDC subject claim for an organization
    ///
    /// Creates or updates the customization template for an OpenID Connect (OIDC) subject claim.
    /// 
    /// OAuth app tokens and personal access tokens (classic) need the `write:org` scope to use this endpoint.
    ///
    /// [GitHub API docs for update_oidc_custom_sub_template_for_org](https://docs.github.com/rest/actions/oidc#set-the-customization-template-for-an-oidc-subject-claim-for-an-organization)
    ///
    /// ---
    #[cfg(not(target_arch = "wasm32"))]
    pub fn update_oidc_custom_sub_template_for_org(&self, org: &str, body: OidcCustomSub) -> Result<EmptyObject, AdapterError> {

        let request_uri = format!("{}/orgs/{}/actions/oidc/customization/sub", super::GITHUB_BASE_API_URL, org);


        let req = GitHubRequest {
            uri: request_uri,
            body: Some(C::from_json::<OidcCustomSub>(body)?),
            method: "PUT",
            headers: vec![]
        };

        let request = self.client.build(req)?;

        // --

        let github_response = self.client.fetch(request)?;

        // --

        if github_response.is_success() {
            Ok(github_response.to_json()?)
        } else {
            match github_response.status_code() {
                404 => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Status404(github_response.to_json()?).into()),
                403 => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Status403(github_response.to_json()?).into()),
                code => Err(OidcUpdateOidcCustomSubTemplateForOrgError::Generic { code }.into()),
            }
        }
    }

}