Skip to content

Commit

Permalink
Merge pull request #23 from acelaya-forks/feature/geolite-plocy-updates
Browse files Browse the repository at this point in the history
Feature/geolite plocy updates
  • Loading branch information
acelaya authored Jan 27, 2020
2 parents c1b0664 + 31288a6 commit ccb26bc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## 1.3.1 - 2020-01-27

#### Added

* *Nothing*

#### Changed

* *Nothing*

#### Deprecated

* *Nothing*

#### Removed

* *Nothing*

#### Fixed

* [#17](https://github.com/shlinkio/shlink-ip-geolocation/issues/17) Allowed the library to receive the geolite license key via config.


## 1.3.0 - 2020-01-03

#### Added
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function downloadFreshCopy(?callable $handleProgress = null): void;
* `databaseFileExists`: Just tells if the database file exists already (either in an outdated or up to date form).
* `downloadFreshCopy`: Forces a new copy of the GeoLite2 database to be downloaded from MaxMind repos. It allows to optionally handle the progress of the download.

## GeoLite2 config

To get both the resolver and the database updater to work, this configuration has to be defined:

```php
Expand All @@ -73,16 +75,21 @@ declare(strict_types=1);
return [

'geolite2' => [
// Mandatory options
'db_location' => __DIR__ . '/../../data/GeoLite2-City.mmdb',
'temp_dir' => sys_get_temp_dir(),
// 'download_from' => 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz',

// Optional options
'license_key' => 'kjhk45hkj34fdwe5',
'download_from' => 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={license_key}&suffix=tar.gz',
],

];
```

* `db_location`: It's the config option used to tell where in the local filesystem the database file is located (or should be located once the `DbUpdater` downloads it).
* `db_location`: Tells where in the local filesystem the database file is located (or should be located once the `DbUpdater` downloads it).
* `temp_dir`: A temporary location where new versions of the database are located while downloading. Once a download succeeds, the new DB will be moved to the location defined in previous config option.
* `download_from`: The repository from which new GeoLite2 db files are downloaded. This option has a default value which is usually ok, but just in case you need to change it for some reason, you can do it here.
* `license_key`: The GeoLite license key used to download the database. It has a default value, but it is recommended to [generate your own](https://support.maxmind.com/account-faq/account-related/how-do-i-generate-a-license-key/).
* `download_from`: The repository from which new GeoLite2 db files are downloaded. This option has a default value which is usually ok. It can contain a `{license_key}` placeholder which will be replaced with the value provided in previous config option, but it can also be a hardcoded URL which will make the license key option to be ignored.

> This project includes GeoLite2 data created by MaxMind, available from [https://www.maxmind.com](https://www.maxmind.com)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"phpstan/phpstan": "^0.12.3",
"phpunit/phpunit": "^8.3",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.1.0"
"shlinkio/php-coding-standard": "~2.1.0",
"symfony/var-dumper": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 12 additions & 2 deletions src/GeoLite2/GeoLite2Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

use Laminas\Stdlib\AbstractOptions;

use function str_replace;

class GeoLite2Options extends AbstractOptions
{
private string $dbLocation = '';
private string $tempDir = '';
private string $downloadFrom = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz';
private string $licenseKey = 'G4Lm0C60yJsnkdPi';
private string $downloadFrom = 'https://download.maxmind.com/app/geoip_download'
. '?edition_id=GeoLite2-City&license_key={license_key}&suffix=tar.gz';

public function getDbLocation(): string
{
Expand All @@ -36,12 +40,18 @@ protected function setTempDir(string $tempDir): self

public function getDownloadFrom(): string
{
return $this->downloadFrom;
return str_replace('{license_key}', $this->licenseKey, $this->downloadFrom);
}

protected function setDownloadFrom(string $downloadFrom): self
{
$this->downloadFrom = $downloadFrom;
return $this;
}

protected function setLicenseKey(string $licenseKey): self
{
$this->licenseKey = $licenseKey;
return $this;
}
}

0 comments on commit ccb26bc

Please sign in to comment.