1 // Package init provides methods to initiate an odo project. 2 // Most of the methods of the package get a `flags` parameter 3 // representing the flags passed from the user through the command line. 4 // Several backends are available to complete the operations, the backend 5 // being chosen depending on the flags content: 6 // - if no flags are passed, the `interactive` backend will be used 7 // - if some flags are passed, the `flags` backend will be used. 8 package init 9 10 import ( 11 "context" 12 13 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" 14 "github.com/devfile/library/v2/pkg/devfile/parser" 15 16 "github.com/redhat-developer/odo/pkg/api" 17 "github.com/redhat-developer/odo/pkg/testingutil/filesystem" 18 ) 19 20 type Client interface { 21 // GetFlags gets the flag specific to init operation so that it can correctly decide on the backend to be used 22 // It ignores all the flags except the ones specific to init operation, for e.g. verbosity flag 23 GetFlags(flags map[string]string) map[string]string 24 // Validate checks for each backend if flags are valid 25 Validate(flags map[string]string, fs filesystem.Filesystem, dir string) error 26 27 // InitDevfile allows to initialize a Devfile in cases where this operation is needed as a prerequisite, 28 // like if the directory contains no Devfile at all. 29 // `preInitHandlerFunc` allows to perform operations prior to triggering the actual Devfile 30 // initialization and personalization process. 31 // `newDevfileHandlerFunc` is called only when a new Devfile object has been instantiated. 32 // It allows to perform operations right after the Devfile has been initialized and personalized. 33 // It is not called if the context directory already has a Devfile file. 34 InitDevfile(ctx context.Context, flags map[string]string, contextDir string, preInitHandlerFunc func(interactiveMode bool), 35 newDevfileHandlerFunc func(newDevfileObj parser.DevfileObj) error) error 36 37 // SelectDevfile returns information about a devfile selected based on Alizer if the directory content, 38 // or based on the flags if the directory is empty, or 39 // interactively if flags is empty 40 SelectDevfile(ctx context.Context, flags map[string]string, fs filesystem.Filesystem, dir string) (*api.DetectionResult, error) 41 42 // DownloadDevfile downloads a devfile given its location information and a destination directory 43 // and returns the path of the downloaded file 44 DownloadDevfile(ctx context.Context, devfileLocation *api.DetectionResult, destDir string) (string, error) 45 46 // SelectStarterProject selects a starter project from the devfile and returns information about the starter project, 47 // depending on the flags. If not starter project is selected, a nil starter is returned 48 SelectStarterProject(devfile parser.DevfileObj, flags map[string]string, isEmptyDir bool) (*v1alpha2.StarterProject, error) 49 50 // DownloadStarterProject downloads the starter project referenced in devfile and stores it in dest directory 51 // WARNING: This will first remove all the content of dest. 52 DownloadStarterProject(project *v1alpha2.StarterProject, dest string) (bool, error) 53 54 // PersonalizeName returns the customized Devfile Metadata Name. 55 // Depending on the flags, it may return a name set interactively or not. 56 PersonalizeName(devfile parser.DevfileObj, flags map[string]string) (string, error) 57 58 // PersonalizeDevfileConfig updates the env vars, and URL endpoints 59 PersonalizeDevfileConfig(devfileobj parser.DevfileObj, flags map[string]string, fs filesystem.Filesystem, dir string) (parser.DevfileObj, error) 60 61 // SelectAndPersonalizeDevfile selects a devfile, then downloads, parse and personalize it 62 // Returns the devfile object, its path and pointer to *api.devfileLocation 63 SelectAndPersonalizeDevfile(ctx context.Context, flags map[string]string, contextDir string) (parser.DevfileObj, string, *api.DetectionResult, error) 64 65 // HandleApplicationPorts updates the ports in the Devfile accordingly. 66 HandleApplicationPorts(devfileobj parser.DevfileObj, ports []int, flags map[string]string, fs filesystem.Filesystem, dir string) (parser.DevfileObj, error) 67 } 68