Skip to content

Commit

Permalink
Merge pull request #7 from go-dataspace/ainmosni/feature/dsp-types
Browse files Browse the repository at this point in the history
Add DSP types.
  • Loading branch information
Daniel Swärd authored Jun 10, 2024
2 parents 706e27c + 2d1ef54 commit c3cefc7
Show file tree
Hide file tree
Showing 11 changed files with 803 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"licenser.author": "go-dataspace",
"licenser.license": "AL2"
"licenser.license": "AL2",
"go.addTags": {
"transform": "camelcase"
}
}
98 changes: 98 additions & 0 deletions dsp/catalog_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dsp

import (
"github.com/go-dataspace/run-dsp/jsonld"
"github.com/go-dataspace/run-dsp/odrl"
)

// CatalogRequestMessage is a message to request a catalog. Note that the filter format is defined
// as "implementation specific" and nothing else in the spec.
// TODO: define how we want to support filters.
type CatalogRequestMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:CatalogRequestMessage"`
Filter []any `json:"dspace:filter"`
}

// DatasetRequestMessage is a message to request a dataset.
type DatasetRequestMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:DatasetRequestMessage"`
Dataset string `json:"dspace:dataset" validate:"required"`
}

// CatalogAcknowledgement is an acknowledgement for a catalog, containing a dataset.
type CatalogAcknowledgement struct {
Dataset
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dcat:Catalog"`
Datasets []Dataset `json:"dcat:dataset" validate:"gte=1,dive"`
Service []DataService `json:"dcat:service" validate:"gte=1,dive"`
ParticipantID string `json:"dspace:participantID,omitempty"`
Homepage string `json:"foaf:homepage,omitempty"`
}

// CatalogError is a standardised error for catalog requests.
type CatalogError struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:CatalogError"`
Code string `json:"dspace:code"`
Reason []map[string]any `json:"dspace:reason"`
}

// Dataset is a DCAT dataset.
type Dataset struct {
Resource
HasPolicy []odrl.Offer `json:"odrl:hasPolicy" validate:"required,gte=1,dive"`
Distribution []Distribution `json:"dcat:distribution" validate:"gte=1,dive"`
}

// Resource is a DCAT resource.
type Resource struct {
Keyword []string `json:"dcat:keyword,omitempty"`
Theme []Reference `json:"dcat:them,omitempty" validate:"gte=1,dive"`
ConformsTo string `json:"dct:conformsTo,omitempty"`
Creator string `json:"dct:creator,omitempty"`
Description []Multilanguage `json:"dct:description,omitempty" validate:"dive"`
Identifier string `json:"dct:identifier,omitempty"`
Issued string `json:"dct:issued,omitempty"`
Modified string `json:"dct:modified,omitempty"`
Title string `json:"dct:title,omitempty"`
}

// Distribution is a DCAT distribution.
type Distribution struct {
Title string `json:"dct:title,omitempty"`
Description []Multilanguage `json:"dct:description,omitempty" validate:"dive"`
Issued string `json:"dct:issued,omitempty"`
Modified string `json:"dct:modified,omitempty"`
HasPolicy []odrl.Offer `json:"odrl:hasPolicy" validate:"gte=1,dive"`
AccessService []DataService `json:"dcat:accessService" validate:"required,gte=1,dive"`
}

// DataService is a DCAT dataservice.
type DataService struct {
Resource
EndpointDescription string `json:"dcat:endpointDescription,omitempty"`
EndpointURL string `json:"dcat:endpointURL,omitempty"`
ServesDataset []Dataset `json:"dcat:servesDataset,omitempty"`
}

// Reference is a DCAT reference.
type Reference struct {
ID string `json:"@id" validate:"required"`
}
41 changes: 41 additions & 0 deletions dsp/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dsp

// This file contains types to support the IDSA dataspace protocol.
// Currently we support 2024-1.
// Reference: https://docs.internationaldataspaces.org/ids-knowledgebase/v/dataspace-protocol

import (
"github.com/go-dataspace/run-dsp/jsonld"
)

// VersionResponse contains multiple protocol version specifications.
type VersionResponse struct {
Context jsonld.Context `json:"@context"`
ProtocolVersions []ProtocolVersion `json:"protocolVersions" validate:"required,gte=1,dive"`
}

// ProtocolVersion contains a version and the path to the endpoints.
type ProtocolVersion struct {
Version string `json:"version" validate:"required"`
Path string `json:"path" validate:"required,dirpath"`
}

// Multilanguage is a DCAT multilanguage set.
type Multilanguage struct {
Value string `json:"@value" validate:"required"`
Language string `json:"@language" validate:"required"`
}
97 changes: 97 additions & 0 deletions dsp/contract_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dsp

import (
"github.com/go-dataspace/run-dsp/jsonld"
"github.com/go-dataspace/run-dsp/odrl"
)

