From 95dd24c7183a46c2f7b91910023b84e3a6369dc0 Mon Sep 17 00:00:00 2001 From: gabe Date: Tue, 1 Aug 2023 09:59:20 -0700 Subject: [PATCH] remove access --- config/info.go | 48 +++++++++++++++------------- integration/common.go | 6 ++-- pkg/server/router/credential_test.go | 4 +-- pkg/server/server.go | 22 ++++++------- pkg/server/server_test.go | 4 +-- pkg/service/credential/service.go | 2 +- pkg/service/credential/status.go | 2 +- pkg/service/schema/service.go | 2 +- 8 files changed, 46 insertions(+), 44 deletions(-) diff --git a/config/info.go b/config/info.go index 99ab51b0e..772d1868d 100644 --- a/config/info.go +++ b/config/info.go @@ -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 @@ -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] } diff --git a/integration/common.go b/integration/common.go index 29b7261fa..09628ce52 100644 --- a/integration/common.go +++ b/integration/common.go @@ -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 { diff --git a/pkg/server/router/credential_test.go b/pkg/server/router/credential_test.go index 0642b0a82..d69058655 100644 --- a/pkg/server/router/credential_test.go +++ b/pkg/server/router/credential_test.go @@ -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) { diff --git a/pkg/server/server.go b/pkg/server/server.go index e0943a0d9..dbc760428 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index e9974d97a..429b09f5b 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -45,7 +45,7 @@ const ( func TestMain(t *testing.M) { testutil.EnableSchemaCaching() - config.GetServiceInfo().SetAPIBase(testServerURL) + config.SetAPIBase(testServerURL) os.Exit(t.Run()) } @@ -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) diff --git a/pkg/service/credential/service.go b/pkg/service/credential/service.go index 780c7e3eb..7f8f02290 100644 --- a/pkg/service/credential/service.go +++ b/pkg/service/credential/service.go @@ -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) } diff --git a/pkg/service/credential/status.go b/pkg/service/credential/status.go index 194bd9c7d..6037b4c2d 100644 --- a/pkg/service/credential/status.go +++ b/pkg/service/credential/status.go @@ -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 { diff --git a/pkg/service/schema/service.go b/pkg/service/schema/service.go index 56b4eb2c9..77c1a8cb2 100644 --- a/pkg/service/schema/service.go +++ b/pkg/service/schema/service.go @@ -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}