Skip to content

Commit

Permalink
Maintainer using sqlite db
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Nov 6, 2023
1 parent 6ddc667 commit c1c4acf
Show file tree
Hide file tree
Showing 25 changed files with 1,191 additions and 5 deletions.
2 changes: 2 additions & 0 deletions storage/sql_migrations/1_first.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop table usecaselist_presentations;
drop table usecaselist_timestamps;
17 changes: 17 additions & 0 deletions storage/sql_migrations/1_first.up.sql
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
);
11 changes: 11 additions & 0 deletions usecase/api/v1/api.go
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)
//}
48 changes: 48 additions & 0 deletions usecase/config.go
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
}
68 changes: 68 additions & 0 deletions usecase/definition.go
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
}
26 changes: 26 additions & 0 deletions usecase/interface.go
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
31 changes: 31 additions & 0 deletions usecase/log/logger.go
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
}
Loading

0 comments on commit c1c4acf

Please sign in to comment.