// ContractRequestMessage is a dsp contract request.
type ContractRequestMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractRequestMessage"`
ProviderPID string `json:"dspace:providerPid"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
Offer odrl.MessageOffer `json:"dspace:offer" validate:"required"`
CallbackAddress string `json:"dspace:callbackAddress" validate:"required"`
}

// ContractOfferMessage is a DSP contract offer.
type ContractOfferMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractOfferMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid"`
Offer odrl.MessageOffer `json:"dspace:offer" validate:"required"`
CallbackAddress string `json:"dspace:callbackAddress" validate:"required"`
}

// ContractAgreementMessage is a DSP contract agreement.
type ContractAgreementMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractAgreementMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid"`
Agreement odrl.Agreement `json:"dspace:agreement" validate:"required"`
CallbackAddress string `json:"dspace:callbackAddress" validate:"required"`
}

// ContractAgreementVerificationMessage verifies the contract agreement.
type ContractAgreementVerificationMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractAgreementMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
}

// ContractNegotiationEventMessage notifies of a contract event.
type ContractNegotiationEventMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractAgreementMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
EventType string `json:"dspace:eventType" validate:"required,oneof=dspace:ACCEPTED dspace:FINALIZED"`
}

// ContractNegotiationTerminationMessage terminates the negotiation.
type ContractNegotiationTerminationMessage struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractNegotiationTerminationMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
Code string `json:"dspace:code"`
Reason []map[string]any `json:"dspace:reason"`
}

// ContractNegotiation is a response to show the state of the contract negotiation.
type ContractNegotiation struct {
Context jsonld.Context `json:"@context"`
Type string `json:"@type" validate:"required,eq=dspace:ContractNegotiation"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
State string `json:"dspace:state" validate:"required,contract_state"`
}

// ContractNegotiationError is a response to show the state of the contract negotiation.
type ContractNegotiationERror struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:ContractNegotiation"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
Code string `json:"dspace:code,omitempty"`
Reason []map[string]any `json:"dspace:reason,omitempty"`
Description []Multilanguage `json:"dct:description,omitempty"`
}
99 changes: 99 additions & 0 deletions dsp/transfer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2024 go-dataspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dsp

import "github.com/go-dataspace/run-dsp/jsonld"

// TransferRequestMessage requests a data transfer.
type TransferRequestMessage struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferRequestMessage"`
AgreementID string `json:"dspace:agreementID" validate:"required"`
Format string `json:"dct:format" validate:"required"`
DataAddress DataAddress `json:"dspace:dataAddress"`
CallbackAddress string `json:"dspace:callbackAddress" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
}

// TransferStartMessage signals a transfer start.
type TransferStartMessage struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferStartMessage"`
ProviderPID string `json:"dspace:providerPid" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid" validate:"required"`
DataAddress DataAddress `json:"dspace:dataAddress"`
}

// TransferSuspensionMessage signals the suspension of a datatransfer.
type TransferSuspensionMessage struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferSuspensionMessage"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
Code string `json:"code,omitempty"`
Reason []map[string]any `json:"reason,omitempty"`
}

// TransferCompletionMessage signals the completion of a datatransfer.
type TransferCompletionMessage struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferCompletionMessage"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
}

// TransferTerminationMessage signals the suspension of a datatransfer.
type TransferTerminationMessage struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferTerminationMessage"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
Code string `json:"code,omitempty"`
Reason []map[string]any `json:"reason,omitempty"`
}

// TransferProcess are state change reponses.
type TransferProcess struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferProcess"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
State string `json:"dspace:state" validate:"required,transfer_state"`
}

// TransferError signals the suspension of a datatransfer.
type TransferError struct {
Context jsonld.Context `json:"@context,omitempty"`
Type string `json:"@type,omitempty" validate:"required,eq=dspace:TransferError"`
ProviderPID string `json:"dspace:providerPid,omitempty" validate:"required"`
ConsumerPID string `json:"dspace:consumerPid,omitempty" validate:"required"`
Code string `json:"code,omitempty"`
Reason []map[string]any `json:"reason,omitempty"`
}

// DataAddress represents a dataspace data address.
type DataAddress struct {
Type string `json:"@type,omitempty" validate:"required,eq=dspace:DataAddress"`
EndpointType string `json:"endpointType" validate:"required"`
Endpoint string `json:"endpoint" validate:"required"`
EndpointProperties []EndpointProperty `json:"endpointProperties"`
}

// EndpointProperty represents endpoint properties.
type EndpointProperty struct {
Type string `json:"@type,omitempty" validate:"required,eq=dspace:EndpointProperty"`
Name string `json:"dspace:name" validate:"required"`
Value string `json:"dspace:value" validate:"required"`
}
Loading

0 comments on commit c3cefc7

Please sign in to comment.