Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-fossati committed Jul 7, 2023
1 parent 4932566 commit 41552b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions capability/well-known.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions provisioning/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion verification/api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 41552b0

Please sign in to comment.