-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,191 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
drop table usecaselist_presentations; | ||
drop table usecaselist_timestamps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
create table usecaselist_presentations | ||
( | ||
id text not null primary key, | ||
list_id text not null, | ||
timestamp integer not null, | ||
credential_subject_id text not null, | ||
presentation_id text not null, | ||
presentation_raw text not null, | ||
presentation_expiration integer not null, | ||
unique (list_id, credential_subject_id) | ||
); | ||
|
||
create table usecaselist_timestamps | ||
( | ||
list_id text not null primary key, | ||
timestamp integer not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package v1 | ||
|
||
//// lists maps a list name (last path part of use case endpoint) to the list ID | ||
//lists map[string]string | ||
//// name is derived from endpoint: it's the last path part of the definition endpoint | ||
//// It is used to route HTTP GET requests to the correct list. | ||
//pathParts := strings.Split(definition.Endpoint, "/") | ||
//name := pathParts[len(pathParts)-1] | ||
//if name == "" { | ||
//return nil, fmt.Errorf("can't derive list name from definition endpoint: %s", definition.Endpoint) | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2023 Nuts community | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package usecase | ||
|
||
// Config holds the config for use case listDefinition | ||
type Config struct { | ||
Maintainer MaintainerConfig `koanf:"maintainer"` | ||
Definitions DefinitionsConfig `koanf:"definitions"` | ||
} | ||
|
||
type DefinitionsConfig struct { | ||
Directory string `koanf:"directory"` | ||
} | ||
|
||
// MaintainerConfig holds the config for the maintainer | ||
type MaintainerConfig struct { | ||
// DefinitionIDs specifies which use case lists the maintainer serves. | ||
DefinitionIDs []string `koanf:"definition_ids"` | ||
// Directory is the directory where the maintainer stores the lists. | ||
Directory string `koanf:"directory"` | ||
} | ||
|
||
// DefaultConfig returns the default configuration. | ||
func DefaultConfig() Config { | ||
return Config{ | ||
Maintainer: MaintainerConfig{}, | ||
} | ||
} | ||
|
||
func (c Config) IsMaintainer() bool { | ||
return len(c.Maintainer.DefinitionIDs) > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2023 Nuts community | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package usecase | ||
|
||
import ( | ||
"bytes" | ||
"embed" | ||
"encoding/json" | ||
"github.com/nuts-foundation/nuts-node/vcr/pe" | ||
v2 "github.com/nuts-foundation/nuts-node/vcr/pe/schema/v2" | ||
"github.com/santhosh-tekuri/jsonschema" | ||
) | ||
|
||
//go:embed *.json | ||
var jsonSchemaFiles embed.FS | ||
var definitionJsonSchema *jsonschema.Schema | ||
|
||
func init() { | ||
usecaseDefinitionSchemaData, err := jsonSchemaFiles.ReadFile("usecase-definition-schema.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
const schemaURL = "http://nuts.nl/schemas/usecase-v0.json" | ||
if err := v2.Compiler.AddResource(schemaURL, bytes.NewReader(usecaseDefinitionSchemaData)); err != nil { | ||
panic(err) | ||
} | ||
definitionJsonSchema = v2.Compiler.MustCompile(schemaURL) | ||
} | ||
|
||
// Definition holds the definition of a use case list. | ||
type Definition struct { | ||
// ID is the unique identifier of the use case. | ||
ID string `json:"id"` | ||
// Endpoint is the endpoint where the use case list is served. | ||
Endpoint string `json:"endpoint"` | ||
// PresentationDefinition specifies the Presentation Definition submissions to the list must conform to, | ||
// according to the Presentation Exchange specification. | ||
PresentationDefinition pe.PresentationDefinition `json:"presentation_definition"` | ||
// PresentationMaxValidity specifies how long submitted presentations are allowed to be valid (in seconds). | ||
PresentationMaxValidity int `json:"presentation_max_validity"` | ||
} | ||
|
||
func parseDefinition(data []byte) (*Definition, error) { | ||
if err := definitionJsonSchema.Validate(bytes.NewReader(data)); err != nil { | ||
return nil, err | ||
} | ||
var definition Definition | ||
if err := json.Unmarshal(data, &definition); err != nil { | ||
return nil, err | ||
} | ||
return &definition, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2023 Nuts community | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package usecase | ||
|
||
// Timestamp is value that references a point in the list. | ||
// It is used by clients to request new entries since their last query. | ||
// It's implemented as lamport timestamp (https://en.wikipedia.org/wiki/Lamport_timestamp); | ||
// it is incremented when a new entry is added to the list. | ||
// Pass 0 to start at the beginning of the list. | ||
type Timestamp uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2023 Nuts community | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package log | ||
|
||
import ( | ||
"github.com/nuts-foundation/nuts-node/core" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var _logger = logrus.StandardLogger().WithField(core.LogFieldModule, "UseCase") | ||
|
||
// Logger returns a logger with the module field set | ||
func Logger() *logrus.Entry { | ||
return _logger | ||
} |
Oops, something went wrong.