mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 12:07:51 +02:00
Add script to convert datastore-indexes.xml to index.yaml
The gcloud datastore cleanup-indexes command takes its input in index.yaml form instead of datastore-indexes.yaml form. This simple translation script allows us to generate one from the other. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=169260811
This commit is contained in:
parent
f34d4b6bbb
commit
0994ce76c7
5 changed files with 301 additions and 0 deletions
20
python/google/registry/scripts/BUILD
Normal file
20
python/google/registry/scripts/BUILD
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package(default_visibility = ["//java/google/registry:registry_project"])
|
||||||
|
|
||||||
|
licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
|
py_binary(
|
||||||
|
name = "xml_to_index_yaml_translator",
|
||||||
|
srcs = ["xml_to_index_yaml_translator.py"],
|
||||||
|
deps = ["//python:python_directory_import"],
|
||||||
|
)
|
||||||
|
|
||||||
|
py_test(
|
||||||
|
name = "xml_to_index_yaml_translator_test",
|
||||||
|
size = "small",
|
||||||
|
srcs = ["xml_to_index_yaml_translator_test.py"],
|
||||||
|
data = [
|
||||||
|
"testdata/datastore-indexes.xml",
|
||||||
|
"testdata/index.yaml",
|
||||||
|
],
|
||||||
|
deps = [":xml_to_index_yaml_translator"],
|
||||||
|
)
|
86
python/google/registry/scripts/testdata/datastore-indexes.xml
vendored
Normal file
86
python/google/registry/scripts/testdata/datastore-indexes.xml
vendored
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<datastore-indexes autoGenerate="false">
|
||||||
|
<!-- For finding contact resources by registrar. -->
|
||||||
|
<datastore-index kind="ContactResource" ancestor="false" source="manual">
|
||||||
|
<property name="currentSponsorClientId" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For finding domain resources by registrar. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="^i" direction="asc"/>
|
||||||
|
<property name="currentSponsorClientId" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For finding domain resources by TLD. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="^i" direction="asc"/>
|
||||||
|
<property name="tld" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For finding domain resources by registrar. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="currentSponsorClientId" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For finding host resources by registrar. -->
|
||||||
|
<datastore-index kind="HostResource" ancestor="false" source="manual">
|
||||||
|
<property name="currentSponsorClientId" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For finding account balance of registrar and viewing billing history. -->
|
||||||
|
<datastore-index kind="RegistrarBillingEntry" ancestor="true" source="manual">
|
||||||
|
<property name="currency" direction="asc"/>
|
||||||
|
<property name="created" direction="desc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For determining the active domains linked to a given contact. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="allContacts.contact" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For determining the active domains linked to a given host. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="nsHosts" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For RDAP searches by linked nameserver. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="^i" direction="asc"/>
|
||||||
|
<property name="nsHosts" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For WHOIS IP address lookup -->
|
||||||
|
<datastore-index kind="HostResource" ancestor="false" source="manual">
|
||||||
|
<property name="inetAddresses" direction="asc"/>
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For Poll -->
|
||||||
|
<datastore-index kind="PollMessage" ancestor="false" source="manual">
|
||||||
|
<property name="clientId" direction="asc"/>
|
||||||
|
<property name="eventTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<datastore-index kind="PollMessage" ancestor="true" source="manual">
|
||||||
|
<property name="clientId" direction="asc"/>
|
||||||
|
<property name="eventTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For the history viewer. -->
|
||||||
|
<datastore-index kind="HistoryEntry" ancestor="true" source="manual">
|
||||||
|
<property name="modificationTime" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<!-- For RDAP. -->
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="^i" direction="asc"/>
|
||||||
|
<property name="fullyQualifiedDomainName" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<datastore-index kind="DomainBase" ancestor="false" source="manual">
|
||||||
|
<property name="^i" direction="asc"/>
|
||||||
|
<property name="tld" direction="asc"/>
|
||||||
|
<property name="fullyQualifiedDomainName" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<datastore-index kind="HostResource" ancestor="false" source="manual">
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
<property name="fullyQualifiedHostName" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
<datastore-index kind="ContactResource" ancestor="false" source="manual">
|
||||||
|
<property name="deletionTime" direction="asc"/>
|
||||||
|
<property name="searchName" direction="asc"/>
|
||||||
|
</datastore-index>
|
||||||
|
</datastore-indexes>
|
93
python/google/registry/scripts/testdata/index.yaml
vendored
Normal file
93
python/google/registry/scripts/testdata/index.yaml
vendored
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
indexes:
|
||||||
|
|
||||||
|
- kind: ContactResource
|
||||||
|
properties:
|
||||||
|
- name: currentSponsorClientId
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: ^i
|
||||||
|
- name: currentSponsorClientId
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: ^i
|
||||||
|
- name: tld
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: currentSponsorClientId
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: HostResource
|
||||||
|
properties:
|
||||||
|
- name: currentSponsorClientId
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: RegistrarBillingEntry
|
||||||
|
ancestor: yes
|
||||||
|
properties:
|
||||||
|
- name: currency
|
||||||
|
- name: created
|
||||||
|
direction: desc
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: allContacts.contact
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: nsHosts
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: ^i
|
||||||
|
- name: nsHosts
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: HostResource
|
||||||
|
properties:
|
||||||
|
- name: inetAddresses
|
||||||
|
- name: deletionTime
|
||||||
|
|
||||||
|
- kind: PollMessage
|
||||||
|
properties:
|
||||||
|
- name: clientId
|
||||||
|
- name: eventTime
|
||||||
|
|
||||||
|
- kind: PollMessage
|
||||||
|
ancestor: yes
|
||||||
|
properties:
|
||||||
|
- name: clientId
|
||||||
|
- name: eventTime
|
||||||
|
|
||||||
|
- kind: HistoryEntry
|
||||||
|
ancestor: yes
|
||||||
|
properties:
|
||||||
|
- name: modificationTime
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: ^i
|
||||||
|
- name: fullyQualifiedDomainName
|
||||||
|
|
||||||
|
- kind: DomainBase
|
||||||
|
properties:
|
||||||
|
- name: ^i
|
||||||
|
- name: tld
|
||||||
|
- name: fullyQualifiedDomainName
|
||||||
|
|
||||||
|
- kind: HostResource
|
||||||
|
properties:
|
||||||
|
- name: deletionTime
|
||||||
|
- name: fullyQualifiedHostName
|
||||||
|
|
||||||
|
- kind: ContactResource
|
||||||
|
properties:
|
||||||
|
- name: deletionTime
|
||||||
|
- name: searchName
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""Convert App Engine Java datastore-indexes.xml file to index.yaml format.
|
||||||
|
|
||||||
|
Pass the name of a datastore-indexes.xml file. The output will be dumped to
|
||||||
|
stdout.
|
||||||
|
|
||||||
|
The resulting file can be used to call the gcloud cleanup-indexes command,
|
||||||
|
which interactively removes indexes which are defined on an App Engine
|
||||||
|
project but not present in the file. The syntax for that command is:
|
||||||
|
|
||||||
|
gcloud datastore cleanup-indexes {index.yaml file} --project={project-id}
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
if len(argv) < 2:
|
||||||
|
print 'Usage: command {datastore-indexes.xml file}'
|
||||||
|
return 1
|
||||||
|
|
||||||
|
root = ElementTree.parse(argv[1]).getroot()
|
||||||
|
print 'indexes:'
|
||||||
|
for index in root:
|
||||||
|
print ''
|
||||||
|
print '- kind: %s' % index.attrib['kind']
|
||||||
|
if index.attrib['ancestor'] != 'false':
|
||||||
|
print ' ancestor: %s' % ('yes' if (index.attrib['ancestor'] == 'true')
|
||||||
|
else 'no')
|
||||||
|
print ' properties:'
|
||||||
|
for index_property in index:
|
||||||
|
print ' - name: %s' % index_property.attrib['name']
|
||||||
|
if index_property.attrib['direction'] != 'asc':
|
||||||
|
print ' direction: %s' % index_property.attrib['direction']
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
|
@ -0,0 +1,51 @@
|
||||||
|
# Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""Tests for xml_to_index_yaml_translator.py."""
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
import StringIO
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from google.registry.scripts import xml_to_index_yaml_translator
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def _RedirectStdout():
|
||||||
|
orig_stdout = sys.stdout
|
||||||
|
sio = StringIO.StringIO()
|
||||||
|
sys.stdout = sio
|
||||||
|
try:
|
||||||
|
yield sio
|
||||||
|
finally:
|
||||||
|
sys.stdout = orig_stdout
|
||||||
|
|
||||||
|
|
||||||
|
class XmlToIndexYamlTranslatorTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def testSuccess(self):
|
||||||
|
with _RedirectStdout() as sio:
|
||||||
|
xml_to_index_yaml_translator.main(['test',
|
||||||
|
'python/'
|
||||||
|
'google/registry/scripts/testdata/'
|
||||||
|
'datastore-indexes.xml'])
|
||||||
|
actual = sio.getvalue()
|
||||||
|
expectedfile = open('python/google/registry/'
|
||||||
|
'scripts/testdata/index.yaml')
|
||||||
|
expected = expectedfile.read()
|
||||||
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Add table
Reference in a new issue