Skip to content

Commit

Permalink
multiple updates to address spicedb validation errors (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytheleg authored Nov 15, 2024
1 parent ff15e42 commit 08ee79c
Show file tree
Hide file tree
Showing 14 changed files with 970 additions and 90 deletions.
2 changes: 1 addition & 1 deletion data/host-service-account.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"rhel_host": {
"metadata": {
"workspace_id": "hbi/rhel_host"
"workspace_id": "workspace1"
},
"reporter_data": {
"reporter_type": "OCM",
Expand Down
4 changes: 2 additions & 2 deletions data/host.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"rhel_host": {
"metadata": {
"resource_type": "rhel-host",
"workspace_id": "hbi/rhel_host"
"resource_type": "rhel_host",
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0"
},
"reporter_data": {
"reporter_type": "OCM",
Expand Down
9 changes: 9 additions & 0 deletions data/k8s-cluster-reporter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"reporter_data": {
"reporter_type": "OCM",
"reporter_version": "0.1",
"local_resource_id": "2",
"api_href": "www.example.com",
"console_href": "www.example.com"
}
}
4 changes: 2 additions & 2 deletions data/k8s-cluster.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"k8s_cluster": {
"metadata": {
"resource_type": "k8s-cluster",
"workspace_id": "hbi/k8s_cluster"
"resource_type": "k8s_cluster",
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0"
},
"reporter_data": {
"reporter_type": "ACM",
Expand Down
4 changes: 2 additions & 2 deletions data/k8s-policy.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"k8s_policy": {
"metadata": {
"resource_type": "k8s-policy",
"workspace_id": "hbi/k8s_policy"
"resource_type": "k8s_policy",
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0"
},
"reporter_data": {
"reporter_type": "ACM",
Expand Down
2 changes: 1 addition & 1 deletion data/k8spolicy_ispropagatedto_k8scluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"metadata": {
},
"reporter_data": {
"reporter_type": "OCM",
"reporter_type": "ACM",
"reporter_version": "0.1",
"subject_local_resource_id": "1",
"object_local_resource_id": "2"
Expand Down
521 changes: 453 additions & 68 deletions deploy/schema.yaml

Large diffs are not rendered by default.

475 changes: 475 additions & 0 deletions deploy/schema.zed

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ services:
relations-api:
image: "quay.io/cloudservices/kessel-relations:latest"
hostname: relations-api
volumes:
- ./deploy/schema.zed:/deploy/schema.zed:ro,z
environment:
- "SPICEDB_PRESHARED=${SPICEDB_GRPC_PRESHARED_KEY}"
# - "SPICEDB_PRESHARED_FILE=/run/secrets/spicedb_pre_shared"
Expand Down
13 changes: 9 additions & 4 deletions internal/service/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func ReporterRelationshipIdFromPb(relationshipType, reporterId string, reporter
return model.ReporterRelationshipId{}, errors.New("invalid relationship type, not in the expected format subject_relation_object ")
}

subjectType := res[0]
objectType := res[2]
subjectType := conform(res[0])
objectType := conform(res[2])

return model.ReporterRelationshipId{
ReporterId: reporterId,
Expand Down Expand Up @@ -106,8 +106,8 @@ func RelationshipFromPb(relationshipType, reporterId string, relationshipData mo
return nil, errors.New("invalid relationship type, not in the expected format subject_relation_object ")
}

subjectType := res[0]
objectType := res[2]
subjectType := conform(res[0])
objectType := conform(res[2])

return &model.Relationship{
ID: uuid.UUID{},
Expand All @@ -129,3 +129,8 @@ func RelationshipFromPb(relationshipType, reporterId string, relationshipData mo
},
}, nil
}

// Conform converts any hyphens in resource types to underscores to conform with SpiceDB validation requirements
func conform(resource string) string {
return strings.ReplaceAll(resource, "-", "_")
}
3 changes: 2 additions & 1 deletion internal/service/resources/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hosts

import (
"context"

pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/resources"
authnapi "github.com/project-kessel/inventory-api/internal/authn/api"
"github.com/project-kessel/inventory-api/internal/biz/model"
Expand All @@ -11,7 +12,7 @@ import (
)

const (
ResourceType = "rhel-host"
ResourceType = "rhel_host"
)

// HostsService handles requests for Rhel hosts
Expand Down
3 changes: 2 additions & 1 deletion internal/service/resources/k8sclusters/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8sclusters

import (
"context"

"github.com/project-kessel/inventory-api/internal/biz/resources"

pb "github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/resources"
Expand All @@ -12,7 +13,7 @@ import (
)

const (
ResourceType = "k8s-cluster"
ResourceType = "k8s_cluster"
)

// K8sClustersService handles requests for k8s clusters
Expand Down
3 changes: 2 additions & 1 deletion internal/service/resources/k8spolicies/k8spolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package k8spolicies

import (
"context"

"github.com/project-kessel/inventory-api/internal/biz/model"
"github.com/project-kessel/inventory-api/internal/biz/resources"

Expand All @@ -12,7 +13,7 @@ import (
)

const (
ResourceType = "k8s-policy"
ResourceType = "k8s_policy"
)

// K8sPoliciesService handles requests for K8s Policies
Expand Down
15 changes: 8 additions & 7 deletions test/e2e/inventory_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
nethttp "net/http"
"os"
"strconv"
"testing"

"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/transport/http"
v1 "github.com/project-kessel/inventory-api/api/kessel/inventory/v1"
"github.com/project-kessel/inventory-api/api/kessel/inventory/v1beta1/resources"
"github.com/project-kessel/inventory-client-go/v1beta1"
"github.com/stretchr/testify/assert"
nethttp "net/http"
"os"
"strconv"
"testing"
)

var inventoryapi_http_url string
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestInventoryAPIHTTP_CreateRHELHost(t *testing.T) {
}
request := resources.CreateRhelHostRequest{RhelHost: &resources.RhelHost{
Metadata: &resources.Metadata{
ResourceType: "rhel-host",
ResourceType: "rhel_host",
WorkspaceId: "workspace1",
OrgId: "",
},
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestInventoryAPIHTTP_K8SCluster_CreateK8SCluster(t *testing.T) {
request := resources.CreateK8SClusterRequest{
K8SCluster: &resources.K8SCluster{
Metadata: &resources.Metadata{
ResourceType: "k8s-cluster",
ResourceType: "k8s_cluster",
WorkspaceId: "",
OrgId: "",
},
Expand Down Expand Up @@ -238,7 +239,7 @@ func TestInventoryAPIHTTP_K8SPolicy_CreateK8SPolicy(t *testing.T) {
request := resources.CreateK8SPolicyRequest{
K8SPolicy: &resources.K8SPolicy{
Metadata: &resources.Metadata{
ResourceType: "k8s-policy",
ResourceType: "k8s_policy",
WorkspaceId: "default",
OrgId: "",
},
Expand Down

0 comments on commit 08ee79c

Please sign in to comment.