// Print prints the complete information of component onto stdout (Note: long term this function should not need to access any parameters, but just print the information in struct)
Print prints the complete information of component onto stdout (Note: long term this function should not need to access any parameters, but just print the information in struct)
// Print prints the complete information of component onto stdout ( Note : long term this function should not need to access any parameters but just print the information in struct )
func (cfd *ComponentFullDescription) Print(client *occlient.Client) error {
	log.Describef("Component Name: ", cfd.GetName())
	log.Describef("Type: ", cfd.Spec.Type)
	if cfd.Spec.Source != "" {
		log.Describef("Source: ", cfd.Spec.Source)
	}
	if cfd.Spec.Env != nil {
		var output string
		for _, env := range cfd.Spec.Env {
			output += fmt.Sprintf(" · %v=%v\n", env.Name, env.Value)
		}
		if len(output) > 0 {
			output = output[:len(output)-1]
			log.Describef("Environment Variables:\n", output)
		}
	}
	if len(cfd.Spec.Storage.Items) > 0 {
		var output string
		for _, store := range cfd.Spec.Storage.Items {
			output += fmt.Sprintf(" · %v of size %v mounted to %v\n", store.Name, store.Spec.Size, store.Spec.Path)
		}
		if len(output) > 0 {
			output = output[:len(output)-1]
			log.Describef("Storage:\n", output)
		}
	}
	if len(cfd.Spec.URL.Items) > 0 {
		var output string
		for _, componentURL := range cfd.Spec.URL.Items {
			if componentURL.Status.State == urlpkg.StateTypePushed {
				output += fmt.Sprintf(" · %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, "", true), componentURL.Spec.Port)
			} else {
				output += fmt.Sprintf(" · URL named %s will be exposed via %v\n", componentURL.Name, componentURL.Spec.Port)
			}
		}
		output = output[:len(output)-1]
		log.Describef("URLs:\n", output)
	}
	if len(cfd.Status.LinkedServices) > 0 {
		var output string
		for _, linkedService := range cfd.Status.LinkedServices {
			if linkedService.SecretName == "" {
				output += fmt.Sprintf(" · %s\n", linkedService.ServiceName)
				continue
			}
			secrets, err := client.GetKubeClient().GetSecret(linkedService.SecretName, cfd.GetNamespace())
			if err != nil {
				return err
			}
			if len(secrets.Data) > 0 {
				var secretOutput string
				for i := range secrets.Data {
					if linkedService.MountVolume {
						secretOutput += fmt.Sprintf("    · %v\n", filepath.Join(linkedService.MountPath, i))
					} else {
						secretOutput += fmt.Sprintf("    · %v\n", i)
					}
				}
				if len(secretOutput) > 0 {
					secretOutput = secretOutput[:len(secretOutput)-1]
					if linkedService.MountVolume {
						output += fmt.Sprintf(" · %s\n   Files:\n%s\n", linkedService.ServiceName, secretOutput)
					} else {
						output += fmt.Sprintf(" · %s\n   Environment Variables:\n%s\n", linkedService.ServiceName, secretOutput)
					}
				}
			} else {
				output += fmt.Sprintf(" · %s\n", linkedService.SecretName)
			}
		}
		if len(output) > 0 {
			output = output[:len(output)-1]
			log.Describef("Linked Services:\n", output)
		}
	}
	return nil
}
func ( cfd * ComponentFullDescription ) Print ( client * occlient . Client ) error { log . Describef ( " " , cfd . GetName ( ) ) log . Describef ( " " , cfd . Spec . Type ) if cfd . Spec . Source != " " { log . Describef ( " " , cfd . Spec . Source ) } if cfd . Spec . Env != nil { var output string for _ , env := range cfd . Spec . Env { output += fmt . Sprintf ( " n" , nv. N ame, nv. V alue) } if len ( output ) > 0 { output = output [ : len ( output ) - 1 ] log . Describef ( " \n " , output ) } } if len ( cfd . Spec . Storage . Items ) > 0 { var output string for _ , store := range cfd . Spec . Storage . Items { output += fmt . Sprintf ( " n" , tore. N ame, tore. S pec. S ize, tore. S pec. P ath) } if len ( output ) > 0 { output = output [ : len ( output ) - 1 ] log . Describef ( " \n " , output ) } } if len ( cfd . Spec . URL . Items ) > 0 { var output string for _ , componentURL := range cfd . Spec . URL . Items { if componentURL . Status . State == urlpkg . StateTypePushed { output += fmt . Sprintf ( " n" , rlpkg. G etURLString( c omponentURL. S pec. P rotocol, omponentURL. S pec. H ost, " , rue) , omponentURL. S pec. P ort) } else { output += fmt . Sprintf ( " n" , omponentURL. N ame, omponentURL. S pec. P ort) } } output = output [ : len ( output ) - 1 ] log . Describef ( " \n " , output ) } if len ( cfd . Status . LinkedServices ) > 0 { var output string for _ , linkedService := range cfd . Status . LinkedServices { if linkedService . SecretName == " " { output += fmt . Sprintf ( " n" , inkedService. S erviceName) continue } secrets , err := client . GetKubeClient ( ) . GetSecret ( linkedService . SecretName , cfd . GetNamespace ( ) ) if err != nil { return err } if len ( secrets . Data ) > 0 { var secretOutput string for i := range secrets . Data { if linkedService . MountVolume { secretOutput += fmt . Sprintf ( " n" , ilepath. J oin( l inkedService. M ountPath, ) ) } else { secretOutput += fmt . Sprintf ( " n" , ) } } if len ( secretOutput ) > 0 { secretOutput = secretOutput [ : len ( secretOutput ) - 1 ] if linkedService . MountVolume { output += fmt . Sprintf ( " n  n% n" , inkedService. S erviceName, ecretOutput) } else { output += fmt . Sprintf ( " n  n% n" , inkedService. S erviceName, ecretOutput) } } } else { output += fmt . Sprintf ( " n" , inkedService. S ecretName) } } if len ( output ) > 0 { output = output [ : len ( output ) - 1 ] log . Describef ( " \n " , output ) } } return nil }
Print prints the complete information of component onto stdout (Note: long term this function should not need to access any parameters, but just print the information in struct)
Print prints the complete information of component onto stdout ( Note : long term this function should not need to access any parameters but just print the information in struct )
// TODO: remove the need to client here print should just deal with printing // Source // Env // Retrieve all the environment variables // Cut off the last newline and output // Storage // Gather the output // Cut off the last newline and output // URL // if the component is not pushed // Cut off the last newline and output // Linked services // Gather the output // Let's also get the secrets / environment variables that are being passed in.. (if there are any) // Iterate through the secrets to throw in a string // Cut off the last newline // Cut off the last newline and output