pub async fn refresh_software_vendors() {
    let gsuite_customer = env::var("GADMIN_ACCOUNT_ID").unwrap();
    let token = get_gsuite_token("").await;
    let gsuite = GSuite::new(&gsuite_customer, GSUITE_DOMAIN, token.clone());

    let db = Database::new();

    let github = authenticate_github_jwt();

    let okta = Okta::new_from_env();

    let slack = slack_chat_api::Slack::new_from_env();

    // Get all the records from Airtable.
    let results: Vec<airtable_api::Record<SoftwareVendor>> = SoftwareVendor::airtable().list_records(&SoftwareVendor::airtable_table(), "Grid view", vec![]).await.unwrap();
    for vendor_record in results {
        let mut vendor: NewSoftwareVendor = vendor_record.fields.into();

        if vendor.name == "GitHub" {
            // Update the number of GitHub users in our org.
            let org = github.org(github_org()).get().await.unwrap();
            vendor.users = org.plan.filled_seats;
        }

        if vendor.name == "Okta" {
            let users = okta.list_users().await.unwrap();
            vendor.users = users.len() as i32;
        }

        if vendor.name == "Google Workspace" {
            let users = gsuite.list_users().await.unwrap();
            vendor.users = users.len() as i32;
        }

        if vendor.name == "Slack" {
            let users = slack.billable_info().await.unwrap();
            let mut count = 0;
            for (_, user) in users {
                if user.billing_active {
                    count += 1;
                }
            }

            vendor.users = count;
        }

        // Airtable, Brex, Gusto, Expensify are all the same number of users as
        // in all@.
        if vendor.name == "Airtable" || vendor.name == "Ramp" || vendor.name == "Brex" || vendor.name == "Gusto" || vendor.name == "Expensify" {
            let group = Group::get_from_db(&db, "all".to_string()).unwrap();
            let airtable_group = group.get_existing_airtable_record().await.unwrap();
            vendor.users = airtable_group.fields.members.len() as i32;
        }

        // Upsert the record in our database.
        let mut db_vendor = vendor.upsert_in_db(&db);

        if db_vendor.airtable_record_id.is_empty() {
            db_vendor.airtable_record_id = vendor_record.id;
        }

        // Update the cost per month.
        db_vendor.total_cost_per_month = (db_vendor.cost_per_user_per_month * db_vendor.users as f32) + db_vendor.flat_cost_per_month;

        db_vendor.update(&db).await;
    }

    SoftwareVendors::get_from_db(&db).update_airtable().await
}
/// Sync software vendors from Airtable.
Sync software vendors from Airtable.
Sync software vendors from Airtable .
pub async fn refresh_software_vendors() {
    let gsuite_customer = env::var("GADMIN_ACCOUNT_ID").unwrap();
    let token = get_gsuite_token("").await;
    let gsuite = GSuite::new(&gsuite_customer, GSUITE_DOMAIN, token.clone());
    let db = Database::new();
    let github = authenticate_github_jwt();
    let okta = Okta::new_from_env();
    let slack = slack_chat_api::Slack::new_from_env();
    // Get all the records from Airtable.
    let results: Vec<airtable_api::Record<SoftwareVendor>> = SoftwareVendor::airtable().list_records(&SoftwareVendor::airtable_table(), "Grid view", vec![]).await.unwrap();
    for vendor_record in results {
        let mut vendor: NewSoftwareVendor = vendor_record.fields.into();
        if vendor.name == "GitHub" {
            // Update the number of GitHub users in our org.
            let org = github.org(github_org()).get().await.unwrap();
            vendor.users = org.plan.filled_seats;
        }
        if vendor.name == "Okta" {
            let users = okta.list_users().await.unwrap();
            vendor.users = users.len() as i32;
        }
        if vendor.name == "Google Workspace" {
            let users = gsuite.list_users().await.unwrap();
            vendor.users = users.len() as i32;
        }
        if vendor.name == "Slack" {
            let users = slack.billable_info().await.unwrap();
            let mut count = 0;
            for (_, user) in users {
                if user.billing_active {
                    count += 1;
                }
            }
            vendor.users = count;
        }
        // Airtable, Brex, Gusto, Expensify are all the same number of users as
        // in all@.
        if vendor.name == "Airtable" || vendor.name == "Ramp" || vendor.name == "Brex" || vendor.name == "Gusto" || vendor.name == "Expensify" {
            let group = Group::get_from_db(&db, "all".to_string()).unwrap();
            let airtable_group = group.get_existing_airtable_record().await.unwrap();
            vendor.users = airtable_group.fields.members.len() as i32;
        }
        // Upsert the record in our database.
        let mut db_vendor = vendor.upsert_in_db(&db);
        if db_vendor.airtable_record_id.is_empty() {
            db_vendor.airtable_record_id = vendor_record.id;
        }
        // Update the cost per month.
        db_vendor.total_cost_per_month = (db_vendor.cost_per_user_per_month * db_vendor.users as f32) + db_vendor.flat_cost_per_month;
        db_vendor.update(&db).await;
    }
    SoftwareVendors::get_from_db(&db).update_airtable().await
}
pub async fn refresh_software_vendors ( ) { let gsuite_customer = env :: var ( " " ) . unwrap ( ) ; let token = get_gsuite_token ( " " ) . await ; let gsuite = GSuite :: new ( & gsuite_customer , GSUITE_DOMAIN , token . clone ( ) ) ; let db = Database :: new ( ) ; let github = authenticate_github_jwt ( ) ; let okta = Okta :: new_from_env ( ) ; let slack = slack_chat_api :: Slack :: new_from_env ( ) ; // Get all the records from Airtable. let results : Vec < airtable_api :: Record < SoftwareVendor > > = SoftwareVendor :: airtable ( ) . list_records ( & SoftwareVendor :: airtable_table ( ) , " " , vec ! [ ] ) . await . unwrap ( ) ; for vendor_record in results { let mut vendor : NewSoftwareVendor = vendor_record . fields . into ( ) ; if vendor . name == " " { // Update the number of GitHub users in our org. let org = github . org ( github_org ( ) ) . get ( ) . await . unwrap ( ) ; vendor . users = org . plan . filled_seats ; } if vendor . name == " " { let users = okta . list_users ( ) . await . unwrap ( ) ; vendor . users = users . len ( ) as i32 ; } if vendor . name == " " { let users = gsuite . list_users ( ) . await . unwrap ( ) ; vendor . users = users . len ( ) as i32 ; } if vendor . name == " " { let users = slack . billable_info ( ) . await . unwrap ( ) ; let mut count = 0 ; for ( _ , user ) in users { if user . billing_active { count += 1 ; } } vendor . users = count ; } // Airtable, Brex, Gusto, Expensify are all the same number of users as // in all@. if vendor . name == " " || vendor . name == " " || vendor . name == " " || vendor . name == " " || vendor . name == " " { let group = Group :: get_from_db ( & db , " " . to_string ( ) ) . unwrap ( ) ; let airtable_group = group . get_existing_airtable_record ( ) . await . unwrap ( ) ; vendor . users = airtable_group . fields . members . len ( ) as i32 ; } // Upsert the record in our database. let mut db_vendor = vendor . upsert_in_db ( & db ) ; if db_vendor . airtable_record_id . is_empty ( ) { db_vendor . airtable_record_id = vendor_record . id ; } // Update the cost per month. db_vendor . total_cost_per_month = ( db_vendor . cost_per_user_per_month * db_vendor . users as f32 ) + db_vendor . flat_cost_per_month ; db_vendor . update ( & db ) . await ; } SoftwareVendors :: get_from_db ( & db ) . update_airtable ( ) . await }
Sync software vendors from Airtable.
Sync software vendors from Airtable .