...

Source file src/edge-infra.dev/pkg/edge/iam/config/bsl.go

Documentation: edge-infra.dev/pkg/edge/iam/config

     1  package config
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  	"k8s.io/client-go/kubernetes"
     9  	"k8s.io/client-go/rest"
    10  
    11  	"edge-infra.dev/pkg/edge/bsl"
    12  	"edge-infra.dev/pkg/edge/constants"
    13  )
    14  
    15  type BslInfo struct {
    16  	organizationID   string
    17  	organizationName string
    18  	timeZone         string
    19  	siteID           string
    20  }
    21  
    22  func getBslInfo() (*BslInfo, error) {
    23  	config, err := rest.InClusterConfig()
    24  	if err != nil {
    25  		return nil, fmt.Errorf("failed to create in-cluster config. %v", err.Error())
    26  	}
    27  
    28  	clientset, err := kubernetes.NewForConfig(config)
    29  	if err != nil {
    30  		return nil, fmt.Errorf("failed to create clientset. %v", err.Error())
    31  	}
    32  
    33  	cm := clientset.CoreV1().ConfigMaps(constants.KubePublicNamespace)
    34  	bslConfigmap, err := cm.Get(context.Background(), bsl.BSLInfoConfigMapName, metav1.GetOptions{})
    35  	if err != nil {
    36  		return nil, fmt.Errorf("failed to get bsl-info configmap. %v", err.Error())
    37  	}
    38  
    39  	bslInfo := &BslInfo{
    40  		organizationID:   bslConfigmap.Data[bsl.BSLOrganizationID],
    41  		organizationName: bslConfigmap.Data[bsl.BSLSiteOrganizationName],
    42  		siteID:           bslConfigmap.Data[bsl.BSLSiteID],
    43  		timeZone:         bslConfigmap.Data[bsl.BSLSiteTimeZone],
    44  	}
    45  
    46  	return bslInfo, nil
    47  }
    48  

View as plain text