<commit_before>package k8s

import (
	"fmt"
	"strings"

	"github.com/Bplotka/oidc"
	"github.com/Bplotka/oidc/login"
	cfg "k8s.io/client-go/tools/clientcmd"
	api "k8s.io/client-go/tools/clientcmd/api"
)

var defaultKubeConfigPath = cfg.RecommendedHomeFile

// ConfigCache is an cache for OIDC tokens that installs token inside k8s user config directory in `Users:` sections of yaml.
// It is convenient for initial install of token (possibly refresh-token) for OIDC auth-provider. It stores config following
// set-credentials way of saving credentials:
//
//users:
//- name: <k8sUsers[0]>
//  user:
//    auth-provider:
//      config:
//        client-id: <clientID>
//        client-secret: <clientSecret>
//        extra-scopes: groups
//        id-token: <id-token>
//        idp-issuer-url: <provider>
//        refresh-token: <[optional] refresh-token)
//      name: oidc
//
type ConfigCache struct {
	cfg            login.Config
	users          map[string]struct{}
	kubeConfigPath string
}

// NewConfigCache constructs cache.
func NewConfigCache(loginCfg login.Config, k8sUsers ...string) *ConfigCache {
	users := map[string]struct{}{}
	// For easier lookup.
	for _, u := range k8sUsers {
		users[u] = struct{}{}
	}
	return &ConfigCache{cfg: loginCfg, users: users, kubeConfigPath: defaultKubeConfigPath}
}

func extraScopes(cfg login.Config) []string {
	var extra []string
	for _, scope := range cfg.Scopes {<commit_msg>Extended CacheConfig for setting custom kube config path.<commit_after>package k8s

import (
	"fmt"
	"strings"

	"github.com/Bplotka/oidc"
	"github.com/Bplotka/oidc/login"
	cfg "k8s.io/client-go/tools/clientcmd"
	api "k8s.io/client-go/tools/clientcmd/api"
)

var DefaultKubeConfigPath = cfg.RecommendedHomeFile

// ConfigCache is an cache for OIDC tokens that installs token inside k8s user config directory in `Users:` sections of yaml.
// It is convenient for initial install of token (possibly refresh-token) for OIDC auth-provider. It stores config following
// set-credentials way of saving credentials:
//
//users:
//- name: <k8sUsers[0]>
//  user:
//    auth-provider:
//      config:
//        client-id: <clientID>
//        client-secret: <clientSecret>
//        extra-scopes: groups
//        id-token: <id-token>
//        idp-issuer-url: <provider>
//        refresh-token: <[optional] refresh-token)
//      name: oidc
//
type ConfigCache struct {
	cfg            login.Config
	users          map[string]struct{}
	kubeConfigPath string
}

// NewConfigCache constructs cache.
func NewConfigCache(loginCfg login.Config, k8sUsers ...string) *ConfigCache {
	users := map[string]struct{}{}
	// For easier lookup.
	for _, u := range k8sUsers {
		users[u] = struct{}{}
	}
	return &ConfigCache{cfg: loginCfg, users: users, kubeConfigPath: DefaultKubeConfigPath}
}

// SetConfigPath sets custom path as config path for kube config.
func (c *ConfigCache) SetConfigPath(path string) {
	c.kubeConfigPath = path
}

func extraScopes(cfg login.Config) []string {
	var extra []string
	for _, scope := range cfg.Scopes {
{'fraction_non_alphanumeric': 0.12569740728585493, 'fraction_numerical': 0.005251066622907778, 'mean_word_length': 3.2569832402234637, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '5143543', 'n_tokens_mistral': 1012, 'n_tokens_neox': 996, 'n_words': 272}