Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
adding in seperate status base URI (#660)
Browse files Browse the repository at this point in the history
* adding in seperate status base URI

* Update config/info.go

Co-authored-by: Gabe <[email protected]>

* Update config/info.go

Co-authored-by: Gabe <[email protected]>

* Update config/info.go

Co-authored-by: Gabe <[email protected]>

* fixing for default and gabes feedback

* Status (#666)

* tmp

* fix tests

* Update integration/common.go

* Status 2 (#668)

* tmp

* fix tests

* fix int test

* fix config

* Update integration/common.go

---------

Co-authored-by: Gabe <[email protected]>
  • Loading branch information
michaelneale and decentralgabe authored Aug 23, 2023
1 parent d23383b commit ce5957a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type ServicesConfig struct {
StorageProvider string `toml:"storage" conf:"default:bolt"`
StorageOptions []storage.Option `toml:"storage_option"`
ServiceEndpoint string `toml:"service_endpoint" conf:"default:http://localhost:8080"`
StatusEndpoint string `toml:"status_endpoint"`

// Application level encryption configuration. Defines how values are encrypted before they are stored in the
// configured KV store.
Expand Down
24 changes: 18 additions & 6 deletions config/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ var (
// serviceInfo is intended to be a singleton object for static service info.
// WARNING: it is **NOT** currently thread safe.
type serviceInfo struct {
name string
description string
version string
apiBase string
apiVersion string
servicePaths map[framework.Type]string
name string
description string
version string
apiBase string
statusBaseURL string
apiVersion string
servicePaths map[framework.Type]string
}

func Name() string {
Expand All @@ -57,6 +58,17 @@ func GetAPIBase() string {
return si.apiBase
}

func SetStatusBase(url string) {
if strings.LastIndexAny(url, "/") == len(url)-1 {
url = url[:len(url)-1]
}
si.statusBaseURL = url
}

func GetStatusBase() string {
return si.statusBaseURL
}

func SetServicePath(service framework.Type, path string) {
// normalize path
if strings.IndexAny(path, "/") == 0 {
Expand Down
1 change: 1 addition & 0 deletions config/kitchensink.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enable_schema_caching = true

[services]
service_endpoint = "http://localhost:8080"
status_endpoint = "https://our-site.com/status"

# Uncomment one of the following database configurations

Expand Down
6 changes: 0 additions & 6 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/tbd54566975/ssi-service/config"
credmodel "github.com/tbd54566975/ssi-service/internal/credential"
"github.com/tbd54566975/ssi-service/internal/keyaccess"
"github.com/tbd54566975/ssi-service/internal/util"
"github.com/tbd54566975/ssi-service/pkg/server/router"
"github.com/tbd54566975/ssi-service/pkg/service/framework"
)

const (
Expand All @@ -47,10 +45,6 @@ func init() {
DisableQuote: true,
ForceColors: true,
})

config.SetAPIBase(endpoint)
config.SetServicePath(framework.Credential, "/credentials")
config.SetServicePath(framework.Schema, "/schemas")
}

type didConfigurationResourceParams struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/router/testutils_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package router

import (
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -28,6 +29,7 @@ func TestMain(t *testing.M) {
testutil.EnableSchemaCaching()
config.SetAPIBase(testServerURL)
config.SetServicePath(framework.Credential, "/credentials")
config.SetStatusBase(fmt.Sprintf("%s/status", config.GetServicePath(framework.Credential)))
os.Exit(t.Run())
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package server

import (
"fmt"
"os"

sdkutil "github.com/TBD54566975/ssi-sdk/util"
Expand Down Expand Up @@ -85,7 +86,7 @@ func NewSSIServer(shutdown chan os.Signal, cfg config.SSIServiceConfig) (*SSISer
if err = SchemaAPI(v1, ssi.Schema, ssi.Webhook); err != nil {
return nil, sdkutil.LoggingErrorMsg(err, "unable to instantiate Schema API")
}
if err = CredentialAPI(v1, ssi.Credential, ssi.Webhook); err != nil {
if err = CredentialAPI(v1, ssi.Credential, ssi.Webhook, cfg.Services.StatusEndpoint); err != nil {
return nil, sdkutil.LoggingErrorMsg(err, "unable to instantiate Credential API")
}
if err = OperationAPI(v1, ssi.Operation); err != nil {
Expand Down Expand Up @@ -199,7 +200,7 @@ func SchemaAPI(rg *gin.RouterGroup, service svcframework.Service, webhookService
}

// CredentialAPI registers all HTTP handlers for the Credentials Service
func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookService *webhook.Service) (err error) {
func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookService *webhook.Service, statusEndpoint string) (err error) {
credRouter, err := router.NewCredentialRouter(service)
if err != nil {
return sdkutil.LoggingErrorMsg(err, "creating credential router")
Expand All @@ -208,6 +209,13 @@ func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookSer
// make sure the credential service is configured to use the correct path
config.SetServicePath(svcframework.Credential, CredentialsPrefix)

// allows for a custom URI to be used for status list credentials, if not set, we use the default path
if statusEndpoint != "" {
config.SetStatusBase(statusEndpoint)
} else {
config.SetStatusBase(fmt.Sprintf("%s/status", config.GetServicePath(svcframework.Credential)))
}

// Credentials
credentialAPI := rg.Group(CredentialsPrefix)
credentialAPI.PUT("", middleware.Webhook(webhookService, webhook.Credential, webhook.Create), credRouter.CreateCredential)
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"bytes"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/tbd54566975/ssi-service/config"
credmodel "github.com/tbd54566975/ssi-service/internal/credential"
"github.com/tbd54566975/ssi-service/internal/util"
Expand Down Expand Up @@ -296,6 +298,7 @@ func testCredentialRouter(t *testing.T, bolt storage.ServiceStorage, keyStore *k

// set endpoint in service info
config.SetServicePath(svcframework.Credential, CredentialsPrefix)
config.SetStatusBase(fmt.Sprintf("%s/status", config.GetServicePath(svcframework.Credential)))

// create router for service
credentialRouter, err := router.NewCredentialRouter(credentialService)
Expand Down
4 changes: 1 addition & 3 deletions pkg/service/credential/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/tbd54566975/ssi-service/config"
credint "github.com/tbd54566975/ssi-service/internal/credential"
"github.com/tbd54566975/ssi-service/pkg/service/framework"
"github.com/tbd54566975/ssi-service/pkg/storage"
)

Expand Down Expand Up @@ -69,8 +68,7 @@ func (s Service) createStatusListEntryForCredential(ctx context.Context, credID

func (s Service) createStatusListCredential(ctx context.Context, tx storage.Tx, statusPurpose statussdk.StatusPurpose, issuerID, fullyQualifiedVerificationMethodID string, slcMetadata StatusListCredentialMetadata) (int, *credential.VerifiableCredential, error) {
statusListID := uuid.NewString()
statusListURI := fmt.Sprintf("%s/status/%s", config.GetServicePath(framework.Credential), statusListID)

statusListURI := fmt.Sprintf("%s/%s", config.GetStatusBase(), statusListID)
generatedStatusListCredential, err := statussdk.GenerateStatusList2021Credential(statusListURI, issuerID, statusPurpose, []credential.VerifiableCredential{})
if err != nil {
return -1, nil, sdkutil.LoggingErrorMsg(err, "could not generate status list")
Expand Down

0 comments on commit ce5957a

Please sign in to comment.