func SetupLicenseAndProjectHash()

in internal/core/startup/license.go [31:99]


func SetupLicenseAndProjectHash(prod product.Product, endpoints *cloud.QdApiEndpoints, token string) {
	var licenseData cloud.LicenseData
	if token != "" {
		licenseData = endpoints.GetLicenseData(token)
		if licenseData.ProjectIdHash != "" {
			err := os.Setenv(qdenv.QodanaProjectIdHash, licenseData.ProjectIdHash)
			if err != nil {
				log.Fatal(err)
			}
		}
		if licenseData.OrganisationIdHash != "" {
			err := os.Setenv(qdenv.QodanaOrganisationIdHash, licenseData.OrganisationIdHash)
			if err != nil {
				log.Fatal(err)
			}
		}
	}
	_, exists := os.LookupEnv(qdenv.QodanaLicense)
	if exists {
		return
	}

	// community versions works without any license and can't check any license
	if !prod.Analyzer.GetLinter().IsPaid {
		return
	}

	// eap version works with eap's license dependent on build date
	if prod.IsEap {
		if token == "" {
			fmt.Printf(cloud.EapWarnTokenMessage, endpoints.RootEndpoint.Url)
			fmt.Println()
			fmt.Println()
		}
		return
	}

	// usual builds should have token and LicenseData for execution
	if token == "" {
		log.Fatalf(cloud.EmptyTokenMessage, endpoints.RootEndpoint.Url)
	}

	licenseDataResponse, err := endpoints.RequestLicenseData(token)
	if errors.Is(err, cloud.ErrTokenDeclined) {
		log.Fatalf("License request: %v\n%s", err, cloud.DeclinedTokenErrorMessage)
	}
	if err != nil {
		errMessage := fmt.Sprintf(cloud.GeneralLicenseErrorMessage, endpoints.RootEndpoint.Url)
		log.Fatalf("License request: %v\n%s", err, errMessage)
	}
	licenseData = cloud.DeserializeLicenseData(licenseDataResponse)
	if strings.ToLower(licenseData.LicensePlan) == "community" {
		log.Fatalf(
			"Your Qodana Cloud organization has Community license that doesn’t support \"%s\" linter, "+
				"please try one of the community linters instead: %s or obtain Ultimate "+
				"or Ultimate Plus license. Read more about licenses and plans at "+
				"https://www.jetbrains.com/help/qodana/pricing.html#pricing-linters-licenses.",
			prod.GetProductNameFromCode(),
			allCommunityNames(),
		)
	}
	if licenseData.LicenseKey == "" {
		log.Fatalf("License key should not be empty\n")
	}
	err = os.Setenv(qdenv.QodanaLicense, licenseData.LicenseKey)
	if err != nil {
		log.Fatal(err)
	}
}