mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Auth: Use camelCase in SSO Settings API (#78480)
Return/accept camelCase fields in sso setting api
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt/strcase"
|
||||
)
|
||||
|
||||
type SettingsSource int
|
||||
@@ -39,6 +41,46 @@ func (s SSOSetting) TableName() string {
|
||||
return "sso_setting"
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface and converts the s.Settings from map[string]any to map[string]any in camelCase
|
||||
func (s SSOSetting) MarshalJSON() ([]byte, error) {
|
||||
type Alias SSOSetting
|
||||
aux := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(&s),
|
||||
}
|
||||
|
||||
settings := make(map[string]any)
|
||||
for k, v := range aux.Settings {
|
||||
settings[strcase.ToLowerCamel(k)] = v
|
||||
}
|
||||
|
||||
aux.Settings = settings
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface and converts the settings from map[string]any camelCase to map[string]interface{} snake_case
|
||||
func (s *SSOSetting) UnmarshalJSON(data []byte) error {
|
||||
type Alias SSOSetting
|
||||
aux := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(s),
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
settings := make(map[string]any)
|
||||
for k, v := range aux.Settings {
|
||||
settings[strcase.ToSnake(k)] = v
|
||||
}
|
||||
|
||||
s.Settings = settings
|
||||
return nil
|
||||
}
|
||||
|
||||
type SSOSettingsResponse struct {
|
||||
Settings map[string]interface{} `json:"settings"`
|
||||
Provider string `json:"type"`
|
||||
|
||||
Reference in New Issue
Block a user