github.com/nais/knorten@v0.0.0-20240104110906-55926958e361/pkg/helm/jupyterhub.go (about)

     1  package helm
     2  
     3  import (
     4  	"context"
     5  	"database/sql"
     6  	"encoding/json"
     7  	"errors"
     8  
     9  	"github.com/nais/knorten/pkg/database/gensql"
    10  )
    11  
    12  const (
    13  	profileListKey = "singleuser.profileList"
    14  )
    15  
    16  func (c Client) concatenateImageProfiles(ctx context.Context, teamID string, values map[string]any) error {
    17  	userProfileList, err := c.repo.TeamValueGet(ctx, profileListKey, teamID)
    18  	if err != nil {
    19  		if errors.Is(err, sql.ErrNoRows) {
    20  			return nil
    21  		}
    22  		return err
    23  	}
    24  	userProfiles := []map[string]any{}
    25  	if err := json.Unmarshal([]byte(userProfileList.Value), &userProfiles); err != nil {
    26  		return err
    27  	}
    28  
    29  	globalProfileList, err := c.repo.GlobalValueGet(ctx, gensql.ChartTypeJupyterhub, profileListKey)
    30  	if err != nil {
    31  		return err
    32  	}
    33  	globalProfiles := []map[string]any{}
    34  	if err := json.Unmarshal([]byte(globalProfileList.Value), &globalProfiles); err != nil {
    35  		return err
    36  	}
    37  
    38  	profiles := append(userProfiles, globalProfiles...)
    39  	mergeMaps(values, map[string]any{
    40  		"singleuser": map[string]any{
    41  			"profileList": profiles,
    42  		},
    43  	})
    44  
    45  	return nil
    46  }