Skip to content

Commit

Permalink
remove access
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed Aug 1, 2023
1 parent a3c0c6d commit 95dd24c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
48 changes: 25 additions & 23 deletions config/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ import (
const (
ServiceName = "ssi-service"
ServiceVersion = "0.0.3"
APIVersion = "v1"
)

var (
serviceInfo ServiceInfo
once sync.Once
si *serviceInfo
once sync.Once
)

// GetServiceInfo provides ServiceInfo as a singleton
func GetServiceInfo() ServiceInfo {
// getServiceInfo provides serviceInfo as a singleton
func getServiceInfo() *serviceInfo {
once.Do(func() {
serviceInfo = ServiceInfo{
si = &serviceInfo{
name: ServiceName,
description: "The Self Sovereign Identity Service is a RESTful web service that facilitates all things relating" +
" to DIDs, VCs, and related standards-based interactions.",
version: ServiceVersion,
apiVersion: "v1",
apiVersion: APIVersion,
servicePaths: make(map[framework.Type]string),
}
})

return serviceInfo
return si
}

// ServiceInfo is intended to be a (mostly) read-only singleton object for static service info
type ServiceInfo struct {
// serviceInfo is intended to be a (mostly) read-only singleton object for static service info
type serviceInfo struct {
name string
description string
version string
Expand All @@ -43,37 +44,38 @@ type ServiceInfo struct {
servicePaths map[framework.Type]string
}

func (si *ServiceInfo) Name() string {
return si.name
func Name() string {
return getServiceInfo().name
}

func (si *ServiceInfo) Description() string {
return si.description
func Description() string {
return getServiceInfo().description
}

func (si *ServiceInfo) Version() string {
return si.version
func (si *serviceInfo) Version() string {
return getServiceInfo().version
}

func (si *ServiceInfo) SetAPIBase(url string) {
func SetAPIBase(url string) {
if strings.LastIndexAny(url, "/") == len(url)-1 {
url = url[:len(url)-1]
}
si.apiBase = url
getServiceInfo().apiBase = url
}

func (si *ServiceInfo) GetAPIBase() string {
return si.apiBase
func GetAPIBase() string {
return getServiceInfo().apiBase
}

func (si *ServiceInfo) SetServicePath(service framework.Type, path string) {
func SetServicePath(service framework.Type, path string) {
// normalize path
if strings.IndexAny(path, "/") == 0 {
path = path[1:]
}
si.servicePaths[service] = strings.Join([]string{si.apiBase, si.apiVersion, path}, "/")
base := getServiceInfo().apiBase
getServiceInfo().servicePaths[service] = strings.Join([]string{base, APIVersion, path}, "/")
}

func (si *ServiceInfo) GetServicePath(service framework.Type) string {
return si.servicePaths[service]
func GetServicePath(service framework.Type) string {
return getServiceInfo().servicePaths[service]
}
6 changes: 3 additions & 3 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func init() {
ForceColors: true,
})

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

type didConfigurationResourceParams struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/router/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

func TestCredentialRouter(t *testing.T) {

config.GetServiceInfo().SetAPIBase("http://localhost:1234")
config.GetServiceInfo().SetServicePath(framework.Credential, "/credentials")
config.SetAPIBase("http://localhost:1234")
config.SetServicePath(framework.Credential, "/credentials")

for _, test := range testutil.TestDatabases {
t.Run(test.Name, func(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewSSIServer(shutdown chan os.Signal, cfg config.SSIServiceConfig) (*SSISer
}

// make sure to set the api base in our service info
config.GetServiceInfo().SetAPIBase(cfg.Services.ServiceEndpoint)
config.SetAPIBase(cfg.Services.ServiceEndpoint)

// service-level routers
engine.GET(HealthPrefix, router.Health)
Expand Down Expand Up @@ -149,7 +149,7 @@ func KeyStoreAPI(rg *gin.RouterGroup, service svcframework.Service) (err error)
}

// make sure the keystore service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.KeyStore, KeyStorePrefix)
config.SetServicePath(svcframework.KeyStore, KeyStorePrefix)
keyStoreAPI := rg.Group(KeyStorePrefix)
keyStoreAPI.PUT("", keyStoreRouter.StoreKey)
keyStoreAPI.GET("/:id", keyStoreRouter.GetKeyDetails)
Expand All @@ -166,7 +166,7 @@ func DecentralizedIdentityAPI(rg *gin.RouterGroup, service *didsvc.Service, did
batchDIDRouter := router.NewBatchDIDRouter(did)

// make sure the DID service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.DID, DIDsPrefix)
config.SetServicePath(svcframework.DID, DIDsPrefix)
didAPI := rg.Group(DIDsPrefix)
didAPI.GET("", didRouter.ListDIDMethods)
didAPI.PUT("/:method", middleware.Webhook(webhookService, webhook.DID, webhook.Create), didRouter.CreateDIDByMethod)
Expand All @@ -186,7 +186,7 @@ func SchemaAPI(rg *gin.RouterGroup, service svcframework.Service, webhookService
}

// make sure the schema service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Schema, SchemasPrefix)
config.SetServicePath(svcframework.Schema, SchemasPrefix)
schemaAPI := rg.Group(SchemasPrefix)
schemaAPI.PUT("", middleware.Webhook(webhookService, webhook.Schema, webhook.Create), schemaRouter.CreateSchema)
schemaAPI.GET("/:id", schemaRouter.GetSchema)
Expand All @@ -203,7 +203,7 @@ func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookSer
}

// make sure the credential service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Credential, CredentialsPrefix)
config.SetServicePath(svcframework.Credential, CredentialsPrefix)

// Credentials
credentialAPI := rg.Group(CredentialsPrefix)
Expand All @@ -229,7 +229,7 @@ func PresentationAPI(rg *gin.RouterGroup, service svcframework.Service, webhookS
}

// make sure the presentation service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Presentation, PresentationsPrefix)
config.SetServicePath(svcframework.Presentation, PresentationsPrefix)

presDefAPI := rg.Group(PresentationsPrefix + DefinitionsPrefix)
presDefAPI.PUT("", presRouter.CreateDefinition)
Expand Down Expand Up @@ -259,7 +259,7 @@ func OperationAPI(rg *gin.RouterGroup, service svcframework.Service) (err error)
}

// make sure the operation service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Operation, OperationPrefix)
config.SetServicePath(svcframework.Operation, OperationPrefix)

operationAPI := rg.Group(OperationPrefix)
operationAPI.GET("", operationRouter.ListOperations)
Expand All @@ -278,7 +278,7 @@ func ManifestAPI(rg *gin.RouterGroup, service svcframework.Service, webhookServi
}

// make sure the manifest service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Manifest, ManifestsPrefix)
config.SetServicePath(svcframework.Manifest, ManifestsPrefix)

manifestAPI := rg.Group(ManifestsPrefix)
manifestAPI.PUT("", middleware.Webhook(webhookService, webhook.Manifest, webhook.Create), manifestRouter.CreateManifest)
Expand Down Expand Up @@ -314,7 +314,7 @@ func IssuanceAPI(rg *gin.RouterGroup, service svcframework.Service) error {
}

// make sure the issuance service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Issuance, IssuanceTemplatePrefix)
config.SetServicePath(svcframework.Issuance, IssuanceTemplatePrefix)

issuanceAPI := rg.Group(IssuanceTemplatePrefix)
issuanceAPI.PUT("", issuanceRouter.CreateIssuanceTemplate)
Expand All @@ -332,7 +332,7 @@ func WebhookAPI(rg *gin.RouterGroup, service svcframework.Service) (err error) {
}

// make sure the webhook service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.Webhook, WebhookPrefix)
config.SetServicePath(svcframework.Webhook, WebhookPrefix)

webhookAPI := rg.Group(WebhookPrefix)
webhookAPI.PUT("", webhookRouter.CreateWebhook)
Expand All @@ -353,7 +353,7 @@ func DIDConfigurationAPI(rg *gin.RouterGroup, service svcframework.Service) erro
}

// make sure the did configuration service is configured to use the correct path
config.GetServiceInfo().SetServicePath(svcframework.DIDConfiguration, DIDConfigurationsPrefix)
config.SetServicePath(svcframework.DIDConfiguration, DIDConfigurationsPrefix)

webhookAPI := rg.Group(DIDConfigurationsPrefix)
webhookAPI.PUT("", didConfigurationsRouter.CreateDIDConfiguration)
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

func TestMain(t *testing.M) {
testutil.EnableSchemaCaching()
config.GetServiceInfo().SetAPIBase(testServerURL)
config.SetAPIBase(testServerURL)
os.Exit(t.Run())
}

Expand Down Expand Up @@ -310,7 +310,7 @@ func testCredentialRouter(t *testing.T, bolt storage.ServiceStorage, keyStore *k
credentialService := testCredentialService(t, bolt, keyStore, did, schema)

// set endpoint in service info
config.GetServiceInfo().SetServicePath(svcframework.Credential, CredentialsPrefix)
config.SetServicePath(svcframework.Credential, CredentialsPrefix)

// create router for service
credentialRouter, err := router.NewCredentialRouter(credentialService)
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/credential/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s Service) createCredential(ctx context.Context, request CreateCredentialR

builder := credential.NewVerifiableCredentialBuilder()
credentialID := uuid.NewString()
credentialURI := config.GetServiceInfo().GetServicePath(framework.Credential) + "/" + credentialID
credentialURI := config.GetServicePath(framework.Credential) + "/" + credentialID
if err := builder.SetID(credentialURI); err != nil {
return nil, sdkutil.LoggingErrorMsgf(err, "could not build credential when setting id: %s", credentialURI)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/credential/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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.GetServiceInfo().GetServicePath(framework.Credential), statusListID)
statusListURI := fmt.Sprintf("%s/status/%s", config.GetServicePath(framework.Credential), statusListID)

generatedStatusListCredential, err := statussdk.GenerateStatusList2021Credential(statusListURI, issuerID, statusPurpose, []credential.VerifiableCredential{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/schema/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s Service) CreateSchema(ctx context.Context, request CreateSchemaRequest)
// if the schema is a credential schema, the credential's id is a fully qualified URI
// if the schema is a JSON schema, the schema's id is a fully qualified URI
schemaID := uuid.NewString()
schemaURI := strings.Join([]string{config.GetServiceInfo().GetServicePath(framework.Schema), schemaID}, "/")
schemaURI := strings.Join([]string{config.GetServicePath(framework.Schema), schemaID}, "/")

// create schema for storage
storedSchema := StoredSchema{ID: schemaID}
Expand Down

0 comments on commit 95dd24c

Please sign in to comment.