Skip to content

Commit

Permalink
feat: use mgmtPB.Owner to embed the owner information in response
Browse files Browse the repository at this point in the history
  • Loading branch information
donch1989 committed Feb 22, 2024
1 parent a5a336d commit 8a2934a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 74 deletions.
5 changes: 4 additions & 1 deletion internal/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ type Namespace struct {
NsUID uuid.UUID
}

func (ns Namespace) String() string {
func (ns Namespace) Name() string {
return fmt.Sprintf("%s/%s", ns.NsType, ns.NsID)
}
func (ns Namespace) Permalink() string {
return fmt.Sprintf("%s/%s", ns.NsType, ns.NsUID.String())
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/handler/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ func (h *PublicHandler) createNamespaceConnector(ctx context.Context, connector
return nil, st.Err()
}

connector.OwnerName = req.GetParent()

connectorCreated, err = h.service.CreateNamespaceConnector(ctx, ns, authUser, connector)

if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions pkg/handler/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,9 @@ func (h *PublicHandler) createNamespacePipeline(ctx context.Context, req CreateN

pipelineToCreate := req.GetPipeline()

pipelineToCreate.OwnerName = req.GetParent()
if pipelineToCreate.Recipe != nil {
for _, comp := range pipelineToCreate.Recipe.Components {
if comp.ResourceName != "" && !strings.HasPrefix(comp.ResourceName, pipelineToCreate.OwnerName+"/") {
if comp.ResourceName != "" && !strings.HasPrefix(comp.ResourceName, ns.Name()+"/") {
return nil, ErrConnectorNamespace
}
}
Expand Down Expand Up @@ -541,7 +540,7 @@ func (h *PublicHandler) updateNamespacePipeline(ctx context.Context, req UpdateN
}
if pbPipelineReq.Recipe != nil {
for _, comp := range pbPipelineReq.Recipe.Components {
if comp.ResourceName != "" && !strings.HasPrefix(comp.ResourceName, pbPipelineToUpdate.OwnerName+"/") {
if comp.ResourceName != "" && !strings.HasPrefix(comp.ResourceName, ns.Name()+"/") {
return nil, ErrConnectorNamespace
}
}
Expand Down
40 changes: 18 additions & 22 deletions pkg/service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"

mgmtPB "github.com/instill-ai/protogen-go/core/mgmt/v1beta"
pipelinePB "github.com/instill-ai/protogen-go/vdp/pipeline/v1beta"
)

Expand Down Expand Up @@ -271,17 +272,11 @@ func (s *service) includeDetailInRecipe(recipe *pipelinePB.Recipe, userUID uuid.
}

// PBToDBPipeline converts protobuf data model to db data model
func (s *service) PBToDBPipeline(ctx context.Context, pbPipeline *pipelinePB.Pipeline) (*datamodel.Pipeline, error) {
func (s *service) PBToDBPipeline(ctx context.Context, ns resource.Namespace, pbPipeline *pipelinePB.Pipeline) (*datamodel.Pipeline, error) {
logger, _ := logger.GetZapLogger(ctx)

var owner string
var err error

owner, err = s.ConvertOwnerNameToPermalink(pbPipeline.GetOwnerName())
if err != nil {
return nil, err
}

recipe := &datamodel.Recipe{}
if pbPipeline.GetRecipe() != nil {
recipePermalink, err := s.recipeNameToPermalink(pbPipeline.Recipe)
Expand Down Expand Up @@ -317,7 +312,7 @@ func (s *service) PBToDBPipeline(ctx context.Context, pbPipeline *pipelinePB.Pip
}

return &datamodel.Pipeline{
Owner: owner,
Owner: ns.Permalink(),
ID: pbPipeline.GetId(),

BaseDynamic: datamodel.BaseDynamic{
Expand Down Expand Up @@ -376,9 +371,12 @@ func (s *service) DBToPBPipeline(ctx context.Context, dbPipeline *datamodel.Pipe
if err != nil {
return nil, err
}
owner, err := s.FetchOwnerWithPermalink(dbPipeline.Owner)
if err != nil {
return nil, err
var owner *mgmtPB.Owner

Check failure on line 374 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mgmtPB.Owner

Check failure on line 374 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mgmtPB.Owner

Check failure on line 374 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: mgmtPB.Owner

Check failure on line 374 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: mgmtPB.Owner
if view != ViewBasic {
owner, err = s.FetchOwnerWithPermalink(dbPipeline.Owner)
if err != nil {
return nil, err
}
}

var pbRecipe *pipelinePB.Recipe
Expand Down Expand Up @@ -787,6 +785,7 @@ func (s *service) DBToPBPipelineReleases(ctx context.Context, dbPipelineRelease
// convertProtoToDatamodel converts protobuf data model to db data model
func (s *service) convertProtoToDatamodel(
ctx context.Context,
ns resource.Namespace,
pbConnector *pipelinePB.Connector,
) (*datamodel.Connector, error) {

Expand Down Expand Up @@ -824,15 +823,8 @@ func (s *service) convertProtoToDatamodel(
Valid: true,
}

var owner string

owner, err = s.ConvertOwnerNameToPermalink(pbConnector.GetOwnerName())
if err != nil {
return nil, err
}

return &datamodel.Connector{
Owner: owner,
Owner: ns.Permalink(),
ID: id,
ConnectorType: datamodel.ConnectorType(connectorDefinition.Type),
Description: description,
Expand Down Expand Up @@ -874,10 +866,14 @@ func (s *service) convertDatamodelToProto(
if err != nil {
return nil, err
}
owner, err := s.FetchOwnerWithPermalink(dbConnector.Owner)
if err != nil {
return nil, err
var owner *mgmtPB.Owner

Check failure on line 869 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mgmtPB.Owner (typecheck)

Check failure on line 869 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / lint

undefined: mgmtPB.Owner (typecheck)

Check failure on line 869 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: mgmtPB.Owner

Check failure on line 869 in pkg/service/convert.go

View workflow job for this annotation

GitHub Actions / codecov

undefined: mgmtPB.Owner
if view != ViewBasic {
owner, err = s.FetchOwnerWithPermalink(dbConnector.Owner)
if err != nil {
return nil, err
}
}

dbConnDef, err := s.connector.GetConnectorDefinitionByUID(dbConnector.ConnectorDefinitionUID, nil, nil)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 8a2934a

Please sign in to comment.