diff --git a/platform/run.go b/platform/run.go index 1a5d6832..d5c63fe2 100644 --- a/platform/run.go +++ b/platform/run.go @@ -33,7 +33,8 @@ func RunAnalysis(options *QodanaOptions) (int, error) { ErrorMessage(err.Error()) return 1, err } - checkLinterLicense(options, linterInfo) + checkLinterLicense(options) + printLinterLicense(options, linterInfo) printQodanaLogo(options, linterInfo) defineResultAndCacheDir(options) @@ -134,23 +135,25 @@ func ensureWorkingDirsCreated(options *QodanaOptions, mountInfo *MountInfo) erro return nil } -func checkLinterLicense(options *QodanaOptions, linterInfo *LinterInfo) { - var err error +func checkLinterLicense(options *QodanaOptions) { + options.LicensePlan = cloud.CommunityLicensePlan cloud.SetupLicenseToken(options.LoadToken(false, false, true)) if cloud.Token.Token != "" { licenseData := cloud.GetCloudApiEndpoints().GetLicenseData(cloud.Token.Token) + ValidateTokenPrintProject(cloud.Token.Token) options.LicensePlan = licenseData.LicensePlan - SuccessMessage("Qodana license plan: %s", options.LicensePlan) options.ProjectIdHash = licenseData.ProjectIdHash - } else { - if !linterInfo.IsEap { - log.Fatalf("Failed to get license plan: %e", err) - } - SuccessMessage("Qodana license plan: EAP license.") - options.LicensePlan = cloud.CommunityLicensePlan } } +func printLinterLicense(options *QodanaOptions, linterInfo *LinterInfo) { + licenseString := options.LicensePlan + if cloud.Token.Token == "" && linterInfo.IsEap { + licenseString = "EAP license" + } + SuccessMessage("Qodana license plan: %s", licenseString) +} + func getLinterDescriptors(options *QodanaOptions) (*ThirdPartyOptions, *MountInfo, *LinterInfo, error) { linterOptions := options.GetLinterSpecificOptions() if linterOptions == nil { diff --git a/platform/token.go b/platform/token.go index 67fd223b..02ea5986 100644 --- a/platform/token.go +++ b/platform/token.go @@ -108,20 +108,23 @@ func (o *QodanaOptions) getTokenFromUserInput(requiresToken bool) string { func (o *QodanaOptions) ValidateToken(refresh bool) string { token := o.LoadToken(refresh, true, true) if token != "" { - client := cloud.GetCloudApiEndpoints().NewCloudApiClient(token) - if projectName, err := client.RequestProjectName(); err != nil { - if token != "" { - ErrorMessage(cloud.InvalidTokenMessage) - os.Exit(1) - } - } else { - SuccessMessage("Linked %s project: %s", cloud.GetCloudRootEndpoint().Host, projectName) - o.Setenv(QodanaToken, token) - } + ValidateTokenPrintProject(token) + o.Setenv(QodanaToken, token) } return token } +// ValidateTokenPrintProject validates given token by requesting linked project name. +func ValidateTokenPrintProject(token string) { + client := cloud.GetCloudApiEndpoints().NewCloudApiClient(token) + if projectName, err := client.RequestProjectName(); err != nil { + ErrorMessage(cloud.InvalidTokenMessage) + os.Exit(1) + } else { + SuccessMessage("Linked %s project: %s", cloud.GetCloudRootEndpoint().Host, projectName) + } +} + // saveCloudToken saves token to the system keyring func saveCloudToken(id string, token string) error { err := keyring.Set(defaultService, id, token)