<commit_before>package data

import (
	"fmt"
	"time"

	"github.com/feedhenry/mcp-standalone/pkg/mobile"
	"github.com/pkg/errors"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
	v1 "k8s.io/client-go/pkg/api/v1"
)

const apiKeyMapName = "mcp-mobile-keys"

// MobileAppValidator defines what a validator should do
type MobileAppValidator interface {
	PreCreate(a *mobile.App) error
	PreUpdate(old *mobile.App, new *mobile.App) error
}

// MobileAppRepo interacts with the data store that backs the mobile objects
type MobileAppRepo struct {
	client    corev1.ConfigMapInterface
	validator MobileAppValidator
}

// NewMobileAppRepo instansiates a new MobileAppRepo
func NewMobileAppRepo(c corev1.ConfigMapInterface, v MobileAppValidator) *MobileAppRepo {
	rep := &MobileAppRepo{
		client:    c,
		validator: v,
	}
	if rep.validator == nil {
		rep.validator = &DefaultMobileAppValidator{}
	}
	return rep
}

// UpdateAppApiKeys adds new app api key to apiKey mapping
func (mar *MobileAppRepo) UpdateAppAPIKeys(app *mobile.App) error {
	cm, err := mar.client.Get(apiKeyMapName, meta_v1.GetOptions{})
	if err != nil {
		return errors.Wrap(err, "updating api key config map, could not read")
	}
	if cm.Data == nil {
		cm.Data = map[string]string{}
	}
	cm.Data[app.ID] = app.APIKey
	if _, err := mar.client.Update(cm); err != nil {
		return errors.Wrap(err, "updating api key map, could not save map")
	}
	return nil
}

// DeleteAppAPIKey remove api key from apiKey mapping
func (mar *MobileAppRepo) RemoveAppAPIKeyByID(appID string) error {
	cm, err := mar.client.Get(apiKeyMapName, meta_v1.GetOptions{})
	if err != nil {<commit_msg>FH-4070 Match comment with function name<commit_after>package data

import (
	"fmt"
	"time"

	"github.com/feedhenry/mcp-standalone/pkg/mobile"
	"github.com/pkg/errors"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
	v1 "k8s.io/client-go/pkg/api/v1"
)

const apiKeyMapName = "mcp-mobile-keys"

// MobileAppValidator defines what a validator should do
type MobileAppValidator interface {
	PreCreate(a *mobile.App) error
	PreUpdate(old *mobile.App, new *mobile.App) error
}

// MobileAppRepo interacts with the data store that backs the mobile objects
type MobileAppRepo struct {
	client    corev1.ConfigMapInterface
	validator MobileAppValidator
}

// NewMobileAppRepo instansiates a new MobileAppRepo
func NewMobileAppRepo(c corev1.ConfigMapInterface, v MobileAppValidator) *MobileAppRepo {
	rep := &MobileAppRepo{
		client:    c,
		validator: v,
	}
	if rep.validator == nil {
		rep.validator = &DefaultMobileAppValidator{}
	}
	return rep
}

// UpdateAppApiKeys adds new app api key to apiKey mapping
func (mar *MobileAppRepo) UpdateAppAPIKeys(app *mobile.App) error {
	cm, err := mar.client.Get(apiKeyMapName, meta_v1.GetOptions{})
	if err != nil {
		return errors.Wrap(err, "updating api key config map, could not read")
	}
	if cm.Data == nil {
		cm.Data = map[string]string{}
	}
	cm.Data[app.ID] = app.APIKey
	if _, err := mar.client.Update(cm); err != nil {
		return errors.Wrap(err, "updating api key map, could not save map")
	}
	return nil
}

// RemoveAppAPIKeyByID remove api key from apiKey mapping
func (mar *MobileAppRepo) RemoveAppAPIKeyByID(appID string) error {
	cm, err := mar.client.Get(apiKeyMapName, meta_v1.GetOptions{})
	if err != nil {
{'fraction_non_alphanumeric': 0.11314623338257017, 'fraction_numerical': 0.008862629246676515, 'mean_word_length': 4.452495974235105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620688', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1212, 'n_words': 309}