From 66838cf9b6f87be014379ca59c9bb4c2f411c7b18875e983b85550e67857a752 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Fri, 16 Nov 2018 18:18:43 +0000 Subject: [PATCH] Accepting request 649653 from home:glaubitz:branches:devel:languages:python - Submit new pytest component transitively required for python-dns-lexicon OBS-URL: https://build.opensuse.org/request/show/649653 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-PyNamecheap?expand=0&rev=1 --- .gitattributes | 23 ++ .gitignore | 1 + LICENSE.txt | 818 +++++++++++++++++++++++++++++++++++++ PyNamecheap-0.0.3.tar.gz | 3 + README.md | 798 ++++++++++++++++++++++++++++++++++++ python-PyNamecheap.changes | 5 + python-PyNamecheap.spec | 59 +++ 7 files changed, 1707 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 PyNamecheap-0.0.3.tar.gz create mode 100644 README.md create mode 100644 python-PyNamecheap.changes create mode 100644 python-PyNamecheap.spec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ba0c73a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,818 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PyNamecheap/LICENSE.txt at master · Bemmu/PyNamecheap · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content +
+ + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+
+ + + + + + + + + + +
+
+ + + + + Permalink + + + + + + +
+ +
+ + +
+ +
+
+ + Switch branches/tags +
+ +
+
+ +
+
+ +
+
+ + + +
+ + +
Nothing to show
+
+ +
+
+
+ +
+ + Find file + + + Copy path + +
+ +
+ +
+
+ +

+ Bemmu/PyNamecheap is licensed under the +

+

MIT License

+

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

+
+ +
+ + + +
+ +

+ This is not legal advice. + Learn more about repository licenses. +

+
+ + + +
+ Fetching contributors… +
+ +
+ + Cannot retrieve contributors at this time +
+
+ + +
+
+
+ + +
+ Raw + Blame + History +
+ + + + +
+ +
+ 9 lines (5 sloc) + + 1.05 KB +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
The MIT License (MIT)
Copyright (c) 2016 Bemmu Sepponen
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ + + +
+ +
+ + + +
+ + +
+ + +
+
+ + +
+ +
+ +
+
+ +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + +
+ + You signed in with another tab or window. Reload to refresh your session. + You signed out in another tab or window. Reload to refresh your session. +
+ + + + + + +
+ Press h to open a hovercard with more details. +
+ + + + + diff --git a/PyNamecheap-0.0.3.tar.gz b/PyNamecheap-0.0.3.tar.gz new file mode 100644 index 0000000..105817b --- /dev/null +++ b/PyNamecheap-0.0.3.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d428f9455f6226f5dbe2e67c5a81b5b37a215edf94d55f7576164904c4e76b72 +size 5748 diff --git a/README.md b/README.md new file mode 100644 index 0000000..67fff8d --- /dev/null +++ b/README.md @@ -0,0 +1,798 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PyNamecheap/README.md at master · Bemmu/PyNamecheap · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content +
+ + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+
+ + + + + + + + + + +
+
+ + + + + Permalink + + + + + + +
+ +
+ + +
+ +
+
+ + Switch branches/tags +
+ +
+
+ +
+
+ +
+
+ + + +
+ + +
Nothing to show
+
+ +
+
+
+ +
+ + Find file + + + Copy path + +
+ +
+ + + +
+ Fetching contributors… +
+ +
+ + Cannot retrieve contributors at this time +
+
+ + +
+
+
+ + +
+ Raw + Blame + History +
+ + + + +
+ +
+ 151 lines (99 sloc) + + 5.31 KB +
+
+ + +
+

Namecheap API for Python

+

PyNamecheap is a Namecheap API client in Python. +API itself is documented at http://developer.namecheap.com/docs/

+

This client supports:

+
    +
  • Registering a domain
  • +
  • Checking domain name availability
  • +
  • Listing domains you have registered
  • +
  • Getting contact information for a domain
  • +
  • Setting DNS info to default values
  • +
  • Set DNS host records
  • +
+

Installation

+

Thanks to @inomoz, as simple as:

+
pip install PyNamecheap
+
+

How to sign up to start using the API

+

The API has two environments, production and sandbox. Since this API will spend real money when registering domains, start with the sandbox by going to http://www.sandbox.namecheap.com/ and creating an account. Accounts between production and sandbox are different, so even if you already have a Namecheap account you will need a new one.

+

After you have an account, go to "Profile".

+

Profile

+

From there, select the "Profile" menu again, then "Tools". Scroll to the bottom of the page to the "Business & Dev Tools" and select "Manage" on the "Namecheap API Access" section.

+

API menu

+

You'll get to your credentials page. From here you need to take note of your api key, username and add your IP to the whitelist of IP addresses that are allowed to access the account. You can check your public IP by searching "what is my ip" on Google and add it here. It might take some time before it actually starts working, so don't panic if API access doesn't work at first.

+

Credentials

+

How to access the API from Python

+

Copy namecheap.py to your project. In Python you can access the API as follows:

+
from namecheap import Api
+api = Api(username, api_key, username, ip_address, sandbox = True)
+
+

The fields are the ones which appear in the credentials screen above. The username appears twice, because you might be acting on behalf of someone else.

+

Registering a domain name using the API

+

