#策略 #策略 #决策 #Shisho # #编写 #SDK

test-shisho-policy

这是Shisho云策略的SDK,用于在Rust中编写自定义策略

1个不稳定版本

0.1.0 2022年11月9日

#963HTTP服务器

Apache-2.0

12KB
187

Shisho策略Rust SDK

这是Shisho云工作流程的辅助Crates,用于编写自定义策略。

这是编写自定义策略的核心库。

  • decision 包含了 输出数据(=决策结果)的结构体。
  • gqlgen 包含了从 geraphql 模式和查询转换的功能。原始代码来自 graphql-client/graphql_client_codegen
  • schema 包含了 datasource graphql查询的字符串。该模式由代码生成器生成。

所需Crates

需要辅助Crates,shisho-gql-derive

示例用法

use shisho_gql_derive::*;
pub use shisho_policy_sdk::decision::data_entry::*;
pub use shisho_policy_sdk::decision::github::organization::org_owners::*;
pub use shisho_policy_sdk::decision::*;

use self::input::InputGithubOrganizations;

#[allow(dead_code)]
#[derive(ShishoGraphQLQuery)]
#[shisho_graphql(
    query_path = "src/policies/organization/org_owners/query.graphql",
    response_derives = "Debug, PartialEq"
)]
pub struct Input;

pub fn decisions(input: input::InputData) -> Vec<Decision<OrgOwnersEntryData>> {
    input
        .github
        .organizations
        .into_iter()
        .map(|o: InputGithubOrganizations| decide_on_each_org(o))
        .collect()
}

pub fn decide_on_each_org(o: InputGithubOrganizations) -> Decision<OrgOwnersEntryData> {
    ...
}

参考

依赖

~0.4–1MB
~22K SLoC