Skip to content

Commit

Permalink
Add check for auth details
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitbohra committed Jun 17, 2020
1 parent 8a7b2c5 commit 396260f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Above package details hold important info to connect and download zip from produ
- `version` used to get the zip, check account for version number
- `type` use wordpress-plugin or wordpress-theme,

- `url` product website url
- `url` product website url (include https)
- `edd_installer` enable package via edd powered store
- `item_name` name of product, can be found under account info
- `license` name of env variable to get the license key *(do not add your actual key here)*
Expand Down Expand Up @@ -83,7 +83,7 @@ Create the `auth.json` and Add the store access credentials. Find more about htt
``` json
{
"http-basic": {
"productwebsite.com": {
"www.productwebsite.com": {
"username": "your-username",
"password": "your-password"
},
Expand All @@ -93,9 +93,9 @@ Create the `auth.json` and Add the store access credentials. Find more about htt

**Important**

- `productwebsite.com` product website domain name
- `www.productwebsite.com` product website host name
- `username` login username for product website
- `username` login password for product website
- `password` login password for product website

**Note**

Expand All @@ -109,11 +109,11 @@ Install the plugin
composer require namespace/edd-product-name
```

**Troubleshooting**
## Troubleshooting

```
[Composer\Downloader\TransportException]
Your configuration does not allow connections to http://edd-store.com See https://getcomposer.org/doc/06-config.md#sec
Your configuration does not allow connections to http://www.productwebsite.com See https://getcomposer.org/doc/06-config.md#sec
ure-http for details.
```
you will get above error if edd store deliver file over `http` instead of `https`. To fix this config composer to allow non secure url by setting `secure-http` to false. Find more about secure-http in the [composer documentation](https://getcomposer.org/doc/06-config.md#secure-http)
Expand Down
14 changes: 14 additions & 0 deletions src/Exception/MissingAuthException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LubusIN\ComposerEddPlugin\Exception;

class MissingAuthException extends \Exception
{
public function __construct($key)
{
parent::__construct(sprintf(
'\'%1$s\' see https://github.com/lubusIN/composer-edd-plugin#step-3 for details.',
$key
));
}
}
17 changes: 16 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Composer\Plugin\PreFileDownloadEvent;
use Dotenv\Dotenv;
use Exception;
use LubusIN\ComposerEddPlugin\Exception\MissingAuthException;
use LubusIN\ComposerEddPlugin\Exception\MissingExtraException;
use LubusIN\ComposerEddPlugin\Exception\MissingEnvException;

Expand Down Expand Up @@ -100,6 +101,20 @@ public function getDownloadUrl( PackageEvent $event ) {
}
}

if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . 'auth.json' ) ) {
$auth_file = getcwd() . DIRECTORY_SEPARATOR . 'auth.json';
$auth_data = json_decode(file_get_contents($auth_file), true);
$package = parse_url($package_dist_url);

print $package['host'];

if (!array_key_exists($package['host'], $auth_data['http-basic'])) {
throw new MissingAuthException('Auth credentials missing for ' . $package['host']);
}
} else {
throw new MissingAuthException('Auth file auth.json missing');
}

$package_details = [
'edd_action' => 'get_version',
'license' => getenv( $package_extra['license'] ),
Expand All @@ -112,7 +127,7 @@ public function getDownloadUrl( PackageEvent $event ) {
"http" => [
"method" => "POST",
'header' =>"Content-Type: application/json; charset=utf-8",
"timeout" => 30
"timeout" => 30,
],
]);

Expand Down
2 changes: 0 additions & 2 deletions src/RemoteFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public function copy(
$progress = true,
$options = []
) {
print $originUrl;
print $this->fileUrl;
return parent::copy(
$originUrl,
$this->fileUrl,
Expand Down

0 comments on commit 396260f

Please sign in to comment.