github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/configuration/coreconfig/config_data.go (about)

     1  package coreconfig
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"code.cloudfoundry.org/cli/cf/models"
     7  	"code.cloudfoundry.org/cli/util/configv3"
     8  )
     9  
    10  type AuthPromptType string
    11  
    12  const (
    13  	AuthPromptTypeText     AuthPromptType = "TEXT"
    14  	AuthPromptTypePassword AuthPromptType = "PASSWORD"
    15  )
    16  
    17  type AuthPrompt struct {
    18  	Type        AuthPromptType
    19  	DisplayName string
    20  }
    21  
    22  type Data struct {
    23  	AccessToken              string
    24  	APIVersion               string
    25  	AsyncTimeout             uint
    26  	AuthorizationEndpoint    string
    27  	ColorEnabled             string
    28  	ConfigVersion            int
    29  	DopplerEndPoint          string
    30  	Locale                   string
    31  	MinCLIVersion            string
    32  	MinRecommendedCLIVersion string
    33  	OrganizationFields       models.OrganizationFields
    34  	PluginRepos              []models.PluginRepo
    35  	RefreshToken             string
    36  	RoutingAPIEndpoint       string
    37  	SpaceFields              models.SpaceFields
    38  	SSHOAuthClient           string
    39  	SSLDisabled              bool
    40  	Target                   string
    41  	Trace                    string
    42  	UaaEndpoint              string
    43  	UAAGrantType             string
    44  	UAAOAuthClient           string
    45  	UAAOAuthClientSecret     string
    46  }
    47  
    48  func NewData() *Data {
    49  	data := new(Data)
    50  
    51  	data.UAAOAuthClient = "cf"
    52  	data.UAAOAuthClientSecret = ""
    53  
    54  	return data
    55  }
    56  
    57  func (d *Data) JSONMarshalV3() ([]byte, error) {
    58  	d.ConfigVersion = configv3.CurrentConfigVersion
    59  	return json.MarshalIndent(d, "", "  ")
    60  }
    61  
    62  func (d *Data) JSONUnmarshalV3(input []byte) error {
    63  	err := json.Unmarshal(input, d)
    64  	if err != nil {
    65  		return err
    66  	}
    67  
    68  	if d.ConfigVersion != configv3.CurrentConfigVersion {
    69  		*d = Data{}
    70  		return nil
    71  	}
    72  
    73  	return nil
    74  }