Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Codegen

on:
pull_request:
push:
branches: ["main"]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }}
cancel-in-progress: true

jobs:
codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
# Compile the generators under the `codegen` build tag. The reusable
# go-check/go-test workflows build without this tag, so a generator that
# no longer compiles would otherwise slip through CI.
- run: make codegen-build
# Run `go generate` and fail if the committed generated files are stale.
- run: make gen-check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
.PHONY: gen
.PHONY: gen build test codegen-build gen-check ci

gen:
go generate ./...

build:
go build ./...

test:
go test ./...

# Compile the code generators under the `codegen` build tag they actually run
# with. A normal `go build ./...` never sets this tag, so a generator that no
# longer compiles (e.g. it references a renamed or removed type) would otherwise
# go unnoticed until someone runs `go generate`.
codegen-build:
go build -tags codegen $(shell go list ./... | grep '/gen$$')

# Regenerate everything and fail if the committed output changed, catching both
# generators that no longer compile and generated files that are out of date.
gen-check: gen
@git diff --exit-code -- '*_gen.go' '*_gen.*.go' || \
{ echo "generated files are out of date; run 'make gen' and commit the result" >&2; exit 1; }

# Aggregate target suitable for CI.
ci: build codegen-build gen-check test
185 changes: 185 additions & 0 deletions commands/access/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions commands/access/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
access.ClaimOK{},
access.ConfirmArguments{},
access.DelegateArguments{},
access.GrantArguments{},
}
const (
cborFile = "../cbor_gen.go"
Expand Down
36 changes: 36 additions & 0 deletions commands/access/grant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build !codegen

package access

import (
"github.com/fil-forge/ucantone/errors"

"github.com/fil-forge/libforge/commands"
)

const GrantCommand = "/access/grant"

// GrantOK mirrors ClaimOK / ConfirmOK: a successful grant resolves into a
// bundle of delegation CIDs. The actual delegation envelopes ride in the
// receipt response container as metadata.
type GrantOK = ClaimOK

// Grant can be invoked by an agent to request that a set of capabilities be
// granted directly. Unlike Request -> Confirm, Grant is one-shot: the
// executor decides immediately whether to issue the delegation.
var Grant = commands.MustParse[*GrantArguments](GrantCommand)

const (
UnknownAbilityErrorName = "UnknownAbility"
MissingCapabilityErrorName = "MissingCapability"
UnknownCauseErrorName = "UnknownCause"
MissingCauseErrorName = "MissingCause"
InvalidCauseErrorName = "InvalidCause"
UnauthorizedCauseErrorName = "UnauthorizedCause"
)

var (
ErrMissingCapability = errors.New(MissingCapabilityErrorName, "grant requires one or more capabilities")
ErrMissingCause = errors.New(MissingCauseErrorName, "grant requires a supporting contextual invocation")
ErrUnknownCause = errors.New(UnknownCauseErrorName, "unknown cause invocation")
)
Loading
Loading