Skip to content

Commit

Permalink
🚸 Unify license plan output. Print linked project. (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid committed Apr 30, 2024
1 parent c172f84 commit 97f5f0c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
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

0 comments on commit 97f5f0c

Please sign in to comment.