Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding in seperate status base URI #660

Merged
merged 11 commits into from
Aug 23, 2023
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
1 change: 1 addition & 0 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
decentralgabe marked this conversation as resolved.
Show resolved Hide resolved

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
8 changes: 8 additions & 0 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 @@ -68,6 +69,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)

// 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)
engine.GET(ReadinessPrefix, router.Readiness(ssi.GetServices()))
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
Loading