diff --git a/capability/well-known.go b/capability/well-known.go index dc9ac113..d9901e5f 100644 --- a/capability/well-known.go +++ b/capability/well-known.go @@ -16,21 +16,29 @@ type WellKnownInfo struct { ApiEndpoints map[string]string `json:"api-endpoints"` } -func NewWellKnownInfoObj(key jwk.Key, mediaTypes []string, version string, serviceState string, endpoints map[string]string) (*WellKnownInfo, error) { - // MUST be kept in sync with proto/state.proto - var ssTrans = map[string]string{ - "SERVICE_STATUS_UNSPECIFIED": "UNSPECIFIED", - "SERVICE_STATUS_DOWN": "DOWN", - "SERVICE_STATUS_INITIALIZING": "INITIALIZING", - "SERVICE_STATUS_READY": "READY", - "SERVICE_STATUS_TERMINATING": "TERMINATING", +var ssTrans = map[string]string{ + "SERVICE_STATUS_UNSPECIFIED": "UNSPECIFIED", + "SERVICE_STATUS_DOWN": "DOWN", + "SERVICE_STATUS_INITIALIZING": "INITIALIZING", + "SERVICE_STATUS_READY": "READY", + "SERVICE_STATUS_TERMINATING": "TERMINATING", +} + +func ServiceStateToAPI(ss string) string { + t, ok := ssTrans[ss] + if !ok { + return "UNKNOWN" } + return t +} +func NewWellKnownInfoObj(key jwk.Key, mediaTypes []string, version string, serviceState string, endpoints map[string]string) (*WellKnownInfo, error) { + // MUST be kept in sync with proto/state.proto obj := &WellKnownInfo{ PublicKey: key, MediaTypes: mediaTypes, Version: version, - ServiceState: ssTrans[serviceState], + ServiceState: ServiceStateToAPI(serviceState), ApiEndpoints: endpoints, } diff --git a/provisioning/api/handler_test.go b/provisioning/api/handler_test.go index b2874f36..e9ccfa2b 100644 --- a/provisioning/api/handler_test.go +++ b/provisioning/api/handler_test.go @@ -599,7 +599,7 @@ func TestHandler_GetWellKnownProvisioningInfo_ok(t *testing.T) { expectedBody := capability.WellKnownInfo{ MediaTypes: supportedMediaTypes, Version: testGoodServiceState.ServerVersion, - ServiceState: testGoodServiceState.Status.String(), + ServiceState: capability.ServiceStateToAPI(testGoodServiceState.Status.String()), ApiEndpoints: publicApiMap, } @@ -643,7 +643,7 @@ func TestHandler_GetWellKnownProvisioningInfo_GetRegisteredMediaTypes_empty(t *t expectedBody := capability.WellKnownInfo{ MediaTypes: []string{}, Version: testGoodServiceState.ServerVersion, - ServiceState: testGoodServiceState.Status.String(), + ServiceState: capability.ServiceStateToAPI(testGoodServiceState.Status.String()), ApiEndpoints: publicApiMap, } diff --git a/verification/api/handler_test.go b/verification/api/handler_test.go index 84c11b37..a545d9f9 100644 --- a/verification/api/handler_test.go +++ b/verification/api/handler_test.go @@ -957,7 +957,7 @@ func TestHandler_GetWellKnownVerificationInfo_ok(t *testing.T) { expectedBody := capability.WellKnownInfo{ MediaTypes: supportedMediaTypes, Version: testGoodServiceState.ServerVersion, - ServiceState: testGoodServiceState.Status.String(), + ServiceState: capability.ServiceStateToAPI(testGoodServiceState.Status.String()), ApiEndpoints: publicApiMap, }