Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Unify license plan output. Print linked project. #345

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions platform/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 13 additions & 10 deletions platform/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading