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

Provide console command for adding a marketplace license key (#18070) #18071

Merged

Conversation

ziegenberg
Copy link
Contributor

Description:

Adds a new console command marketplace:add-license-key which adds a marketplace license key (Fixes #18070)

This is the first draft. It does not implement any checks like it's done in the Marketplace API:

public function saveLicenseKey($licenseKey)
{
Piwik::checkUserHasSuperUserAccess();
$licenseKey = trim($licenseKey);
// we are currently using the Marketplace service directly to 1) change LicenseKey and 2) not use any cache
$this->marketplaceService->authenticate($licenseKey);
try {
$consumer = $this->marketplaceService->fetch('consumer/validate', array());
} catch (Api\Service\Exception $e) {
if ($e->getCode() === Api\Service\Exception::HTTP_ERROR) {
throw $e;
}
$consumer = array();
}
if (empty($consumer['isValid'])) {
throw new Exception(Piwik::translate('Marketplace_ExceptionLinceseKeyIsNotValid'));
}
$this->setLicenseKey($licenseKey);
return true;
}

I'd need some pointers for further implementing this, if checking the license key this is deemed necessary.

Review

@ziegenberg
Copy link
Contributor Author

The failing checks do not seem to be related to my change.

@github-actions
Copy link
Contributor

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Oct 13, 2021
@tsteur
Copy link
Member

tsteur commented Oct 13, 2021

@ziegenberg I see this PR is in draft. Not sure if that was you? Is that ready for a review?

@ziegenberg
Copy link
Contributor Author

Hi @tsteur,

I left this in the draft state because it is most certainly not ready yet and I wanted to discuss my implementation before going to review. I suspect that I have misinterpreted the workflow here...

@tsteur
Copy link
Member

tsteur commented Oct 13, 2021

@ziegenberg this looked all good to me. I would maybe just rename the command to be set license key instead of add license key.

@ziegenberg
Copy link
Contributor Author

So you don't want to add any checks for validity while setting the license key?

@ziegenberg ziegenberg force-pushed the 18070_marketplace-add-license-key branch 2 times, most recently from 849d26b to 00c849a Compare October 13, 2021 19:04
@ziegenberg
Copy link
Contributor Author

I quickly made the suggested changes and rebased onto current 4.x-dev

@ziegenberg ziegenberg marked this pull request as ready for review October 13, 2021 19:05
@tsteur
Copy link
Member

tsteur commented Oct 13, 2021

@ziegenberg it depends what you are using the command for and how quick things need to go as the validation will take a bit of time. We have an API that you can use like \Piwik\Plugins\Marketplace\Api::getInstance()->saveLicenseKey($licenseKey) and then it will validate the license key and also invalidate caches.

This API won't "remove/unset" the license key though. If an empty license key is provided, then you would need to call the API method deleteLicenseKey().

Overall this would be better indeed 👍

@ziegenberg ziegenberg force-pushed the 18070_marketplace-add-license-key branch from 00c849a to 1110c07 Compare October 13, 2021 19:30
* adds a new console command marketplace:set-license-key which sets a marketplace license key

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
@ziegenberg ziegenberg force-pushed the 18070_marketplace-add-license-key branch from 1110c07 to 1af77be Compare October 13, 2021 19:31
@ziegenberg
Copy link
Contributor Author

@tsteur I added the checks using the API. Does this look good to you?

@tsteur
Copy link
Member

tsteur commented Oct 13, 2021

Nice, that looks good and works nicely 👍 Thanks for that.

@tsteur tsteur merged commit 99cf099 into matomo-org:4.x-dev Oct 13, 2021
@justinvelluppillai justinvelluppillai changed the title provide console command for adding a marketplace license key (#18070) Provide console command for adding a marketplace license key (#18070) Nov 29, 2021
@ziegenberg ziegenberg deleted the 18070_marketplace-add-license-key branch May 12, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale The label used by the Close Stale Issues action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New console command "marketplace:add-license-key" which adds a marketplace license key
2 participants