Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor setting util #165

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/settingsvc/internal/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (s *GrpcSettingServer) CreateSetting(ctx context.Context, creq *settingProt

func (s *GrpcSettingServer) GetSettingValue(ctx context.Context, sreq *settingProto.Id) (*settingProto.SettingValue, error) {
resp := &settingProto.SettingValue{}
setting, err := GetSetting(SettingName(sreq.GetName()))
setting, err := GetSetting(settingUtil.SettingName(sreq.GetName()))

if err != nil {
newErr := status.Newf(
Expand Down
27 changes: 14 additions & 13 deletions services/settingsvc/internal/preinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/golang/glog"
"github.com/hobbyfarm/gargantua/v3/pkg/labels"
settingUtil "github.com/hobbyfarm/gargantua/v3/pkg/setting"
"github.com/hobbyfarm/gargantua/v3/pkg/util"
settingProto "github.com/hobbyfarm/gargantua/v3/protos/setting"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -86,7 +87,7 @@ func scopes() []*settingProto.CreateScopeRequest {
func predefinedSettings() []*settingProto.CreateSettingRequest {
return []*settingProto.CreateSettingRequest{
{
Name: string(SettingAdminUIMOTD),
Name: string(settingUtil.SettingAdminUIMOTD),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "admin-ui",
Expand All @@ -99,7 +100,7 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
},
{
Name: string(SettingUIMOTD),
Name: string(settingUtil.SettingUIMOTD),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "public",
Expand All @@ -112,7 +113,7 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
},
{
Name: string(SettingRegistrationDisabled),
Name: string(settingUtil.SettingRegistrationDisabled),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "public",
Expand All @@ -126,7 +127,7 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
{

Name: string(ScheduledEventRetentionTime),
Name: string(settingUtil.ScheduledEventRetentionTime),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "gargantua",
Expand All @@ -139,11 +140,11 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
},
{
Name: string(SettingRegistrationPrivacyPolicyRequired),
Name: string(settingUtil.SettingRegistrationPrivacyPolicyRequired),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingWeight: "3",
},
Value: "false",
Expand All @@ -154,11 +155,11 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
},
{
Name: string(SettingRegistrationPrivacyPolicyLink),
Name: string(settingUtil.SettingRegistrationPrivacyPolicyLink),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingWeight: "2",
},
Value: "",
Expand All @@ -169,11 +170,11 @@ func predefinedSettings() []*settingProto.CreateSettingRequest {
},
},
{
Name: string(SettingRegistrationPrivacyPolicyLinkName),
Name: string(settingUtil.SettingRegistrationPrivacyPolicyLinkName),
Namespace: util.GetReleaseNamespace(),
Labels: map[string]string{
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingScope: "public",
labels.SettingGroup: "privacy-policy",
labels.SettingWeight: "1",
},
Value: "",
Expand Down
16 changes: 2 additions & 14 deletions services/settingsvc/internal/settingclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1"
hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned"
"github.com/hobbyfarm/gargantua/v3/pkg/client/informers/externalversions"
settingUtil "github.com/hobbyfarm/gargantua/v3/pkg/setting"
"github.com/hobbyfarm/gargantua/v3/pkg/util"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -17,19 +18,6 @@ var (
settings = map[string]*v1.Setting{}
)

// TODO remove SettingName and consts in facor of settingUtil
const (
SettingRegistrationDisabled SettingName = "registration-disabled"
SettingAdminUIMOTD SettingName = "motd-admin-ui"
SettingUIMOTD SettingName = "motd-ui"
ScheduledEventRetentionTime SettingName = "scheduledevent-retention-time"
SettingRegistrationPrivacyPolicyRequired SettingName = "registration-privacy-policy-required"
SettingRegistrationPrivacyPolicyLink SettingName = "registration-privacy-policy-link"
SettingRegistrationPrivacyPolicyLinkName SettingName = "registration-privacy-policy-linkname"
)

type SettingName string

type SettingsHandlers struct {
}

Expand Down Expand Up @@ -72,7 +60,7 @@ func WatchSettings(ctx context.Context,
return nil
}

func GetSetting(name SettingName) (*v1.Setting, error) {
func GetSetting(name settingUtil.SettingName) (*v1.Setting, error) {
var set, ok = settings[string(name)]
if !ok {
glog.Errorf("error retrieving setting %s", name)
Expand Down