in cmd/get_logs.go [107:164]
func (glc *getLogsCmd) validateArgs() (err error) {
if glc.locale, err = i18n.LoadTranslations(); err != nil {
return errors.Wrap(err, "loading translation files")
}
glc.location = helpers.NormalizeAzureRegion(glc.location)
if glc.location == "" {
return errors.New("--location must be specified")
}
if glc.sshHostURI == "" {
return errors.New("--ssh-host must be specified")
}
if glc.apiModelPath == "" {
return errors.New("--api-model must be specified")
} else if _, err := os.Stat(glc.apiModelPath); os.IsNotExist(err) {
return errors.Errorf("specified --api-model does not exist (%s)", glc.apiModelPath)
}
if glc.linuxSSHPrivateKeyPath == "" {
return errors.New("--linux-ssh-private-key must be specified")
} else if _, err := os.Stat(glc.linuxSSHPrivateKeyPath); os.IsNotExist(err) {
return errors.Errorf("specified --linux-ssh-private-key does not exist (%s)", glc.linuxSSHPrivateKeyPath)
}
if glc.linuxScriptPath != "" {
if _, err := os.Stat(glc.linuxScriptPath); os.IsNotExist(err) {
return errors.Errorf("specified --linux-script does not exist (%s)", glc.linuxScriptPath)
}
}
if glc.windowsScriptPath != "" {
if _, err := os.Stat(glc.windowsScriptPath); os.IsNotExist(err) {
return errors.Errorf("specified --windows-script does not exist (%s)", glc.windowsScriptPath)
}
}
if glc.outputDirectory == "" {
glc.outputDirectory = path.Join(filepath.Dir(glc.apiModelPath), "_logs")
if err := os.MkdirAll(glc.outputDirectory, 0755); err != nil {
return errors.Errorf("error creating output directory (%s)", glc.outputDirectory)
}
}
if glc.uploadSASURL != "" {
exp, err := regexp.Compile(`^/\w+`)
if err != nil {
return err
}
sasURL, err := url.ParseRequestURI(glc.uploadSASURL)
if err != nil {
return errors.Errorf("error parsing upload SAS URL")
}
if !exp.MatchString(sasURL.Path) {
return errors.New("invalid upload SAS URL format, expected 'https://{blob-service-uri}/{container-name}?{sas-token}'")
}
}
if glc.nodeNames != nil && len(glc.nodeNames) == 0 {
return errors.New("--vm-names cannot be empty")
}
if glc.nodeNames != nil && glc.controlPlaneOnly {
return errors.New("--control-plane-only and --vm-names are mutually exclusive")
}
return nil
}