Repository: TBD54566975/ssi-service
Pull request #666 (2023-08-23 14:53:59)

Status


Patch:
diff --git a/config/config.go b/config/config.go
index 22f6db9..546f3bb 100644
--- a/config/config.go
+++ b/config/config.go
@@ -68,7 +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" conf:"default:"`
+	StatusEndpoint  string           `toml:"status_endpoint"`
 
 	// Application level encryption configuration. Defines how values are encrypted before they are stored in the
 	// configured KV store.
diff --git a/config/kitchensink.toml b/config/kitchensink.toml
index 26daf15..e56fdf5 100644
--- a/config/kitchensink.toml
+++ b/config/kitchensink.toml
@@ -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
 
diff --git a/integration/common.go b/integration/common.go
index 6de315f..67c11ad 100644
--- a/integration/common.go
+++ b/integration/common.go
@@ -51,6 +51,7 @@ func init() {
 	config.SetAPIBase(endpoint)
 	config.SetServicePath(framework.Credential, "/credentials")
 	config.SetServicePath(framework.Schema, "/schemas")
+	config.SetStatusBase(fmt.Sprintf("%s/status", config.GetServicePath(framework.Credential)))
 }
 
 type didConfigurationResourceParams struct {
diff --git a/pkg/server/server.go b/pkg/server/server.go
index 93b81c6..0749e62 100644
--- a/pkg/server/server.go
+++ b/pkg/server/server.go
@@ -3,6 +3,7 @@
 package server
 
 import (
+	"fmt"
 	"os"
 
 	sdkutil "github.com/TBD54566975/ssi-sdk/util"
@@ -67,7 +68,13 @@ func NewSSIServer(shutdown chan os.Signal, cfg config.SSIServiceConfig) (*SSISer
 
 	// make sure to set the api base in our service info
 	config.SetAPIBase(cfg.Services.ServiceEndpoint)
-	config.SetStatusBase(cfg.Services.StatusEndpoint)
+
+	// allows for a custom URI to be used for status list credentials, if not set, we use the default path
+	if cfg.Services.StatusEndpoint != "" {
+		config.SetStatusBase(cfg.Services.StatusEndpoint)
+	} else {
+		config.SetStatusBase(fmt.Sprintf("%s/status", config.GetServicePath(svcframework.Credential)))
+	}
 
 	// service-level routers
 	engine.GET(HealthPrefix, router.Health)
diff --git a/pkg/service/credential/status.go b/pkg/service/credential/status.go
index d0b8ce8..6d5403f 100644
--- a/pkg/service/credential/status.go
+++ b/pkg/service/credential/status.go
@@ -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"
 )
 
@@ -67,16 +66,9 @@ func (s Service) createStatusListEntryForCredential(ctx context.Context, credID
 	}, nil
 }
 
-func getStatusURI(statusBase string, statusListID string) string {
-	if len(statusBase) > 0 {
-		return fmt.Sprintf("%s/%s", statusBase, statusListID)
-	}
-	return fmt.Sprintf("%s/status/%s", config.GetServicePath(framework.Credential), statusListID)
-}
-
 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 := getStatusURI(config.GetStatusBase(), 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")


Test patch:
diff --git a/pkg/server/router/testutils_test.go b/pkg/server/router/testutils_test.go
index dda9ae0..8078ddd 100644
--- a/pkg/server/router/testutils_test.go
+++ b/pkg/server/router/testutils_test.go
@@ -1,6 +1,7 @@
 package router
 
 import (
+	"fmt"
 	"os"
 	"testing"
 
@@ -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())
 }
 
diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go
index f0306b3..091fe9b 100644
--- a/pkg/server/server_test.go
+++ b/pkg/server/server_test.go
@@ -2,6 +2,7 @@ package server
 
 import (
 	"bytes"
+	"fmt"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -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"
@@ -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)