Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub is a bit awkward as a code repository for installing rulesets #626

Open
b1conrad opened this issue Mar 21, 2023 · 4 comments
Open

Comments

@b1conrad
Copy link
Member

b1conrad commented Mar 21, 2023

The title is odd, because GitHub is, above all else, a code repository. The awkwardness comes from:

  1. We have to use the Raw version of a krl file, and GitHub takes some time to make that available after a commit.
  2. In private/protected repos, the Raw URL has a token with a relatively short TTL, and it is different from one press of the Raw button to another.

These considerations mean that the Flush button in the Rulesets tab isn't useful. The options are:

  • flush using a pico engine api call from Postman, or a browser, or maybe with http:get (haven't tried that) No, that doesn't work because it is also based on the URL from which the ruleset was installed, and that will have changed!
  • install the ruleset instead of flushing it (beware that this could affect/re-initialize entity variables (use with care))
@b1conrad
Copy link
Member Author

b1conrad commented Mar 21, 2023

As a workaround, I am introducing this ruleset into a protected repo, having installed it in the root pico (which doesn't otherwise participate in the application). It then can serve up KRL files.

ruleset code-repo {
  meta {
    use module io.picolabs.wrangler alias wrangler
    shares code
  }
  global {
    code = function(rid){
      ent:code >< rid      => ent:code.get(rid) |
      rid.match(valid_rid) => "ruleset "+rid+" {}" |
                              ""
    }
    tags = ["code-repo"]
    rs_event_domain = "code_repo"
    valid_rid = re#(^\w[\w\d-.]+)$#
  }
  rule stashCode {
    select when code_repo new_ruleset
      rid re#(^\w[\w\d-.]+)$# setting(rid)
    fired {
      ent:code{rid} := event:attrs{"krl"}
    }
  }
  rule initialize {
    select when wrangler ruleset_installed where event:attrs{"rids"} >< meta:rid
    pre {
      chan = wrangler:channels(tags).head()
    }
    if chan.isnull() then
      wrangler:createChannel(
        tags,
        {"allow":[{"domain":rs_event_domain,"name":"*"}],"deny":[]},
        {"allow":[{"rid":meta:rid,"name":"*"}],"deny":[]}
      )
  }
}

Then a URL to get code would look like:

http://DOMAIN:PORT/c/ECI/query/code-repo/code.txt?rid=html

assuming one had raised the code_repo:new_ruleset event with the corresponding event attributes previously.

I suppose one could use a GitHub post commit action to update by raising that same event.

@b1conrad
Copy link
Member Author

b1conrad commented Mar 21, 2023

Have tested this with a couple of rulesets, and it works. Waiting for a change to see how well Flush works.

@b1conrad
Copy link
Member Author

The one proviso is that it cannot be used to hold/install a ruleset into itself. Hence using a pico that doesn't otherwise participate in any way in the application.

@b1conrad
Copy link
Member Author

While the new ruleset was written in the context of a protected repo, it leaks no information from that project, and is general-purpose. It will be maintained in the PicoStack repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant