Skip to content
Draft
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
6 changes: 6 additions & 0 deletions module/services/accounts/code/pkg/adapters/host_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func (s *HostAuthorityServer) Issue(ctx context.Context, req *authorityv1.IssueR
return nil, werr
}
out, err = core.IssueForInstallation(ctx, w, as.Installation.GetInstallationId(), r)
case *authorityv1.IssueRequest_Setup:
w, werr := workload(ctx, req.GetActor().GetCredential(), "actor")
if werr != nil {
return nil, werr
}
out, err = core.IssueForInstallationSetup(ctx, w, as.Setup.GetStepToken(), as.Setup.GetMethod(), r)
case *authorityv1.IssueRequest_ParentToken:
w, werr := workload(ctx, req.GetActor().GetCredential(), "actor")
if werr != nil {
Expand Down
3 changes: 3 additions & 0 deletions module/services/accounts/code/pkg/adapters/host_offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func reviewedOffer(offer authority.ReviewedOffer, bindings map[string]*runnablev
return nil, coreStatus(err)
}
out := &installationv1.ReviewedOffer{Target: projected.Target, ToolsComposed: projected.ToolsComposed, InstallationRole: projected.InstallationRole}
for _, setup := range projected.Setup {
out.Setup = append(out.Setup, &installationv1.OfferSetup{Binding: setup.Binding, Module: setup.Module, Methods: setup.Methods, Scopes: offerScopesToWire(setup.Scopes)})
}
for _, edge := range projected.EdgeDependencies {
out.EdgeDependencies = append(out.EdgeDependencies, &installationv1.OfferDependency{Module: edge.Module, Presence: edge.Presence})
}
Expand Down
17 changes: 17 additions & 0 deletions module/services/accounts/code/pkg/adapters/host_offers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/codefly-dev/authority/libraries/authority-core/go/authority"
"github.com/codefly-dev/authority/libraries/authority-core/go/domain"
modulecontract "github.com/codefly-dev/core/contracts/module"
basev0 "github.com/codefly-dev/core/generated/go/codefly/base/v0"
runnablev0 "github.com/codefly-dev/core/generated/go/codefly/runnable/v0"
"github.com/codefly-dev/core/resources"
Expand Down Expand Up @@ -143,3 +144,19 @@ func TestAReviewedOfferPreservesTheSharedProjectionRefusal(t *testing.T) {
require.Equal(t, codes.FailedPrecondition, status.Code(err))
require.Contains(t, status.Convert(err).Message(), "the composed binding BROKEN is not a valid tool")
}

// Setup grants shown for review retain their binding, target, methods and scope.
func TestReviewedOfferProjectsSetup(t *testing.T) {
offer := proposalsOffer(domain.ConsentApproval{})
offer.Module.Setup = []modulecontract.ResolvedSetup{{Binding: "documents", Methods: []string{"/records.v1.Schema/Define"}, Scopes: []string{"records.types:define"}}}
review, err := reviewedOffer(offer, nil)
require.NoError(t, err)
require.Len(t, review.GetSetup(), 1)
setup := review.GetSetup()[0]
require.Equal(t, "documents", setup.GetBinding())
require.Equal(t, "documents", setup.GetModule())
require.Equal(t, []string{"/records.v1.Schema/Define"}, setup.GetMethods())
require.Len(t, setup.GetScopes(), 1)
require.Equal(t, "records.types", setup.GetScopes()[0].GetResourceKind())
require.Equal(t, []string{"define"}, setup.GetScopes()[0].GetActions())
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/codefly-dev/authority/libraries/authority-core/go/decide"
coredelivered "github.com/codefly-dev/authority/libraries/authority-core/go/delivered"
"github.com/codefly-dev/authority/libraries/authority-core/go/domain"
modulecontract "github.com/codefly-dev/core/contracts/module"
basev0 "github.com/codefly-dev/core/generated/go/codefly/base/v0"
"github.com/codefly-dev/core/solutionhost"
"github.com/codefly-dev/core/wool"
Expand Down Expand Up @@ -43,7 +44,10 @@ func coreModuleOf(manifest *solutionhost.ModuleManifest, carrierDocument []byte,
// documentOf reads this host's binding of the authority's document as the core's.
func documentOf(in *compositionv1.AuthorityManifestV1) *coredelivered.Document {
doc := &coredelivered.Document{Module: in.GetModule(), Generation: in.GetGeneration(), CoreManifestDigest: in.GetCoreManifestDigest(),
ScopeCeilings: wireScopes(in.GetScopeCeilings()), OwnerAware: in.GetOwnerAware(), InstallationRole: in.GetInstallationRole()}
ScopeCeilings: wireScopes(in.GetScopeCeilings()), OwnerAware: in.GetOwnerAware(), OwnerAwareResourceKinds: in.GetOwnerAwareResourceKinds(), InstallationRole: in.GetInstallationRole()}
for _, setup := range in.GetSetup() {
doc.Setup = append(doc.Setup, modulecontract.ResolvedSetup{Binding: setup.GetBinding(), Methods: setup.GetMethods(), Scopes: setup.GetScopes()})
}
for _, edge := range in.GetEdgeDependencies() {
doc.EdgeDependencies = append(doc.EdgeDependencies, domain.EdgeDependency{Module: edge.GetModule(), Presence: edge.GetPresence()})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package business

import (
"testing"

compositionv1 "accounts/pkg/gen/host/composition/v1"
modulecontract "github.com/codefly-dev/core/contracts/module"
"github.com/stretchr/testify/require"
)

func TestDocumentOfRetainsSetupAndOwnerAwareKinds(t *testing.T) {
in := &compositionv1.AuthorityManifestV1{
OwnerAwareResourceKinds: []string{"example.items"},
Setup: []*compositionv1.SetupGrantV1{{Binding: "records", Methods: []string{"/records.v1.Schema/Define"}, Scopes: []string{"records.types:define"}}},
}
got := documentOf(in)
require.Equal(t, in.OwnerAwareResourceKinds, got.OwnerAwareResourceKinds)
require.Equal(t, []modulecontract.ResolvedSetup{{Binding: "records", Methods: []string{"/records.v1.Schema/Define"}, Scopes: []string{"records.types:define"}}}, got.Setup)
}
Loading
Loading