Unfortunately you need a bunch of contact details to register a domain, so it is not as easy as just providing the domain name. In the sandbox, the following contact details are acceptable. Trickiest field is the phone number, which has to be formatted as shown.

+
api.domains_create(
+    DomainName = 'registeringadomainthroughtheapiwow.com',
+    FirstName = 'Jack',
+    LastName = 'Trotter',
+    Address1 = 'Ridiculously Big Mansion, Yellow Brick Road',
+    City = 'Tokushima',
+    StateProvince = 'Tokushima',
+    PostalCode = '771-0144',
+    Country = 'Japan',
+    Phone = '+81.123123123',
+    EmailAddress = 'jack.trotter@example.com'
+)
+
+

This call should succeed in the sandbox, but if you use the API to check whether this domain is available after registering it, the availability will not change. This is normal.

+

How to check if a domain name is available

+

The domains_check method returns True if the domain is available.

+
api.domains_check(domain_name)
+
+

You can also pass a list of domain names, in which case it does a batch check for all and returns a dictionary of the answers. +You should probably not be writing a mass domain checking tool using this, it is intended to be used before registering a domain.

+

CLI tool usage

+

First, you need to edit ./credentials.py file to provide API access for the script. The example is following:

+
#!/usr/bin/env python
+
+api_key = '0123456789abcdef0123456789abcdef'
+username = 'myusername'
+ip_address = '10.0.0.1'
+
+

Then you just call the script with desired arguments:

+
./namecheap-api-cli --domain example.org --list
+
+./namecheap-api-cli --domain example.org --add --type "A" --name "test" --address "127.0.0.1" --ttl 300
+./namecheap-api-cli --domain example.org --add --type "CNAME" --name "alias-of-test" --address "test.example.org." --ttl 1800
+
+./namecheap-api-cli --domain example.org --delete --type "CNAME" --name "alias-of-test" --address "test.example.org."
+./namecheap-api-cli --domain example.org --delete --type "A" --name "test" --address "127.0.0.1"
+
+

Basic host records management code

+

Here's the example of simple DNS records management script:

+
#!/usr/bin/env python
+
+"""
+Define variables regarding to your API account:
+  - api_key
+  - username
+  - ip_address
+"""
+
+api = Api(username, api_key, username, ip_address, sandbox=False)
+
+domain = "example.org"
+
+# list domain records
+api.domains_dns_getHosts(domain)
+
+record = {
+    # required
+    "Type": "A",
+    "Name": "test1",
+    "Address": "127.0.0.1",
+
+    # optional
+    "TTL": "1800",
+    "MXPref": "10"
+}
+
+# add A "test1" record pointing to 127.0.0.1
+api.domains_dns_addHost(domain, record)
+
+# delete record we just created,
+# selecting it by Name, Type and Address values
+api.domains_dns_delHost(domain, record)
+
+

Retry mechanism

+

Sometimes you could face wrong API responses, which are related to server-side errors.

+

Thanks to @gstein, we implemented retry mechanism, one could enable it by adding 2 parameters to Api instance:

+
api = Api(username, api_key, username, ip_address, sandbox=False,
+          attempts_count=3,
+          attempts_delay=0.1)
+
+

Values of 2 or 3 should do the thing.

+

More

+

Look at namecheap_tests.py to see more examples of things you can do.

+
+
+ +
+ + + +
+ + +
+ + +
+
+ + +
+ +
+ +
+
+ +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + +
+ + You signed in with another tab or window. Reload to refresh your session. + You signed out in another tab or window. Reload to refresh your session. +
+ + + + + + +
+ Press h to open a hovercard with more details. +
+ + + + + diff --git a/python-PyNamecheap.changes b/python-PyNamecheap.changes new file mode 100644 index 0000000..6e0da6c --- /dev/null +++ b/python-PyNamecheap.changes @@ -0,0 +1,5 @@ +------------------------------------------------------------------- +Fri Nov 16 12:56:37 UTC 2018 - John Paul Adrian Glaubitz + +- Initial build + + Version 0.0.3 diff --git a/python-PyNamecheap.spec b/python-PyNamecheap.spec new file mode 100644 index 0000000..df47506 --- /dev/null +++ b/python-PyNamecheap.spec @@ -0,0 +1,59 @@ +# +# spec file for package python-PyNamecheap +# +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ + + +%{?!python_module:%define python_module() python-%{**} python3-%{**}} +Name: python-PyNamecheap +Version: 0.0.3 +Release: 0 +License: MIT +Summary: Namecheap API client in Python +Url: https://github.com/Bemmu/PyNamecheap +Group: Development/Languages/Python +Source: https://files.pythonhosted.org/packages/source/P/PyNamecheap/PyNamecheap-%{version}.tar.gz +Source1: LICENSE.txt +Source2: README.md +BuildRequires: python-rpm-macros +BuildRequires: %{python_module devel} +BuildRequires: %{python_module requests} +BuildRequires: %{python_module setuptools} +BuildRequires: fdupes +Requires: python-requests +BuildArch: noarch + +%python_subpackages + +%description +Namecheap API client in Python + +%prep +%setup -q -n PyNamecheap-%{version} +cp %{SOURCE1} LICENSE.txt +cp %{SOURCE2} README.md + +%build +%python_build + +%install +%python_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +%files %{python_files} +%doc README.md +%license LICENSE.txt +%{python_sitelib}/* + +%changelog