From 70736b35114a766aa7b85aad83c1f19600b83a95 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Fri, 20 Oct 2017 07:50:49 -0700 Subject: [PATCH] Repo Migration (#4) * Change to a new linter (ESLint) and code style formatter (prettify). * Update docs to use [JSDoc 3](https://usejsdoc.org/). * Migrate to the `googleapis/nodejs-dns` repository. --- packages/google-cloud-dns/.appveyor.yml | 23 + .../google-cloud-dns/.circleci/config.yml | 215 +++++++ .../google-cloud-dns/.circleci/key.json.enc | Bin 0 -> 2352 bytes .../google-cloud-dns/.cloud-repo-tools.json | 16 + packages/google-cloud-dns/.eslintignore | 3 + packages/google-cloud-dns/.eslintrc.yml | 13 + packages/google-cloud-dns/.gitignore | 10 + packages/google-cloud-dns/.jsdoc.js | 45 ++ packages/google-cloud-dns/.mailmap | 4 + packages/google-cloud-dns/.nycrc | 26 + packages/google-cloud-dns/.prettierignore | 3 + packages/google-cloud-dns/.prettierrc | 8 + packages/google-cloud-dns/CODE_OF_CONDUCT.md | 43 ++ packages/google-cloud-dns/CONTRIBUTORS | 14 + packages/google-cloud-dns/LICENSE | 202 ++++++ packages/google-cloud-dns/README.md | 164 +++-- packages/google-cloud-dns/package.json | 85 +-- .../google-cloud-dns/samples/.eslintrc.yml | 3 + packages/google-cloud-dns/samples/README.md | 44 +- .../google-cloud-dns/samples/package.json | 37 +- .../google-cloud-dns/samples/quickstart.js | 16 +- packages/google-cloud-dns/src/change.js | 90 ++- packages/google-cloud-dns/src/index.js | 262 +++++--- packages/google-cloud-dns/src/record.js | 84 ++- packages/google-cloud-dns/src/zone.js | 605 +++++++++++------- .../system-test/.eslintrc.yml | 6 + packages/google-cloud-dns/system-test/dns.js | 101 ++- packages/google-cloud-dns/test/.eslintrc.yml | 5 + packages/google-cloud-dns/test/change.js | 12 +- packages/google-cloud-dns/test/index.js | 45 +- packages/google-cloud-dns/test/record.js | 44 +- packages/google-cloud-dns/test/zone.js | 152 +++-- 32 files changed, 1692 insertions(+), 688 deletions(-) create mode 100644 packages/google-cloud-dns/.appveyor.yml create mode 100644 packages/google-cloud-dns/.circleci/config.yml create mode 100644 packages/google-cloud-dns/.circleci/key.json.enc create mode 100644 packages/google-cloud-dns/.cloud-repo-tools.json create mode 100644 packages/google-cloud-dns/.eslintignore create mode 100644 packages/google-cloud-dns/.eslintrc.yml create mode 100644 packages/google-cloud-dns/.gitignore create mode 100644 packages/google-cloud-dns/.jsdoc.js create mode 100644 packages/google-cloud-dns/.mailmap create mode 100644 packages/google-cloud-dns/.nycrc create mode 100644 packages/google-cloud-dns/.prettierignore create mode 100644 packages/google-cloud-dns/.prettierrc create mode 100644 packages/google-cloud-dns/CODE_OF_CONDUCT.md create mode 100644 packages/google-cloud-dns/CONTRIBUTORS create mode 100644 packages/google-cloud-dns/LICENSE create mode 100644 packages/google-cloud-dns/samples/.eslintrc.yml create mode 100644 packages/google-cloud-dns/system-test/.eslintrc.yml create mode 100644 packages/google-cloud-dns/test/.eslintrc.yml diff --git a/packages/google-cloud-dns/.appveyor.yml b/packages/google-cloud-dns/.appveyor.yml new file mode 100644 index 00000000000..babe1d587f4 --- /dev/null +++ b/packages/google-cloud-dns/.appveyor.yml @@ -0,0 +1,23 @@ +environment: + matrix: + - nodejs_version: 4 + - nodejs_version: 6 + - nodejs_version: 7 + - nodejs_version: 8 + +install: + - ps: Install-Product node $env:nodejs_version + - npm install -g npm # Force using the latest npm to get dedupe during install + - set PATH=%APPDATA%\npm;%PATH% + - npm install --force --ignore-scripts + +test_script: + - node --version + - npm --version + - npm rebuild + - npm test + +build: off + +matrix: + fast_finish: true diff --git a/packages/google-cloud-dns/.circleci/config.yml b/packages/google-cloud-dns/.circleci/config.yml new file mode 100644 index 00000000000..decbae1f035 --- /dev/null +++ b/packages/google-cloud-dns/.circleci/config.yml @@ -0,0 +1,215 @@ +--- +# "Include" for unit tests definition. +unit_tests: &unit_tests + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Run unit tests. + command: npm test + - run: + name: Submit coverage data to codecov. + command: node_modules/.bin/codecov + when: always + +version: 2.0 +workflows: + version: 2 + tests: + jobs: + - node4: + filters: + tags: + only: /.*/ + - node6: + filters: + tags: + only: /.*/ + - node7: + filters: + tags: + only: /.*/ + - node8: + filters: + tags: + only: /.*/ + - lint: + requires: + - node4 + - node6 + - node7 + - node8 + filters: + tags: + only: /.*/ + - docs: + requires: + - node4 + - node6 + - node7 + - node8 + filters: + tags: + only: /.*/ + - system_tests: + requires: + - lint + - docs + filters: + branches: + only: master + tags: + only: /^v[\d.]+$/ + - sample_tests: + requires: + - lint + - docs + filters: + branches: + only: master + tags: + only: /^v[\d.]+$/ + - publish_npm: + requires: + - system_tests + - sample_tests + filters: + branches: + ignore: /.*/ + tags: + only: /^v[\d.]+$/ + +jobs: + node4: + docker: + - image: node:4 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install --unsafe-perm + - run: + name: Run unit tests. + command: npm test + - run: + name: Submit coverage data to codecov. + command: node_modules/.bin/codecov + when: always + node6: + docker: + - image: node:6 + <<: *unit_tests + node7: + docker: + - image: node:7 + <<: *unit_tests + node8: + docker: + - image: node:8 + <<: *unit_tests + + lint: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: | + npm install + npm link + - run: + name: Link the module being tested to the samples. + command: | + cd samples/ + npm link @google-cloud/dns + npm install + cd .. + - run: + name: Run linting. + command: npm run lint + + docs: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Build documentation. + command: npm run docs + + sample_tests: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: + name: Install and link the module. + command: | + npm install + npm link + - run: + name: Link the module being tested to the samples. + command: | + cd samples/ + npm link @google-cloud/dns + npm install + cd .. + - run: + name: Run sample tests. + command: npm run samples-test + environment: + GCLOUD_PROJECT: long-door-651 + GOOGLE_APPLICATION_CREDENTIALS: /var/dns/.circleci/key.json + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always + working_directory: /var/dns/ + + system_tests: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Run system tests. + command: npm run system-test + environment: + GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always + + publish_npm: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Set NPM authentication. + command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + - run: + name: Publish the module to npm. + command: npm publish diff --git a/packages/google-cloud-dns/.circleci/key.json.enc b/packages/google-cloud-dns/.circleci/key.json.enc new file mode 100644 index 0000000000000000000000000000000000000000..6a12319e04e63e5a9a3d98670128bc1c41b9a5fd GIT binary patch literal 2352 zcmV-03D5RZVQh3|WM5x}oHE^yP{ufpwARq33=Qy(jd#grsDps8fNRO?+x|n7mRlQ7 zh80-tu~j0!FHgs{vkJA;t-7X8dDU;rR9Ug?8?%R@BSBWE9kc1)s~-8WPMLLA){+>a zm$ccLhFIfsWU}ym@S9YUn1RONM&hrN5gCz~k?hxpU5Rx}Hg_Zd0>OF8#uwYM{J~7Z>`gtWaZ%r>HfGlKj%X z^?SUZY=}es>pWtBJgXw_o~G3X0E;u^$%j?S?W= zz{EpCo~L@A=)P?!Qe6}4+Iud;(Lq#GD&s+b*Swub`g}jz2M%)vF84o3OA`B>*u&n! z*6XJFDptQXqdT>GK<-^9|lwgn780lqZ{^j zf{R{Qxp0ADdr`d%%Zli^M$h_T8duI)T{FSMMpSrWwP8)`Qcs7+k*W=~ifM;}0~TDO zJwz%(L_{hCa0R;&2ZF*~lZsF3(0Vn)GoLq-;_^*;@k6QWoeqjR7~Wmg$efyI#6WC^ z2IxNWg1D4OnLdHZ!FrCsKz$|pmT*+qHNQmMI|?D7H(aa2m8{mg{WZlXIqe!Px%I9f zBYa6yjI6FhsI^7(Ju5A*rR3W+GH)=`7a4I3{Y(NNP~?>#V|#rnc7M9e@!QmEXe@el zw79z6qV$zK{&VrUU#fot^uY?lAO^Z^w>1&U4v6kku%5p399=-NN>i>=^H{vc?BI~( zOhCM5ox}6*%Z=cs6&!skuF8ss30mpKpUW1w7B7NH`?-{3ly+>}inP_#tLF9Lu)Q{T zPlKiyv9H5Sxh9MIThq<+abJv!{oyy58^O1N3LN3C+KriQu4pr?IpD{BuZKT3SV#;2 z4n9uDoqU2tSvJW`?3)WBC%=ivScsndc##R0Ezk6r!itZ_^;Ro6dg#6SQQU!k(ti8* zbe{pdejgdeW>%49zp!@O{gcxN#vgoG!A0gKHI~#WGsu*N$OAzVnerS;Tkf0t;y-v2 zOCvBQk3YTU+i&@vRy8P+yh}!Oxl_;^P46dgZZq+l0yFp+TOy+gkOtPlYeY<$&H{E~ z0p6ce!JBJ%%3A~TchX>94@lYdJ-A^msP23nJ=XPA4Cx0>#dAoai`k2u^P*$WFpd^1IOuo%6zuWme903&$5Cp zjk{y!(McsXtCZI0+C8-&BK%ouO+^RY1D2N;PHKvIop`(F*N6gyWIl(&Wori(2Z+5K zwvy5o6TWA7Bm?(=B%~0;6JOgN1IgvY)^H7serrySRdfKBA%1Oz)>WIUt*e{g8M}

EMK4pzKNv$*9N}_C`alG`Zn5Wm)t7MIkVkYLMCuZA{0A=(&G--@t^1@< z3Z+I~Umfc}0XR=YEn#Jn_IS1=wElC8U{F;MSMMl7soRr4V^gMu@z&j(nTcn_sea13 z%ZEKFX1*YpWhK6{gUmIl3}&Iz&v%Dv46A`IPmYAi7X16R!N4LX0#EZblm;IZtCO^S z`PQNRox8a{?4=VIWzKV4)iDhNt?|2i$)o+>Tj{GATr5sw!atwSlK!tl)cH{kPohnu zVFK(a*z~I3(=TvCdk8+zo+wngI@zGqiJ#683x!>k+p`&A2l1#vS6#G&WsJ+KpH0CL z89=YA05JxUSslnuo~5*XOqdA{&cYL1W4U)D9mXxnp*Zw&@-U$NQ-qfYvd8f&ZEpl= zNy>(gN3>j=l|kY`diNMdH?vvcn)|+ISA|*sKf(qB;Wczx&2?M+RSwZ6!)tXhu`?Y; ze<_x?=X~yX+ywUn8;9G+9Gu;_%jQcybUi!L^-Ga6`x3fEIzFPri2*BBt&UXXcxe-lG-IF?afx>Bt+Jm%o#`QTp);c+>r1_& zg=pY-jRI)NWe~vtGq80;U?l?22J@Js_2g8n6gMoo13jg?a!FQaKjZduIsl$q5=3a5 z)#7iD!_$ASz6pp;LTpTIa>u+SKuFA_303PlbPKRrwy`48|5B-YMqu_!HpsPmyk48f zA~=(QQ_`T`@QtE!Da!`A1liWQhep+PZl!fMNG;%ct!!STD#x@}kTBx}3z0*Fz(v%2 zaj9_1H=f+s9t6^L#b(9?Eh8~I_;{?f1UK2R#>-Kv0%LcxtP_W6LY@p6|Dig%Qo8DaG`Ihf?PC? z2~%aVG+Ay0u_}lYNM_)3pm*%tzW1`a$kwThq~`8IXbb!9rF$A->rTFD4d0#vS2=FV zy@rDIQ_ic!f{66e6EO@?0g`af<$D&8W Jason Dobry +Luke Sneeringer Luke Sneeringer +Stephen Sawchuk Stephen Sawchuk +Stephen Sawchuk Stephen Sawchuk \ No newline at end of file diff --git a/packages/google-cloud-dns/.nycrc b/packages/google-cloud-dns/.nycrc new file mode 100644 index 00000000000..a1a8e6920ce --- /dev/null +++ b/packages/google-cloud-dns/.nycrc @@ -0,0 +1,26 @@ +{ + "report-dir": "./.coverage", + "exclude": [ + "src/*{/*,/**/*}.js", + "src/*/v*/*.js", + "test/**/*.js" + ], + "watermarks": { + "branches": [ + 95, + 100 + ], + "functions": [ + 95, + 100 + ], + "lines": [ + 95, + 100 + ], + "statements": [ + 95, + 100 + ] + } +} diff --git a/packages/google-cloud-dns/.prettierignore b/packages/google-cloud-dns/.prettierignore new file mode 100644 index 00000000000..f6fac98b0a8 --- /dev/null +++ b/packages/google-cloud-dns/.prettierignore @@ -0,0 +1,3 @@ +node_modules/* +samples/node_modules/* +src/**/doc/* diff --git a/packages/google-cloud-dns/.prettierrc b/packages/google-cloud-dns/.prettierrc new file mode 100644 index 00000000000..df6eac07446 --- /dev/null +++ b/packages/google-cloud-dns/.prettierrc @@ -0,0 +1,8 @@ +--- +bracketSpacing: false +printWidth: 80 +semi: true +singleQuote: true +tabWidth: 2 +trailingComma: es5 +useTabs: false diff --git a/packages/google-cloud-dns/CODE_OF_CONDUCT.md b/packages/google-cloud-dns/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..46b2a08ea6d --- /dev/null +++ b/packages/google-cloud-dns/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, +and in the interest of fostering an open and welcoming community, +we pledge to respect all people who contribute through reporting issues, +posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in this project +a harassment-free experience for everyone, +regardless of level of experience, gender, gender identity and expression, +sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, +such as physical or electronic +addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct. +By adopting this Code of Conduct, +project maintainers commit themselves to fairly and consistently +applying these principles to every aspect of managing this project. +Project maintainers who do not follow or enforce the Code of Conduct +may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior +may be reported by opening an issue +or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, +available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/packages/google-cloud-dns/CONTRIBUTORS b/packages/google-cloud-dns/CONTRIBUTORS new file mode 100644 index 00000000000..5cc49293225 --- /dev/null +++ b/packages/google-cloud-dns/CONTRIBUTORS @@ -0,0 +1,14 @@ +# The names of individuals who have contributed to this project. +# +# Names are formatted as: +# name +# +Ace Nassri +Dave Gramlich +Eric Uldall +Jason Dobry +Karim +Luke Sneeringer +Stephen Sawchuk +Tim Swast +greenkeeper[bot] diff --git a/packages/google-cloud-dns/LICENSE b/packages/google-cloud-dns/LICENSE new file mode 100644 index 00000000000..7a4a3ea2424 --- /dev/null +++ b/packages/google-cloud-dns/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/packages/google-cloud-dns/README.md b/packages/google-cloud-dns/README.md index a18ba509762..a67d1e7f9c0 100644 --- a/packages/google-cloud-dns/README.md +++ b/packages/google-cloud-dns/README.md @@ -1,98 +1,124 @@ -# @google-cloud/dns ([Alpha][versioning]) -> Cloud DNS Client Library for Node.js +Google Cloud Platform logo -*Looking for more Google APIs than just DNS? You might want to check out [`google-cloud`][google-cloud].* +# Google Cloud DNS: Node.js Client -- [API Documentation][gcloud-dns-docs] -- [Official Documentation][cloud-dns-docs] +[![release level](https://img.shields.io/badge/release%20level-alpha-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages) +[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-dns.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-dns) +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/googleapis/nodejs-dns?branch=master&svg=true)](https://ci.appveyor.com/project/googleapis/nodejs-dns) +[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-dns/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-dns) +> Node.js idiomatic client for [Cloud DNS][product-docs]. -```sh -$ npm install --save @google-cloud/dns -``` -```js -var dns = require('@google-cloud/dns')({ - projectId: 'grape-spaceship-123', - keyFilename: '/path/to/keyfile.json' -}); +[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google's infrastructure for production-quality, high-volume DNS services. Google's global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world. -// Create a managed zone. -dns.createZone('my-new-zone', { - dnsName: 'my-domain.com.' -}, function(err, zone) {}); +* [Cloud DNS Node.js Client API Reference][client-docs] +* [Cloud DNS Documentation][product-docs] -// Reference an existing zone. -var zone = dns.zone('my-existing-zone'); +Read more about the client libraries for Cloud APIs, including the older +Google APIs Client Libraries, in [Client Libraries Explained][explained]. -// Create an NS record. -var nsRecord = zone.record('ns', { - ttl: 86400, - name: 'my-domain.com.', - data: 'ns-cloud1.googledomains.com.' -}); +[explained]: https://cloud.google.com/apis/docs/client-libraries-explained -zone.addRecords([nsRecord], function(err, change) {}); +**Table of contents:** -// Create a zonefile from the records in your zone. -zone.export('/zonefile.zone', function(err) {}); +* [Quickstart](#quickstart) + * [Before you begin](#before-you-begin) + * [Installing the client library](#installing-the-client-library) + * [Using the client library](#using-the-client-library) +* [Samples](#samples) +* [Versioning](#versioning) +* [Contributing](#contributing) +* [License](#license) -// Promises are also supported by omitting callbacks. -zone.addRecords([nsRecord]).then(function(data) { - var change = data[0]; -}); +## Quickstart -// It's also possible to integrate with third-party Promise libraries. -var dns = require('@google-cloud/dns')({ - promise: require('bluebird') -}); -``` +### Before you begin +1. Select or create a Cloud Platform project. -## Authentication + [Go to the projects page][projects] -It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services. +1. Enable billing for your project. -### On Google Cloud Platform + [Enable billing][billing] -If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access. +1. Enable the Google Cloud DNS API. -``` js -var dns = require('@google-cloud/dns')(); -// ...you're good to go! -``` + [Enable the API][enable_api] -### Elsewhere +1. [Set up authentication with a service account][auth] so you can access the + API from your local workstation. -If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account: +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started -1. Visit the [Google Developers Console][dev-console]. -2. Create a new project or click on an existing project. -3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services): - * Google Cloud DNS API -4. Navigate to **APIs & auth** > **Credentials** and then: - * If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests. - * If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file. +### Installing the client library -``` js -var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123' + npm install --save @google-cloud/dns -var dns = require('@google-cloud/dns')({ - projectId: projectId, +### Using the client library + +```javascript +// Imports the Google Cloud client library +const DNS = require('@google-cloud/dns'); - // The path to your key file: - keyFilename: '/path/to/keyfile.json' +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; - // Or the contents of the key file: - credentials: require('./path/to/keyfile.json') +// Creates a client +const dns = new DNS({ + projectId: projectId, }); -// ...you're good to go! +// Lists all zones in the current project +dns + .getZones() + .then(results => { + const zones = results[0]; + + console.log('Zones:'); + zones.forEach(zone => console.log(zone.name)); + }) + .catch(err => { + console.error('ERROR:', err); + }); ``` +## Samples + +Samples are in the [`samples/`](https://github.com/blob/master/samples) directory. The samples' `README.md` +has instructions for running the samples. + +| Sample | Source Code | +| --------------------------- | --------------------------------- | +| Zones | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/zones.js) | + +The [Cloud DNS Node.js Client API Reference][client-docs] documentation +also contains samples. + +## Versioning + +This library follows [Semantic Versioning](http://semver.org/). + +This library is considered to be in **alpha**. This means it is still a +work-in-progress and under active development. Any release is subject to +backwards-incompatible changes at any time. + +More Information: [Google Cloud Platform Launch Stages][launch_stages] + +[launch_stages]: https://cloud.google.com/terms/launch-stages + +## Contributing + +Contributions welcome! See the [Contributing Guide](.github/CONTRIBUTING.md). + +## License + +Apache Version 2.0 + +See [LICENSE](LICENSE) -[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning -[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node -[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using -[dev-console]: https://console.developers.google.com/project -[gcloud-dns-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/dns -[cloud-dns-docs]: https://cloud.google.com/dns/docs +[client-docs]: https://cloud.google.com/nodejs/docs/reference/dns/latest/ +[product-docs]: https://cloud.google.com/dns/docs/ diff --git a/packages/google-cloud-dns/package.json b/packages/google-cloud-dns/package.json index efe913caa00..ae2c441f5ef 100644 --- a/packages/google-cloud-dns/package.json +++ b/packages/google-cloud-dns/package.json @@ -1,34 +1,13 @@ { "name": "@google-cloud/dns", + "description": "Cloud DNS Client Library for Node.js", "version": "0.6.2", + "license": "Apache-2.0", "author": "Google Inc.", - "description": "Cloud DNS Client Library for Node.js", - "contributors": [ - { - "name": "Burcu Dogan", - "email": "jbd@google.com" - }, - { - "name": "Johan Euphrosine", - "email": "proppy@google.com" - }, - { - "name": "Patrick Costello", - "email": "pcostell@google.com" - }, - { - "name": "Ryan Seys", - "email": "ryan@ryanseys.com" - }, - { - "name": "Silvano Luciani", - "email": "silvano@google.com" - }, - { - "name": "Stephen Sawchuk", - "email": "sawchuk@gmail.com" - } - ], + "engines": { + "node": ">=4.0.0" + }, + "repository": "googleapis/nodejs-dns", "main": "./src/index.js", "files": [ "src", @@ -36,7 +15,6 @@ "CONTRIBUTORS", "LICENSE" ], - "repository": "googlecloudplatform/google-cloud-node", "keywords": [ "google apis client", "google api client", @@ -49,29 +27,56 @@ "google dns", "dns" ], + "contributors": [ + "Ace Nassri ", + "Dave Gramlich ", + "Eric Uldall ", + "Jason Dobry ", + "Karim ", + "Luke Sneeringer ", + "Stephen Sawchuk ", + "Tim Swast ", + "greenkeeper[bot] " + ], + "scripts": { + "cover": "nyc --reporter=lcov mocha --require intelli-espower-loader test/*.js && nyc report", + "docs": "repo-tools exec -- jsdoc -c .jsdoc.js", + "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", + "lint": "repo-tools lint --cmd eslint -- src/ samples/ system-test/ test/", + "prettier": "repo-tools exec -- prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js", + "publish-module": "node ../../scripts/publish.js dns", + "test-no-cover": "repo-tools test run --cmd mocha -- test/*.js --no-timeouts", + "test": "repo-tools test run --cmd npm -- run cover", + "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", + "system-test": "repo-tools test run --cmd mocha -- system-test/*.js --no-timeouts" + }, "dependencies": { "@google-cloud/common": "^0.13.0", "arrify": "^1.0.0", - "dns-zonefile": "0.1.18", + "dns-zonefile": "0.2.2", "extend": "^3.0.0", "is": "^3.0.1", "methmeth": "^1.0.0", "string-format-obj": "^1.0.0" }, "devDependencies": { + "@google-cloud/nodejs-repo-tools": "^2.0.9", "async": "^2.1.4", - "mocha": "^3.0.1", + "codecov": "^2.3.1", + "eslint": "^4.9.0", + "eslint-config-prettier": "^2.6.0", + "eslint-plugin-node": "^5.2.0", + "eslint-plugin-prettier": "^2.3.1", + "extend": "^3.0.1", + "ink-docstrap": "^1.3.0", + "intelli-espower-loader": "^1.0.1", + "jsdoc": "^3.5.5", + "mocha": "^4.0.1", + "nyc": "^11.2.1", + "power-assert": "^1.4.4", + "prettier": "^1.7.4", "proxyquire": "^1.7.10", - "tmp": "^0.0.31", + "tmp": "^0.0.33", "uuid": "^3.0.1" - }, - "scripts": { - "publish-module": "node ../../scripts/publish.js dns", - "test": "mocha test/*.js", - "system-test": "mocha system-test/*.js --no-timeouts --bail" - }, - "license": "Apache-2.0", - "engines": { - "node": ">=4.0.0" } } diff --git a/packages/google-cloud-dns/samples/.eslintrc.yml b/packages/google-cloud-dns/samples/.eslintrc.yml new file mode 100644 index 00000000000..282535f55f6 --- /dev/null +++ b/packages/google-cloud-dns/samples/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/packages/google-cloud-dns/samples/README.md b/packages/google-cloud-dns/samples/README.md index edd76b58652..d461040ad51 100644 --- a/packages/google-cloud-dns/samples/README.md +++ b/packages/google-cloud-dns/samples/README.md @@ -1,39 +1,28 @@ Google Cloud Platform logo -# Google Cloud DNS Node.js Samples +# Google Cloud DNS: Node.js Samples -[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-dns.svg)]() +[![Build](https://storage.googleapis.com/.svg)]() [Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google's infrastructure for production-quality, high-volume DNS services. Google's global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world. ## Table of Contents -* [Setup](#setup) +* [Before you begin](#before-you-begin) * [Samples](#samples) * [Zones](#zones) -* [Running the tests](#running-the-tests) -## Setup +## Before you begin -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. -1. Install dependencies: - - With **npm**: - - npm install - - With **yarn**: - - yarn install - -[prereq]: ../README.md#prerequisites -[run]: ../README.md#how-to-run-a-sample +Before running the samples, make sure you've followed the steps in the +[Before you begin section](../README.md#before-you-begin) of the client +library's README. ## Samples ### Zones -View the [documentation][zones_0_docs] or the [source code][zones_0_code]. +View the [source code][zones_0_code]. __Usage:__ `node zones.js --help` @@ -42,7 +31,8 @@ Commands: list Lists all zones in the current project. Options: - --help Show help [boolean] + --version Show version number [boolean] + --help Show help [boolean] Examples: node zones.js list Lists all zones in the current project. @@ -52,17 +42,3 @@ For more information, see https://cloud.google.com/dns/docs [zones_0_docs]: https://cloud.google.com/dns/docs [zones_0_code]: zones.js - -## Running the tests - -1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. - -1. Run the tests: - - With **npm**: - - npm test - - With **yarn**: - - yarn test diff --git a/packages/google-cloud-dns/samples/package.json b/packages/google-cloud-dns/samples/package.json index 2ccca35ab82..f1bc983526e 100644 --- a/packages/google-cloud-dns/samples/package.json +++ b/packages/google-cloud-dns/samples/package.json @@ -4,40 +4,25 @@ "private": true, "license": "Apache-2.0", "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, + "repository": "googleapis/nodejs-dns", "engines": { - "node": ">=4.3.2" + "node": ">=4.0.0" }, "scripts": { - "lint": "samples lint", - "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 1m --verbose system-test/*.test.js" + "ava": "ava -T 20s --verbose test/*.test.js system-test/*.test.js", + "cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js system-test/*.test.js && nyc report", + "test": "repo-tools test run --cmd npm -- run cover" }, "dependencies": { "@google-cloud/dns": "0.6.2", - "yargs": "8.0.2" + "yargs": "9.0.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", + "@google-cloud/nodejs-repo-tools": "2.0.10", + "ava": "0.22.0", + "nyc": "11.2.1", "proxyquire": "1.8.0", - "sinon": "3.2.0" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true, - "product": "dns", - "samples": [ - { - "id": "zones", - "name": "Zones", - "file": "zones.js", - "docs_link": "https://cloud.google.com/dns/docs", - "usage": "node zones.js --help" - } - ] + "sinon": "4.0.1", + "uuid": "3.1.0" } } diff --git a/packages/google-cloud-dns/samples/quickstart.js b/packages/google-cloud-dns/samples/quickstart.js index f686c389ddc..65491560803 100644 --- a/packages/google-cloud-dns/samples/quickstart.js +++ b/packages/google-cloud-dns/samples/quickstart.js @@ -22,17 +22,21 @@ const DNS = require('@google-cloud/dns'); // Your Google Cloud Platform project ID const projectId = 'YOUR_PROJECT_ID'; -// Instantiates a client -const dnsClient = DNS({ - projectId: projectId +// Creates a client +const dns = new DNS({ + projectId: projectId, }); // Lists all zones in the current project -dnsClient.getZones() - .then((results) => { +dns + .getZones() + .then(results => { const zones = results[0]; console.log('Zones:'); - zones.forEach((zone) => console.log(zone.name)); + zones.forEach(zone => console.log(zone.name)); + }) + .catch(err => { + console.error('ERROR:', err); }); // [END dns_quickstart] diff --git a/packages/google-cloud-dns/src/change.js b/packages/google-cloud-dns/src/change.js index 93c78051efd..c85dc3d04e1 100644 --- a/packages/google-cloud-dns/src/change.js +++ b/packages/google-cloud-dns/src/change.js @@ -14,21 +14,16 @@ * limitations under the License. */ -/*! - * @module dns/change - */ - 'use strict'; var common = require('@google-cloud/common'); var util = require('util'); /** - * @constructor - * @alias module:dns/change + * @class * - * @param {module:dns/zone} zone - The parent zone object. - * @param {string} id - ID of the change. + * @param {Zone} zone The parent zone object. + * @param {string} id ID of the change. * * @example * var zone = dns.zone('zone-id'); @@ -36,13 +31,21 @@ var util = require('util'); */ function Change(zone, id) { var methods = { + /** + * @typedef {array} ChangeExistsResponse + * @property {boolean} 0 Whether the {@link Change} exists. + */ + /** + * @callback ChangeExistsCallback + * @param {?Error} err Request error, if any. + * @param {boolean} exists Whether the {@link Change} exists. + */ /** * Check if the change exists. * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An error returned while making this - * request. - * @param {boolean} callback.exists - Whether the change exists or not. + * @method Change#exists + * @param {ChangeExistsCallback} [callback] Callback function. + * @returns {Promise} * * @example * change.exists(function(err, exists) {}); @@ -56,6 +59,17 @@ function Change(zone, id) { */ exists: true, + /** + * @typedef {array} GetChangeResponse + * @property {Change} 0 The {@link Change}. + * @property {object} 1 The full API response. + */ + /** + * @callback GetChangeCallback + * @param {?Error} err Request error, if any. + * @param {Change} change The {@link Change}. + * @param {object} apiResponse The full API response. + */ /** * Get a change if it exists. * @@ -64,9 +78,12 @@ function Change(zone, id) { * normally required for the `create` method must be contained within this * object as well. * - * @param {options=} options - Configuration object. - * @param {boolean} options.autoCreate - Automatically create the object if - * it does not exist. Default: `false` + * @method Change#get + * @param {options} [options] Configuration object. + * @param {boolean} [options.autoCreate=false] Automatically create the + * object if it does not exist. + * @param {GetChangeCallback} [callback] Callback function. + * @returns {Promise} * * @example * change.get(function(err, change, apiResponse) { @@ -83,15 +100,25 @@ function Change(zone, id) { */ get: true, + /** + * @typedef {array} GetChangeMetadataResponse + * @property {object} 0 The {@link Change} metadata. + * @property {object} 1 The full API response. + */ + /** + * @callback GetChangeMetadataCallback + * @param {?Error} err Request error, if any. + * @param {object} metadata The {@link Change} metadata. + * @param {object} apiResponse The full API response. + */ /** * Get the metadata for the change in the zone. * * @resource [Changes: get API Documentation]{@link https://cloud.google.com/dns/api/v1/changes/get} * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?object} callback.metadata - Metadata of the change from the API. - * @param {object} callback.apiResponse - Raw API response. + * @method Change#getMetadata + * @param {GetChangeMetadataCallback} [callback] Callback function. + * @returns {Promise} * * @example * change.getMetadata(function(err, metadata, apiResponse) { @@ -116,14 +143,29 @@ function Change(zone, id) { * var apiResponse = data[1]; * }); */ - getMetadata: true + getMetadata: true, }; + /** + * @name Change#metadata + * @type {object} + */ common.ServiceObject.call(this, { parent: zone, + + /** + * @name Zone#baseUrl + * @type {string} + * @default "/changes" + */ baseUrl: '/changes', + + /** + * @name Change#id + * @type {string} + */ id: id, - methods: methods + methods: methods, }); } @@ -132,7 +174,10 @@ util.inherits(Change, common.ServiceObject); /** * Create a change. * - * @param {object} config - See {module:dns/zone#createChange}. + * @method Change#create + * @param {CreateChangeRequest} config The configuration object. + * @param {CreateChangeCallback} [callback] Callback function. + * @returns {Promise} * * @example * var config = { @@ -179,5 +224,4 @@ Change.prototype.create = function(config, callback) { */ common.util.promisifyAll(Change); - module.exports = Change; diff --git a/packages/google-cloud-dns/src/index.js b/packages/google-cloud-dns/src/index.js index 3e60ccc13fd..921d60c87c8 100644 --- a/packages/google-cloud-dns/src/index.js +++ b/packages/google-cloud-dns/src/index.js @@ -14,10 +14,6 @@ * limitations under the License. */ -/*! - * @module dns - */ - 'use strict'; var arrify = require('arrify'); @@ -26,11 +22,32 @@ var extend = require('extend'); var is = require('is'); var util = require('util'); +var Zone = require('./zone.js'); + /** - * @type {module:dns/zone} - * @private + * @typedef {object} ClientConfig + * @property {string} [projectId] The project ID from the Google Developer's + * Console, e.g. 'grape-spaceship-123'. We will also check the environment + * variable `GCLOUD_PROJECT` for your project ID. If your app is running in + * an environment which supports {@link https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application Application Default Credentials}, + * your project ID will be detected automatically. + * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key + * downloaded from the Google Developers Console. If you provide a path to a + * JSON file, the `projectId` option above is not necessary. NOTE: .pem and + * .p12 require you to specify the `email` option as well. + * @property {string} [email] Account email address. Required when using a .pem + * or .p12 keyFilename. + * @property {object} [credentials] Credentials object. + * @property {string} [credentials.client_email] + * @property {string} [credentials.private_key] + * @property {boolean} [autoRetry=true] Automatically retry requests if the + * response is related to rate limits or certain intermittent server errors. + * We will exponentially backoff subsequent requests by default. + * @property {number} [maxRetries=3] Maximum number of automatic retries + * attempted before returning the error. + * @property {Constructor} [promise] Custom promise module to use instead of + * native Promises. */ -var Zone = require('./zone.js'); /** * [Cloud DNS](https://cloud.google.com/dns/what-is-cloud-dns) is a high- @@ -39,12 +56,27 @@ var Zone = require('./zone.js'); * programmable, authoritative DNS service can be used to easily publish and * manage DNS records using the same infrastructure relied upon by Google. * - * @constructor - * @alias module:dns + * @class * - * @resource [What is Cloud DNS?]{@link https://cloud.google.com/dns/what-is-cloud-dns} + * @see [What is Cloud DNS?]{@link https://cloud.google.com/dns/what-is-cloud-dns} * - * @param {object} options - [Configuration object](#/docs). + * @param {ClientConfig} [options] Configuration options. + * + * @example Import the client library + * const DNS = require('@google-cloud/dns'); + * + * @example Create a client that uses Application Default Credentials (ADC): + * const dns = new DNS(); + * + * @example Create a client with explicit credentials: + * const dns = new DNS({ + * projectId: 'your-project-id', + * keyFilename: '/path/to/keyfile.json' + * }); + * + * @example include:samples/quickstart.js + * region_tag:dns_quickstart + * Full quickstart example: */ function DNS(options) { if (!(this instanceof DNS)) { @@ -56,9 +88,9 @@ function DNS(options) { baseUrl: 'https://www.googleapis.com/dns/v1', scopes: [ 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', - 'https://www.googleapis.com/auth/cloud-platform' + 'https://www.googleapis.com/auth/cloud-platform', ], - packageJson: require('../package.json') + packageJson: require('../package.json'), }; common.Service.call(this, config, options); @@ -66,22 +98,38 @@ function DNS(options) { util.inherits(DNS, common.Service); +/** + * Config to set for the zone. + * + * @typedef {object} CreateZoneRequest + * @property {string} dnsName DNS name for the zone. E.g. "example.com." + * @property {string} [description] Description text for the zone. + */ +/** + * @typedef {array} CreateZoneResponse + * @property {Zone} 0 The new {@link Zone}. + * @property {object} 1 The full API response. + */ +/** + * @callback CreateZoneCallback + * @param {?Error} err Request error, if any. + * @param {Zone} zone The new {@link Zone}. + * @param {object} apiResponse The full API response. + */ /** * Create a managed zone. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * * @throws {error} If a zone name is not provided. * @throws {error} If a zone dnsName is not provided. * - * @param {string} name - Unique name for the zone. E.g. "my-zone" - * @param {object} config - Configuration object. - * @param {string} config.dnsName - DNS name for the zone. E.g. "example.com." - * @param {string=} config.description - Description text for the zone. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/zone} callback.zone - A new {module:dns/zone} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {string} name Name of the zone to create, e.g. "my-zone". + * @param {CreateZoneRequest} [config] Config to set for the zone. + * @param {CreateZoneCallback} [callback] Callback function. + * @returns {Promise} + * @throws {Error} If a name is not provided. + * @see Zone#create * * @example * var config = { @@ -119,39 +167,57 @@ DNS.prototype.createZone = function(name, config, callback) { // Required by the API. config.description = config.description || ''; - this.request({ - method: 'POST', - uri: '/managedZones', - json: config - }, function(err, resp) { - if (err) { - callback(err, null, resp); - return; - } + this.request( + { + method: 'POST', + uri: '/managedZones', + json: config, + }, + function(err, resp) { + if (err) { + callback(err, null, resp); + return; + } - var zone = self.zone(resp.name); - zone.metadata = resp; + var zone = self.zone(resp.name); + zone.metadata = resp; - callback(null, zone, resp); - }); + callback(null, zone, resp); + } + ); }; +/** + * Query object for listing zones. + * + * @typedef {object} GetZonesRequest + * @property {boolean} [autoPaginate=true] Have pagination handled + * automatically. + * @property {number} [maxApiCalls] Maximum number of API calls to make. + * @property {number} [maxResults] Maximum number of items plus prefixes to + * return. + * @property {string} [pageToken] A previously-returned page token + * representing part of the larger set of results to view. + */ +/** + * @typedef {array} GetZonesResponse + * @property {Zone[]} 0 Array of {@link Zone} instances. + * @property {object} 1 The full API response. + */ +/** + * @callback GetZonesCallback + * @param {?Error} err Request error, if any. + * @param {Zone[]} zones Array of {@link Zone} instances. + * @param {object} apiResponse The full API response. + */ /** * Gets a list of managed zones for the project. * - * @resource [ManagedZones: list API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/list} + * @see [ManagedZones: list API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/list} * - * @param {object=} query - Query object. - * @param {boolean} query.autoPaginate - Have pagination handled automatically. - * Default: true. - * @param {number} query.maxApiCalls - Maximum number of API calls to make. - * @param {number} query.maxResults - Maximum number of results to return. - * @param {string} query.pageToken - Page token. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/zone[]} callback.zones - An array of {module:dns/zone} - * objects. - * @param {object} callback.apiResponse - Raw API response. + * @param {GetZonesRequest} [query] Query object for listing zones. + * @param {GetZonesCallback} [callback] Callback function. + * @returns {Promise} * * @example * dns.getZones(function(err, zones, apiResponse) {}); @@ -171,40 +237,43 @@ DNS.prototype.getZones = function(query, callback) { query = {}; } - this.request({ - uri: '/managedZones', - qs: query - }, function(err, resp) { - if (err) { - callback(err, null, null, resp); - return; - } + this.request( + { + uri: '/managedZones', + qs: query, + }, + function(err, resp) { + if (err) { + callback(err, null, null, resp); + return; + } - var zones = arrify(resp.managedZones).map(function(zone) { - var zoneInstance = self.zone(zone.name); - zoneInstance.metadata = zone; - return zoneInstance; - }); + var zones = arrify(resp.managedZones).map(function(zone) { + var zoneInstance = self.zone(zone.name); + zoneInstance.metadata = zone; + return zoneInstance; + }); - var nextQuery = null; + var nextQuery = null; - if (resp.nextPageToken) { - nextQuery = extend({}, query, { - pageToken: resp.nextPageToken - }); - } + if (resp.nextPageToken) { + nextQuery = extend({}, query, { + pageToken: resp.nextPageToken, + }); + } - callback(null, zones, nextQuery, resp); - }); + callback(null, zones, nextQuery, resp); + } + ); }; /** - * Gets a list of {module:dns/zone} objects for the project as a readable object - * stream. + * Get {@link Zone} objects for all of the zones in your project as + * a readable object stream. * - * @param {object=} query - Configuration object. See - * {module:dns#getZones} for a complete list of options. - * @return {stream} + * @method DNS#getZonesStream + * @param {GetZonesRequest} [query] Query object for listing zones. + * @returns {ReadableStream} A readable stream that emits {@link Zone} instances. * * @example * dns.getZonesStream() @@ -228,12 +297,13 @@ DNS.prototype.getZones = function(query, callback) { DNS.prototype.getZonesStream = common.paginator.streamify('getZones'); /** - * Create a zone object representing a managed zone. + * Get a reference to a Zone. * - * @throws {error} If a zone name is not provided. + * @param {string} name The unique name of the zone. + * @returns {Zone} + * @see Zone * - * @param {string} name - The unique name of the zone. - * @return {module:dns/zone} + * @throws {error} If a zone name is not provided. * * @example * var zone = dns.zone('my-zone'); @@ -258,9 +328,45 @@ common.paginator.extend(DNS, 'getZones'); * that a callback is omitted. */ common.util.promisifyAll(DNS, { - exclude: ['zone'] + exclude: ['zone'], }); +/** + * {@link Zone} class. + * + * @name DNS.Zone + * @see Zone + * @type {Constructor} + */ DNS.Zone = Zone; +/** + * The default export of the `@google-cloud/dns` package is the {@link DNS} + * class. + * + * See {@link DNS} and {@link ClientConfig} for client methods and + * configuration options. + * + * @module {DNS} @google-cloud/dns + * @alias nodejs-dns + * + * @example Install the client library with npm: + * npm install --save @google-cloud/dns + * + * @example Import the client library + * const DNS = require('@google-cloud/dns'); + * + * @example Create a client that uses Application Default Credentials (ADC): + * const dns = new DNS(); + * + * @example Create a client with explicit credentials: + * const dns = new DNS({ + * projectId: 'your-project-id', + * keyFilename: '/path/to/keyfile.json' + * }); + * + * @example include:samples/quickstart.js + * region_tag:dns_quickstart + * Full quickstart example: + */ module.exports = DNS; diff --git a/packages/google-cloud-dns/src/record.js b/packages/google-cloud-dns/src/record.js index eb8d53ef0f1..6ca45b18ff5 100644 --- a/packages/google-cloud-dns/src/record.js +++ b/packages/google-cloud-dns/src/record.js @@ -14,10 +14,6 @@ * limitations under the License. */ -/*! - * @module dns/record - */ - 'use strict'; var arrify = require('arrify'); @@ -28,17 +24,16 @@ var format = require('string-format-obj'); /** * Create a Resource Record object. * - * @constructor - * @alias module:dns/record + * @class * - * @param {object} type - The record type, e.g. `A`, `AAAA`, `MX`. - * @param {object} metadata - The metadata of this record. - * @param {string} metadata.name - The name of the record, e.g. + * @param {string} type The record type, e.g. `A`, `AAAA`, `MX`. + * @param {object} metadata The metadata of this record. + * @param {string} metadata.name The name of the record, e.g. * `www.example.com.`. - * @param {string[]} metadata.data - Defined in + * @param {string[]} metadata.data Defined in * [RFC 1035, section 5](https://goo.gl/9EiM0e) and * [RFC 1034, section 3.6.1](https://goo.gl/Hwhsu9). - * @param {number} metadata.ttl - Seconds that the resource is cached by + * @param {number} metadata.ttl Seconds that the resource is cached by * resolvers. * * @example @@ -53,12 +48,28 @@ var format = require('string-format-obj'); function Record(zone, type, metadata) { this.zone_ = zone; + /** + * @name Record#type + * @type {string} + */ this.type = type; + + /** + * @name Record#metadata + * @type {object} + * @property {string} name + * @property {string[]} data + * @property {number} metadata.ttl + */ this.metadata = metadata; extend(this, this.toJSON()); if (this.rrdatas) { + /** + * @name Record#data + * @type {?object[]} + */ this.data = this.rrdatas; delete this.rrdatas; } @@ -69,11 +80,11 @@ function Record(zone, type, metadata) { * * @private * - * @param {module:dns/zone} zone [description] - * @param {string} type - The record type, e.g. `A`, `AAAA`, `MX`. - * @param {object} bindData - Metadata parsed from dns-zonefile. Properties vary + * @param {Zone} zone The zone. + * @param {string} type The record type, e.g. `A`, `AAAA`, `MX`. + * @param {object} bindData Metadata parsed from dns-zonefile. Properties vary * based on the type of record. - * @return {module:dns/record} + * @returns {Record} */ Record.fromZoneRecord_ = function(zone, type, bindData) { var typeToZoneFormat = { @@ -85,18 +96,29 @@ Record.fromZoneRecord_ = function(zone, type, bindData) { soa: '{mname} {rname} {serial} {retry} {refresh} {expire} {minimum}', spf: '{data}', srv: '{priority} {weight} {port} {target}', - txt: '{txt}' + txt: '{txt}', }; var metadata = { data: format(typeToZoneFormat[type.toLowerCase()], bindData), name: bindData.name, - ttl: bindData.ttl + ttl: bindData.ttl, }; return new Record(zone, type, metadata); }; +/** + * @typedef {array} DeleteRecordResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback DeleteRecordCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Delete this record by creating a change on your zone. This is a convenience * method for: @@ -105,12 +127,10 @@ Record.fromZoneRecord_ = function(zone, type, bindData) { * delete: record * }, function(err, change, apiResponse) {}); * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {DeleteRecordCallback} [callback] Callback function. + * @returns {Promise} * * @example * record.delete(function(err, change, apiResponse) { @@ -134,11 +154,11 @@ Record.prototype.delete = function(callback) { /** * Serialize the record instance to the format the API expects. * - * @private + * @returns {object} */ Record.prototype.toJSON = function() { var recordObject = extend({}, this.metadata, { - type: this.type.toUpperCase() + type: this.type.toUpperCase(), }); if (recordObject.data) { @@ -152,17 +172,17 @@ Record.prototype.toJSON = function() { /** * Convert the record to a string, formatted for a zone file. * - * @private - * - * @return {string} + * @returns {string} */ Record.prototype.toString = function() { var json = this.toJSON(); - return (json.rrdatas || [{}]).map(function(data) { - json.rrdata = data; - return format('{name} {ttl} IN {type} {rrdata}', json); - }).join('\n'); + return (json.rrdatas || [{}]) + .map(function(data) { + json.rrdata = data; + return format('{name} {ttl} IN {type} {rrdata}', json); + }) + .join('\n'); }; /*! Developer Documentation @@ -171,7 +191,7 @@ Record.prototype.toString = function() { * that a callback is omitted. */ common.util.promisifyAll(Record, { - exclude: ['toJSON', 'toString'] + exclude: ['toJSON', 'toString'], }); module.exports = Record; diff --git a/packages/google-cloud-dns/src/zone.js b/packages/google-cloud-dns/src/zone.js index 3c2821669e0..d59bb3c66e2 100644 --- a/packages/google-cloud-dns/src/zone.js +++ b/packages/google-cloud-dns/src/zone.js @@ -14,10 +14,6 @@ * limitations under the License. */ -/*! - * @module dns/zone - */ - 'use strict'; var arrify = require('arrify'); @@ -29,16 +25,7 @@ var is = require('is'); var util = require('util'); var zonefile = require('dns-zonefile'); -/** - * @type {module:dns/change} - * @private - */ var Change = require('./change.js'); - -/** - * @type {module:dns/record} - * @private - */ var Record = require('./record.js'); /** @@ -46,8 +33,7 @@ var Record = require('./record.js'); * help you add or delete records, delete your zone, and many other convenience * methods. * - * @constructor - * @alias module:dns/zone + * @class * * @example * var zone = dns.zone('zone-id'); @@ -57,7 +43,10 @@ function Zone(dns, name) { /** * Create a zone. * - * @param {object} config - See {module:dns#createZone}. + * @method Zone#create + * @param {CreateZoneRequest} [metadata] Metadata to set for the zone. + * @param {CreateZoneCallback} [callback] Callback function. + * @returns {Promise} * * @example * var config = { @@ -81,13 +70,21 @@ function Zone(dns, name) { */ create: true, + /** + * @typedef {array} ZoneExistsResponse + * @property {boolean} 0 Whether the {@link Zone} exists. + */ + /** + * @callback ZoneExistsCallback + * @param {?Error} err Request error, if any. + * @param {boolean} exists Whether the {@link Zone} exists. + */ /** * Check if the zone exists. * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An error returned while making this - * request. - * @param {boolean} callback.exists - Whether the zone exists or not. + * @method Zone#exists + * @param {ZoneExistsCallback} [callback] Callback function. + * @returns {Promise} * * @example * zone.exists(function(err, exists) {}); @@ -101,6 +98,17 @@ function Zone(dns, name) { */ exists: true, + /** + * @typedef {array} GetZoneResponse + * @property {Zone} 0 The {@link Zone}. + * @property {object} 1 The full API response. + */ + /** + * @callback GetZoneCallback + * @param {?Error} err Request error, if any. + * @param {Zone} zone The {@link Zone}. + * @param {object} apiResponse The full API response. + */ /** * Get a zone if it exists. * @@ -109,9 +117,12 @@ function Zone(dns, name) { * normally required for the `create` method must be contained within this * object as well. * - * @param {options=} options - Configuration object. - * @param {boolean} options.autoCreate - Automatically create the object if - * it does not exist. Default: `false` + * @method Zone#get + * @param {options} [options] Configuration object. + * @param {boolean} [options.autoCreate=false] Automatically create the + * object if it does not exist. + * @param {GetZoneCallback} [callback] Callback function. + * @returns {Promise} * * @example * zone.get(function(err, zone, apiResponse) { @@ -128,15 +139,25 @@ function Zone(dns, name) { */ get: true, + /** + * @typedef {array} GetZoneMetadataResponse + * @property {object} 0 The {@link Zone} metadata. + * @property {object} 1 The full API response. + */ + /** + * @callback GetZoneMetadataCallback + * @param {?Error} err Request error, if any. + * @param {object} metadata The {@link Zone} metadata. + * @param {object} apiResponse The full API response. + */ /** * Get the metadata for the zone. * - * @resource [ManagedZones: get API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/get} + * @see [ManagedZones: get API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/get} * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?object} callback.metadata - Metadata of the zone from the API. - * @param {object} callback.apiResponse - Raw API response. + * @method Zone#getMetadata + * @param {GetZoneMetadataCallback} [callback] Callback function. + * @returns {Promise} * * @example * zone.getMetadata(function(err, metadata, apiResponse) {}); @@ -149,45 +170,76 @@ function Zone(dns, name) { * var apiResponse = data[1]; * }); */ - getMetadata: true + getMetadata: true, }; + /** + * @name Zone#metadata + * @type {object} + */ common.ServiceObject.call(this, { parent: dns, + + /** + * @name Zone#baseUrl + * @type {string} + * @default "/managedZones" + */ baseUrl: '/managedZones', + + /** + * @name Zone#id + * @type {string} + */ id: name, createMethod: dns.createZone.bind(dns), - methods: methods + methods: methods, }); + /** + * @name Zone#name + * @type {string} + */ this.name = name; } util.inherits(Zone, common.ServiceObject); +/** + * @typedef {array} ZoneAddRecordsResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback ZoneAddRecordsCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Add records to this zone. This is a convenience wrapper around - * {module:dns/zone#createChange}. + * {@link Zone#createChange}. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {module:dns/record|module:dns/record[]} record - The record objects to - * add. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {Record|Record[]} record The {@link Record} object(s) to add. + * @param {ZoneAddRecordsCallback} [callback] Callback function. + * @returns {Promise} */ Zone.prototype.addRecords = function(records, callback) { - this.createChange({ - add: records - }, callback); + this.createChange( + { + add: records, + }, + callback + ); }; /** - * Create a reference to a change object in this zone. + * Create a reference to a {@link Change} object in this zone. * - * @param {string} id - The change id. - * @return {module:dns/change} + * @param {string} id The change id. + * @returns {Change} * * @example * var change = zone.change('change-id'); @@ -196,21 +248,35 @@ Zone.prototype.change = function(id) { return new Change(this, id); }; +/** + * Config to set for the change. + * + * @typedef {object} CreateChangeRequest + * @property {Record|Record[]} add {@link Record} objects to add to this + * zone. + * @property {Record|Record[]} delete {@link Record} objects to delete + * from this zone. Be aware that the resource records here must match + * exactly to be deleted. + */ +/** + * @typedef {array} CreateChangeResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback CreateChangeCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Create a change of resource record sets for the zone. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {object} config - The configuration object. - * @param {module:dns/record|module:dns/record[]} config.add - Record objects - * to add to this zone. - * @param {module:dns/record|module:dns/record[]} config.delete - Record - * objects to delete from this zone. Be aware that the resource records here - * must match exactly to be deleted. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {CreateChangeRequest} config The configuration object. + * @param {CreateChangeCallback} [callback] Callback function. + * @returns {Promise} * * @example * var oldARecord = zone.record('a', { @@ -247,50 +313,61 @@ Zone.prototype.change = function(id) { Zone.prototype.createChange = function(config, callback) { var self = this; - if (!config || !config.add && !config.delete) { + if (!config || (!config.add && !config.delete)) { throw new Error('Cannot create a change with no additions or deletions.'); } var body = extend({}, config, { additions: arrify(config.add).map(exec('toJSON')), - deletions: arrify(config.delete).map(exec('toJSON')) + deletions: arrify(config.delete).map(exec('toJSON')), }); delete body.add; delete body.delete; - this.request({ - method: 'POST', - uri: '/changes', - json: body - }, function(err, resp) { - if (err) { - callback(err, null, resp); - return; + this.request( + { + method: 'POST', + uri: '/changes', + json: body, + }, + function(err, resp) { + if (err) { + callback(err, null, resp); + return; + } + + var change = self.change(resp.id); + change.metadata = resp; + + callback(null, change, resp); } - - var change = self.change(resp.id); - change.metadata = resp; - - callback(null, change, resp); - }); + ); }; +/** + * @typedef {array} DeleteZoneResponse + * @property {object} 0 The full API response. + */ +/** + * @callback DeleteZoneCallback + * @param {?Error} err Request error, if any. + * @param {object} apiResponse The full API response. + */ /** * Delete the zone. * - * Only empty zones can be deleted. Set options.force to `true` to call - * {module:dns/zone#empty} before deleting the zone. Two API calls will then be + * Only empty zones can be deleted. Set `options.force` to `true` to call + * {@link Zone#empty} before deleting the zone. Two API calls will then be * made (one to empty, another to delete), which means this is not an * atomic request. * - * @resource [ManagedZones: delete API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/delete} + * @see [ManagedZones: delete API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/delete} * - * @param {object=} options - Configuration object. - * @param {boolean} options.force - Empty the zone before deleting. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {object} callback.apiResponse - Raw API response. + * @param {object} [options] Configuration object. + * @param {boolean} [options.force=false] Empty the zone before deleting. + * @param {DeleteZoneCallback} [callback] Callback function. + * @returns {Promise} * * @example * zone.delete(function(err, apiResponse) { @@ -331,25 +408,35 @@ Zone.prototype.delete = function(options, callback) { common.ServiceObject.prototype.delete.call(this, callback); }; +/** + * @typedef {array} ZoneDeleteRecordsResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback ZoneDeleteRecordsCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Delete records from this zone. This is a convenience wrapper around - * {module:dns/zone#createChange}. + * {@link Zone#createChange}. * - * This method accepts {module:dns/record} objects or string record types in + * This method accepts {@link Record} objects or string record types in * its place. This means that you can delete all A records or NS records, etc. * If used this way, two API requests are made (one to get, then another to - * delete), which means the operation is not atomic and could - * result in unexpected changes. + * delete), which means **the operation is not atomic** and could result in + * unexpected changes. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {module:dns/record|module:dns/record[]|string} record - If given a - * string, it is interpreted as a record type. All records that match that - * type will be retrieved and then deleted. You can also provide a - * {module:dns/record} object or array of objects. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {Record|Record[]|string} record If given a string, it is interpreted + * as a record type. All records that match that type will be retrieved and + * then deleted. You can also provide a {@link Record} object or array of + * {@link Record} objects. + * @param {ZoneDeleteRecordsCallback} [callback] Callback function. + * @returns {Promise} * * @example * var oldARecord = zone.record('a', { @@ -413,23 +500,35 @@ Zone.prototype.deleteRecords = function(records, callback) { return; } - this.createChange({ - delete: records - }, callback); + this.createChange( + { + delete: records, + }, + callback + ); }; +/** + * @typedef {array} ZoneEmptyResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback ZoneEmptyCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Emptying your zone means leaving only 'NS' and 'SOA' records. This method * will first fetch the non-NS and non-SOA records from your zone using - * {module:dns/zone#getRecords}, then use {module:dns/zone#createChange} to + * {@link Zone#getRecords}, then use {@link Zone#createChange} to * create a deletion change. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {object} callback.apiResponse - Raw API response. + * @param {ZoneEmptyCallback} [callback] Callback function. + * @returns {Promise} */ Zone.prototype.empty = function(callback) { var self = this; @@ -452,14 +551,23 @@ Zone.prototype.empty = function(callback) { }); }; +/** + * @typedef {array} ZoneExportResponse + * @property {object} 0 The full API response. + */ +/** + * @callback ZoneExportCallback + * @param {?Error} err Request error, if any. + * @param {object} apiResponse The full API response. + */ /** * Provide a path to a zone file to copy records into the zone. * - * @resource [ResourceRecordSets: list API Documentation]{@link https://cloud.google.com/dns/api/v1/resourceRecordSets/list} + * @see [ResourceRecordSets: list API Documentation]{@link https://cloud.google.com/dns/api/v1/resourceRecordSets/list} * - * @param {string} localPath - The fully qualified path to the zone file. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API or file system error. + * @param {string} localPath The fully qualified path to the zone file. + * @param {ZoneExportCallback} [callback] Callback function. + * @returns {Promise} * * @example * var zoneFilename = '/Users/stephen/zonefile.zone'; @@ -490,25 +598,39 @@ Zone.prototype.export = function(localPath, callback) { }); }; +/** + * Query object for listing changes. + * + * @typedef {object} GetChangesRequest + * @property {boolean} [autoPaginate=true] Have pagination handled automatically. + * @property {number} [maxApiCalls] Maximum number of API calls to make. + * @property {number} [maxResults] Maximum number of items plus prefixes to + * return. + * @property {string} [pageToken] A previously-returned page token + * representing part of the larger set of results to view. + * @property {string} [sort] Set to 'asc' for ascending, and 'desc' for + * descending or omit for no sorting. + */ +/** + * @typedef {array} GetChangesResponse + * @property {Change[]} 0 Array of {@link Change} instances. + * @property {object} 1 The full API response. + */ +/** + * @callback GetChangesCallback + * @param {?Error} err Request error, if any. + * @param {Change[]} changes Array of {@link Change} instances. + * @param {object} apiResponse The full API response. + */ /** * Get the list of changes associated with this zone. A change is an atomic * update to a collection of records. * - * @resource [Changes: get API Documentation]{@link https://cloud.google.com/dns/api/v1/changes/get} + * @see [Changes: get API Documentation]{@link https://cloud.google.com/dns/api/v1/changes/get} * - * @param {object=} query - The query object. - * @param {boolean} query.autoPaginate - Have pagination handled automatically. - * Default: true. - * @param {number} query.maxApiCalls - Maximum number of API calls to make. - * @param {number} query.maxResults - Maximum number of results to return. - * @param {string} query.pageToken - The page token. - * @param {string} query.sort - Set to 'asc' for ascending, and 'desc' for - * descending or omit for no sorting. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change[]} callback.changes - An array of - * {module:dns/change} objects. - * @param {object} callback.apiResponse - Raw API response. + * @param {GetChangesRequest} [query] Query object for listing changes. + * @param {GetChangesCallback} [callback] Callback function. + * @returns {Promise} * * @example * var callback = function(err, changes, nextQuery, apiResponse) { @@ -548,39 +670,43 @@ Zone.prototype.getChanges = function(query, callback) { delete query.sort; } - this.request({ - uri: '/changes', - qs: query - }, function(err, resp) { - if (err) { - callback(err, null, null, resp); - return; - } + this.request( + { + uri: '/changes', + qs: query, + }, + function(err, resp) { + if (err) { + callback(err, null, null, resp); + return; + } + + var changes = (resp.changes || []).map(function(change) { + var changeInstance = self.change(change.id); + changeInstance.metadata = change; + return changeInstance; + }); - var changes = (resp.changes || []).map(function(change) { - var changeInstance = self.change(change.id); - changeInstance.metadata = change; - return changeInstance; - }); + var nextQuery = null; + if (resp.nextPageToken) { + nextQuery = extend({}, query, { + pageToken: resp.nextPageToken, + }); + } - var nextQuery = null; - if (resp.nextPageToken) { - nextQuery = extend({}, query, { - pageToken: resp.nextPageToken - }); + callback(null, changes, nextQuery, resp); } - - callback(null, changes, nextQuery, resp); - }); + ); }; /** - * Get the list of {module:dns/change} objects associated with this zone as a + * Get the list of {@link Change} objects associated with this zone as a * readable object stream. * - * @param {object=} query - Configuration object. See - * {module:dns/zone#getChanges} for a complete list of options. - * @return {stream} + * @method Zone#getChangesStream + * @param {GetChangesRequest} [query] Query object for listing changes. + * @returns {ReadableStream} A readable stream that emits {@link Change} + * instances. * * @example * zone.getChangesStream() @@ -603,26 +729,40 @@ Zone.prototype.getChanges = function(query, callback) { */ Zone.prototype.getChangesStream = common.paginator.streamify('getChanges'); +/** + * Query object for listing records. + * + * @typedef {object} GetRecordsRequest + * @property {boolean} [autoPaginate=true] Have pagination handled automatically. + * @property {number} [maxApiCalls] Maximum number of API calls to make. + * @property {number} [maxResults] Maximum number of items plus prefixes to + * return. + * @property {string} [name] Restricts the list to return only records with this + * fully qualified domain name. + * @property {string} [pageToken] A previously-returned page token + * representing part of the larger set of results to view. + * @property {string} [type] Restricts the list to return only records of this + * type. If present, the "name" parameter must also be present. + */ +/** + * @typedef {array} GetRecordsResponse + * @property {Record[]} 0 Array of {@link Record} instances. + * @property {object} 1 The full API response. + */ +/** + * @callback GetRecordsCallback + * @param {?Error} err Request error, if any. + * @param {Record[]} records Array of {@link Record} instances. + * @param {object} apiResponse The full API response. + */ /** * Get the list of records for this zone. * - * @resource [ResourceRecordSets: list API Documentation]{@link https://cloud.google.com/dns/api/v1/resourceRecordSets/list} - * - * @param {object=} query - The query object. - * @param {boolean} query.autoPaginate - Have pagination handled automatically. - * Default: true. - * @param {number} query.maxApiCalls - Maximum number of API calls to make. - * @param {number} query.maxResults - Maximum number of results to be returned. - * @param {string} query.name - Restricts the list to return only records with - * this fully qualified domain name. - * @param {string} query.pageToken - The page token. - * @param {string} query.type - Restricts the list to return only records of - * this type. If present, the "name" parameter must also be present. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/record[]} callback.records - An array of - * {module:dns/record} objects. - * @param {object} callback.apiResponse - Raw API response. + * @see [ResourceRecordSets: list API Documentation]{@link https://cloud.google.com/dns/api/v1/resourceRecordSets/list} + * + * @param {GetRecordsRequest} [query] Query object for listing records. + * @param {GetRecordsCallback} [callback] Callback function. + * @returns {Promise} * * @example * var callback = function(err, records, nextQuery, apiResponse) { @@ -692,50 +832,54 @@ Zone.prototype.getRecords = function(query, callback) { }); query = { - filterByTypes_: filterByTypes_ + filterByTypes_: filterByTypes_, }; } var requestQuery = extend({}, query); delete requestQuery.filterByTypes_; - this.request({ - uri: '/rrsets', - qs: requestQuery - }, function(err, resp) { - if (err) { - callback(err, null, null, resp); - return; - } + this.request( + { + uri: '/rrsets', + qs: requestQuery, + }, + function(err, resp) { + if (err) { + callback(err, null, null, resp); + return; + } + + var records = (resp.rrsets || []).map(function(record) { + return self.record(record.type, record); + }); - var records = (resp.rrsets || []).map(function(record) { - return self.record(record.type, record); - }); + if (query.filterByTypes_) { + records = records.filter(function(record) { + return query.filterByTypes_[record.type]; + }); + } - if (query.filterByTypes_) { - records = records.filter(function(record) { - return query.filterByTypes_[record.type]; - }); - } + var nextQuery = null; + if (resp.nextPageToken) { + nextQuery = extend({}, query, { + pageToken: resp.nextPageToken, + }); + } - var nextQuery = null; - if (resp.nextPageToken) { - nextQuery = extend({}, query, { - pageToken: resp.nextPageToken - }); + callback(null, records, nextQuery, resp); } - - callback(null, records, nextQuery, resp); - }); + ); }; /** * Get the list of {module:dns/record} objects for this zone as a readable * object stream. * - * @param {object=} query - Configuration object. See - * {module:dns/zone#getRecords} for a complete list of options. - * @return {stream} + * @method Zone#getRecordsStream + * @param {GetRecordsRequest} [query] Query object for listing records. + * @returns {ReadableStream} A readable stream that emits {@link Record} + * instances. * * @example * zone.getRecordsStream() @@ -758,17 +902,25 @@ Zone.prototype.getRecords = function(query, callback) { */ Zone.prototype.getRecordsStream = common.paginator.streamify('getRecords'); +/** + * @typedef {array} ZoneImportResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback ZoneImportCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Copy the records from a zone file into this zone. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} - * - * @param {string} localPath - The fully qualified path to the zone file. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API or file system error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {?object} callback.apiResponse - Raw API response. + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * + * @param {string} localPath The fully qualified path to the zone file. + * @param {ZoneImportCallback} [callback] Callback function. + * @returns {Promise} * @example * var zoneFilename = '/Users/dave/zonefile.zone'; * @@ -812,24 +964,24 @@ Zone.prototype.import = function(localPath, callback) { }; /** - * A {module:dns/record} object can be used to construct a record you want to + * A {@link Record} object can be used to construct a record you want to * add to your zone, or to refer to an existing one. * * Note that using this method will not itself make any API requests. You will * use the object returned in other API calls, for example to add a record to * your zone or to delete an existing one. * - * @param {string} type - The type of record to construct or the type of record + * @param {string} type The type of record to construct or the type of record * you are referencing. - * @param {object} metadata - The metadata of this record. - * @param {string} metadata.name - The name of the record, e.g. + * @param {object} metadata The metadata of this record. + * @param {string} metadata.name The name of the record, e.g. * `www.example.com.`. - * @param {string[]} metadata.data - Defined in + * @param {string[]} metadata.data Defined in * [RFC 1035, section 5](https://goo.gl/9EiM0e) and * [RFC 1034, section 3.6.1](https://goo.gl/Hwhsu9). - * @param {number} metadata.ttl - Seconds that the resource is cached by + * @param {number} metadata.ttl Seconds that the resource is cached by * resolvers. - * @return {module:dns/record} + * @returns {Record} * * @example * //- @@ -862,23 +1014,31 @@ Zone.prototype.record = function(type, metadata) { return new Record(this, type, metadata); }; +/** + * @typedef {array} ZoneReplaceRecordsResponse + * @property {Change} 0 A {@link Change} object. + * @property {object} 1 The full API response. + */ +/** + * @callback ZoneReplaceRecordsCallback + * @param {?Error} err Request error, if any. + * @param {?Change} change A {@link Change} object. + * @param {object} apiResponse The full API response. + */ /** * Provide a record type that should be deleted and replaced with other records. * - * This is not an atomic request. Two API requests are made + * **This is not an atomic request.** Two API requests are made * (one to get records of the type that you've requested, then another to * replace them), which means the operation is not atomic and could result in * unexpected changes. * - * @resource [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} + * @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create} * - * @param {string|string[]} recordTypes - Type(s) of records to replace. - * @param {module:dns/record|module:dns/record[]} newRecords - The record - * objects to add. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {?object} callback.apiResponse - Raw API response. + * @param {string|string[]} recordTypes The type(s) of records to replace. + * @param {Record|Record[]} newRecords The {@link Record} object(s) to add. + * @param {ZoneReplaceRecordsCallback} [callback] Callback function. + * @returns {Promise} * * @example * var newNs1Record = zone.record('ns', { @@ -921,10 +1081,13 @@ Zone.prototype.replaceRecords = function(recordType, newRecords, callback) { return; } - self.createChange({ - add: newRecords, - delete: recordsToDelete - }, callback); + self.createChange( + { + add: newRecords, + delete: recordsToDelete, + }, + callback + ); }); }; @@ -933,11 +1096,8 @@ Zone.prototype.replaceRecords = function(recordType, newRecords, callback) { * * @private * - * @param {string[]} recordTypes - Types of records to delete. Ex: 'NS', 'A'. - * @param {function} callback - The callback function. - * @param {?error} callback.err - An API error. - * @param {?module:dns/change} callback.change - A {module:dns/change} object. - * @param {?object} callback.apiResponse - Raw API response. + * @param {string[]} recordTypes Types of records to delete. Ex: 'NS', 'A'. + * @param {function} callback Callback function. * * @example * zone.deleteRecordsByType_(['NS', 'A'], function(err, change, apiResponse) { @@ -976,7 +1136,12 @@ common.paginator.extend(Zone, ['getChanges', 'getRecords']); * that a callback is omitted. */ common.util.promisifyAll(Zone, { - exclude: ['change', 'record'] + exclude: ['change', 'record'], }); +/** + * Reference to the {@link Zone} class. + * @name module:@google-cloud/dns.Zone + * @see Zone + */ module.exports = Zone; diff --git a/packages/google-cloud-dns/system-test/.eslintrc.yml b/packages/google-cloud-dns/system-test/.eslintrc.yml new file mode 100644 index 00000000000..2e6882e46d2 --- /dev/null +++ b/packages/google-cloud-dns/system-test/.eslintrc.yml @@ -0,0 +1,6 @@ +--- +env: + mocha: true +rules: + node/no-unpublished-require: off + no-console: off diff --git a/packages/google-cloud-dns/system-test/dns.js b/packages/google-cloud-dns/system-test/dns.js index 4aeab6214d0..34aa84c3008 100644 --- a/packages/google-cloud-dns/system-test/dns.js +++ b/packages/google-cloud-dns/system-test/dns.js @@ -25,9 +25,8 @@ var tmp = require('tmp'); var uuid = require('uuid'); var DNS = require('../'); -var env = require('../../../system-test/env.js'); -var dns = new DNS(env); +var dns = new DNS(); var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; // Only run the tests if there is a domain to test with. @@ -44,49 +43,46 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; a: ZONE.record('a', { ttl: 86400, name: DNS_DOMAIN, - data: '1.2.3.4' + data: '1.2.3.4', }), aaaa: ZONE.record('aaaa', { ttl: 86400, name: DNS_DOMAIN, - data: '2607:f8b0:400a:801::1005' + data: '2607:f8b0:400a:801::1005', }), cname: ZONE.record('cname', { ttl: 86400, name: 'mail.' + DNS_DOMAIN, - data: 'example.com.' + data: 'example.com.', }), mx: ZONE.record('mx', { ttl: 86400, name: DNS_DOMAIN, - data: [ - '10 mail.' + DNS_DOMAIN, - '20 mail2.' + DNS_DOMAIN - ] + data: ['10 mail.' + DNS_DOMAIN, '20 mail2.' + DNS_DOMAIN], }), naptr: ZONE.record('naptr', { ttl: 300, name: '2.1.2.1.5.5.5.0.7.7.1.e164.arpa.', data: [ - '100 10 \"u\" \"sip+E2U\" \"!^.*$!sip:information@foo.se!i\" .', - '102 10 \"u\" \"smtp+E2U\" \"!^.*$!mailto:information@foo.se!i\" .' - ] + '100 10 "u" "sip+E2U" "!^.*$!sip:information@foo.se!i" .', + '102 10 "u" "smtp+E2U" "!^.*$!mailto:information@foo.se!i" .', + ], }), ns: ZONE.record('ns', { ttl: 86400, name: DNS_DOMAIN, - data: 'ns-cloud1.googledomains.com.' + data: 'ns-cloud1.googledomains.com.', }), ptr: ZONE.record('ptr', { ttl: 60, name: '2.1.0.10.in-addr.arpa.', - data: 'server.' + DNS_DOMAIN + data: 'server.' + DNS_DOMAIN, }), soa: ZONE.record('soa', { @@ -95,27 +91,27 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; data: [ 'ns-cloud1.googledomains.com.', 'dns-admin.google.com.', - '1 21600 3600 1209600 300' - ].join(' ') + '1 21600 3600 1209600 300', + ].join(' '), }), spf: ZONE.record('spf', { ttl: 21600, name: DNS_DOMAIN, - data: 'v=spf1 mx:' + DNS_DOMAIN.replace(/.$/, '') + ' -all' + data: 'v=spf1 mx:' + DNS_DOMAIN.replace(/.$/, '') + ' -all', }), srv: ZONE.record('srv', { ttl: 21600, name: 'sip.' + DNS_DOMAIN, - data: '0 5 5060 sip.' + DNS_DOMAIN + data: '0 5 5060 sip.' + DNS_DOMAIN, }), txt: ZONE.record('txt', { ttl: 21600, name: DNS_DOMAIN, - data: 'google-site-verification=xxxxxxxxxxxxYYYYYYXXX' - }) + data: 'google-site-verification=xxxxxxxxxxxxYYYYYYXXX', + }), }; before(function(done) { @@ -125,19 +121,19 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; return; } - async.each(zones, exec('delete', { force: true }), function(err) { + async.each(zones, exec('delete', {force: true}), function(err) { if (err) { done(err); return; } - ZONE.create({ dnsName: DNS_DOMAIN }, done); + ZONE.create({dnsName: DNS_DOMAIN}, done); }); }); }); after(function(done) { - ZONE.delete({ force: true }, done); + ZONE.delete({force: true}, done); }); it('should return 0 or more zones', function(done) { @@ -169,7 +165,7 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; records.soa, records.spf, records.srv, - records.txt + records.txt, ]; ZONE.replaceRecords(['ns', 'soa'], recordsToCreate, done); @@ -179,7 +175,7 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; var zoneFilename = require.resolve('./data/zonefile.zone'); var zoneFileTemplate = fs.readFileSync(zoneFilename, 'utf-8'); zoneFileTemplate = format(zoneFileTemplate, { - DNS_DOMAIN: DNS_DOMAIN + DNS_DOMAIN: DNS_DOMAIN, }); tmp.setGracefulCleanup(); @@ -227,24 +223,24 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; tmp.file(function tempFileCreated(err, tmpFilename) { assert.ifError(err); - async.series([ - function(next) { - ZONE.empty(next); - }, + async.series( + [ + function(next) { + ZONE.empty(next); + }, - function(next) { - var recordsToCreate = [ - records.spf, - records.srv - ]; + function(next) { + var recordsToCreate = [records.spf, records.srv]; - ZONE.addRecords(recordsToCreate, next); - }, + ZONE.addRecords(recordsToCreate, next); + }, - function(next) { - ZONE.export(tmpFilename, next); - } - ], done); + function(next) { + ZONE.export(tmpFilename, next); + }, + ], + done + ); }); }); @@ -253,12 +249,12 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; var record = ZONE.record('srv', { ttl: 3600, name: DNS_DOMAIN, - data: '10 0 5222 127.0.0.1.' + data: '10 0 5222 127.0.0.1.', }); var change = ZONE.change(); - change.create({ add: record }, function(err) { + change.create({add: record}, function(err) { assert.ifError(err); var addition = change.metadata.additions[0]; @@ -312,13 +308,13 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; ZONE.record('cname', { ttl: 86400, name: '1.' + DNS_DOMAIN, - data: DNS_DOMAIN + data: DNS_DOMAIN, }), ZONE.record('cname', { ttl: 86400, name: '2.' + DNS_DOMAIN, - data: DNS_DOMAIN - }) + data: DNS_DOMAIN, + }), ]; ZONE.replaceRecords('cname', newRecords, function(err) { @@ -333,10 +329,13 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; ZONE.deleteRecords(newRecords, done); } - ZONE.getRecords({ - types: 'cname', - maxResults: 2 - }, onRecordsReceived); + ZONE.getRecords( + { + types: 'cname', + maxResults: 2, + }, + onRecordsReceived + ); }); }); @@ -344,7 +343,7 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; var name = 'test-zone-' + uuid.v4().substr(0, 18); // Do this in a new zone so no existing records are affected. - dns.createZone(name, { dnsName: DNS_DOMAIN }, function(err, zone) { + dns.createZone(name, {dnsName: DNS_DOMAIN}, function(err, zone) { assert.ifError(err); zone.getRecords('ns', function(err, originalRecords) { @@ -355,7 +354,7 @@ var DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN; var newRecord = zone.record('ns', { ttl: 3600, name: DNS_DOMAIN, - data: ['ns1.nameserver.net.', 'ns2.nameserver.net.'] + data: ['ns1.nameserver.net.', 'ns2.nameserver.net.'], }); zone.replaceRecords('ns', newRecord, function(err, change) { diff --git a/packages/google-cloud-dns/test/.eslintrc.yml b/packages/google-cloud-dns/test/.eslintrc.yml new file mode 100644 index 00000000000..73f7bbc946f --- /dev/null +++ b/packages/google-cloud-dns/test/.eslintrc.yml @@ -0,0 +1,5 @@ +--- +env: + mocha: true +rules: + node/no-unpublished-require: off diff --git a/packages/google-cloud-dns/test/change.js b/packages/google-cloud-dns/test/change.js index 8dd02417852..3ba697dce54 100644 --- a/packages/google-cloud-dns/test/change.js +++ b/packages/google-cloud-dns/test/change.js @@ -29,7 +29,7 @@ var fakeUtil = extend({}, util, { if (Class.name === 'Change') { promisified = true; } - } + }, }); function FakeServiceObject() { @@ -45,7 +45,7 @@ describe('Change', function() { var ZONE = { name: 'zone-name', - createChange: util.noop + createChange: util.noop, }; var CHANGE_ID = 'change-id'; @@ -54,8 +54,8 @@ describe('Change', function() { Change = proxyquire('../src/change.js', { '@google-cloud/common': { ServiceObject: FakeServiceObject, - util: fakeUtil - } + util: fakeUtil, + }, }); }); @@ -75,7 +75,7 @@ describe('Change', function() { assert.deepEqual(calledWith.methods, { exists: true, get: true, - getMetadata: true + getMetadata: true, }); }); @@ -120,7 +120,7 @@ describe('Change', function() { describe('success', function() { var changeInstance = { id: 'id', - metadata: {} + metadata: {}, }; var apiResponse = {}; diff --git a/packages/google-cloud-dns/test/index.js b/packages/google-cloud-dns/test/index.js index 938535492b4..13d75c6153b 100644 --- a/packages/google-cloud-dns/test/index.js +++ b/packages/google-cloud-dns/test/index.js @@ -38,7 +38,7 @@ var fakePaginator = { }, streamify: function(methodName) { return methodName; - } + }, }; function FakeService() { @@ -58,7 +58,7 @@ var fakeUtil = extend({}, util, { promisified = true; assert.deepEqual(options.exclude, ['zone']); - } + }, }); function FakeZone() { @@ -76,15 +76,15 @@ describe('DNS', function() { '@google-cloud/common': { Service: FakeService, paginator: fakePaginator, - util: fakeUtil + util: fakeUtil, }, - './zone.js': FakeZone + './zone.js': FakeZone, }); }); beforeEach(function() { dns = new DNS({ - projectId: PROJECT_ID + projectId: PROJECT_ID, }); }); @@ -104,7 +104,7 @@ describe('DNS', function() { it('should normalize the arguments', function() { var normalizeArguments = fakeUtil.normalizeArguments; var normalizeArgumentsCalled = false; - var fakeOptions = { projectId: PROJECT_ID }; + var fakeOptions = {projectId: PROJECT_ID}; var fakeContext = {}; fakeUtil.normalizeArguments = function(context, options) { @@ -129,7 +129,7 @@ describe('DNS', function() { assert.strictEqual(calledWith.baseUrl, baseUrl); assert.deepEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', - 'https://www.googleapis.com/auth/cloud-platform' + 'https://www.googleapis.com/auth/cloud-platform', ]); assert.deepEqual(calledWith.packageJson, require('../package.json')); }); @@ -137,7 +137,7 @@ describe('DNS', function() { describe('createZone', function() { var zoneName = 'zone-name'; - var config = { dnsName: 'dns-name' }; + var config = {dnsName: 'dns-name'}; it('should throw if a zone name is not provided', function() { assert.throws(function() { @@ -156,7 +156,7 @@ describe('DNS', function() { }); it('should use a provided description', function(done) { - var cfg = extend({}, config, { description: 'description' }); + var cfg = extend({}, config, {description: 'description'}); dns.request = function(reqOpts) { assert.strictEqual(reqOpts.json.description, cfg.description); @@ -182,7 +182,7 @@ describe('DNS', function() { var expectedBody = extend({}, config, { name: zoneName, - description: '' + description: '', }); assert.deepEqual(reqOpts.json, expectedBody); @@ -194,7 +194,7 @@ describe('DNS', function() { describe('error', function() { var error = new Error('Error.'); - var apiResponse = { a: 'b', c: 'd' }; + var apiResponse = {a: 'b', c: 'd'}; beforeEach(function() { dns.request = function(reqOpts, callback) { @@ -213,7 +213,7 @@ describe('DNS', function() { }); describe('success', function() { - var apiResponse = { name: zoneName }; + var apiResponse = {name: zoneName}; var zone = {}; beforeEach(function() { @@ -257,7 +257,7 @@ describe('DNS', function() { describe('getZones', function() { it('should make the correct request', function(done) { - var query = { a: 'b', c: 'd' }; + var query = {a: 'b', c: 'd'}; dns.request = function(reqOpts) { assert.strictEqual(reqOpts.uri, '/managedZones'); @@ -280,7 +280,7 @@ describe('DNS', function() { describe('error', function() { var error = new Error('Error.'); - var apiResponse = { a: 'b', c: 'd' }; + var apiResponse = {a: 'b', c: 'd'}; beforeEach(function() { dns.request = function(reqOpts, callback) { @@ -301,8 +301,8 @@ describe('DNS', function() { }); describe('success', function() { - var zone = { name: 'zone-1', a: 'b', c: 'd' }; - var apiResponse = { managedZones: [zone] }; + var zone = {name: 'zone-1', a: 'b', c: 'd'}; + var apiResponse = {managedZones: [zone]}; beforeEach(function() { dns.request = function(reqOpts, callback) { @@ -326,10 +326,10 @@ describe('DNS', function() { it('should set a nextQuery if necessary', function(done) { var apiResponseWithNextPageToken = extend({}, apiResponse, { - nextPageToken: 'next-page-token' + nextPageToken: 'next-page-token', }); - var query = { a: 'b', c: 'd' }; + var query = {a: 'b', c: 'd'}; var originalQuery = extend({}, query); dns.request = function(reqOpts, callback) { @@ -342,9 +342,12 @@ describe('DNS', function() { // Check the original query wasn't modified. assert.deepEqual(query, originalQuery); - assert.deepEqual(nextQuery, extend({}, query, { - pageToken: apiResponseWithNextPageToken.nextPageToken - })); + assert.deepEqual( + nextQuery, + extend({}, query, { + pageToken: apiResponseWithNextPageToken.nextPageToken, + }) + ); done(); }); diff --git a/packages/google-cloud-dns/test/record.js b/packages/google-cloud-dns/test/record.js index 1b80afa4d74..55b514be072 100644 --- a/packages/google-cloud-dns/test/record.js +++ b/packages/google-cloud-dns/test/record.js @@ -30,7 +30,7 @@ var fakeUtil = extend({}, util, { promisified = true; assert.deepEqual(options.exclude, ['toJSON', 'toString']); - } + }, }); describe('Record', function() { @@ -38,20 +38,20 @@ describe('Record', function() { var record; var ZONE = { - deleteRecords: util.noop + deleteRecords: util.noop, }; var TYPE = 'A'; var METADATA = { name: 'name', data: [], - ttl: 86400 + ttl: 86400, }; before(function() { Record = proxyquire('../src/record.js', { '@google-cloud/common': { - util: fakeUtil - } + util: fakeUtil, + }, }); }); @@ -89,7 +89,7 @@ describe('Record', function() { var originalRrdatas = []; var recordThatHadRrdatas = new Record(ZONE, TYPE, { - rrdatas: originalRrdatas + rrdatas: originalRrdatas, }); assert.strictEqual(recordThatHadRrdatas.rrdatas, undefined); @@ -102,7 +102,7 @@ describe('Record', function() { var aRecord = { ip: '0.0.0.0', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = aRecord.ip; @@ -121,7 +121,7 @@ describe('Record', function() { var aaaaRecord = { ip: '2607:f8b0:400a:801::1005', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = aaaaRecord.ip; @@ -140,7 +140,7 @@ describe('Record', function() { var cnameRecord = { alias: 'example.com.', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = cnameRecord.alias; @@ -160,7 +160,7 @@ describe('Record', function() { preference: 0, host: 'mail', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = mxRecord.preference + ' ' + mxRecord.host; @@ -179,7 +179,7 @@ describe('Record', function() { var nsRecord = { host: 'example.com', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = nsRecord.host; @@ -204,7 +204,7 @@ describe('Record', function() { expire: 604800, minimum: 86400, name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = [ @@ -214,7 +214,7 @@ describe('Record', function() { soaRecord.retry, soaRecord.refresh, soaRecord.expire, - soaRecord.minimum + soaRecord.minimum, ].join(' '); it('should parse an SOA record', function() { @@ -231,7 +231,7 @@ describe('Record', function() { var spfRecord = { data: '"v=spf1" "mx:example.com"', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = spfRecord.data; @@ -253,14 +253,14 @@ describe('Record', function() { port: 5222, target: 'jabber', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = [ srvRecord.priority, srvRecord.weight, srvRecord.port, - srvRecord.target + srvRecord.target, ].join(' '); it('should parse an SRV record', function() { @@ -277,7 +277,7 @@ describe('Record', function() { var txtRecord = { txt: 'txt-record-txt', name: 'name', - ttl: 86400 + ttl: 86400, }; var expectedData = txtRecord.txt; @@ -308,7 +308,7 @@ describe('Record', function() { it('should format the data for the API', function() { var expectedRecord = extend({}, METADATA, { type: 'A', - rrdatas: METADATA.data + rrdatas: METADATA.data, }); delete expectedRecord.data; @@ -320,7 +320,7 @@ describe('Record', function() { it('should format the data for a zonefile', function() { var jsonRecord = extend({}, METADATA, { type: TYPE, - rrdatas: ['example.com.', 'example2.com.'] + rrdatas: ['example.com.', 'example2.com.'], }); record.toJSON = function() { @@ -333,7 +333,7 @@ describe('Record', function() { jsonRecord.ttl, 'IN', TYPE, - jsonRecord.rrdatas[0] + jsonRecord.rrdatas[0], ].join(' '), [ @@ -341,8 +341,8 @@ describe('Record', function() { jsonRecord.ttl, 'IN', TYPE, - jsonRecord.rrdatas[1] - ].join(' ') + jsonRecord.rrdatas[1], + ].join(' '), ].join('\n'); // That's a bunch of silliness, but it generates simply: diff --git a/packages/google-cloud-dns/test/zone.js b/packages/google-cloud-dns/test/zone.js index 195fd5e5e2e..7a95ec3b2e2 100644 --- a/packages/google-cloud-dns/test/zone.js +++ b/packages/google-cloud-dns/test/zone.js @@ -33,14 +33,14 @@ var fakeUtil = extend({}, util, { promisified = true; assert.deepEqual(options.exclude, ['change', 'record']); - } + }, }); var parseOverride; var fakeDnsZonefile = { parse: function() { return (parseOverride || util.noop).apply(null, arguments); - } + }, }; var writeFileOverride; @@ -51,7 +51,7 @@ var fakeFs = { }, writeFile: function() { return (writeFileOverride || util.noop).apply(null, arguments); - } + }, }; function FakeChange() { @@ -88,7 +88,7 @@ var fakePaginator = { }, streamify: function(methodName) { return methodName; - } + }, }; describe('Zone', function() { @@ -96,7 +96,7 @@ describe('Zone', function() { var zone; var DNS = { - createZone: util.noop + createZone: util.noop, }; var ZONE_NAME = 'zone-name'; @@ -107,10 +107,10 @@ describe('Zone', function() { '@google-cloud/common': { ServiceObject: FakeServiceObject, paginator: fakePaginator, - util: fakeUtil + util: fakeUtil, }, './change.js': FakeChange, - './record.js': FakeRecord + './record.js': FakeRecord, }); }); @@ -145,8 +145,8 @@ describe('Zone', function() { bind: function(context) { assert.strictEqual(context, dnsInstance); done(); - } - } + }, + }, }); var zone = new Zone(dnsInstance, ZONE_NAME); @@ -161,7 +161,7 @@ describe('Zone', function() { create: true, exists: true, get: true, - getMetadata: true + getMetadata: true, }); }); }); @@ -200,8 +200,16 @@ describe('Zone', function() { it('should parse and rename add to additions', function(done) { var recordsToAdd = [ - { toJSON: function() { return 'a'; } }, - { toJSON: function() { return 'a'; } } + { + toJSON: function() { + return 'a'; + }, + }, + { + toJSON: function() { + return 'a'; + }, + }, ]; var expectedAdditions = ['a', 'a']; @@ -211,13 +219,21 @@ describe('Zone', function() { done(); }; - zone.createChange({ add: recordsToAdd }, assert.ifError); + zone.createChange({add: recordsToAdd}, assert.ifError); }); it('should parse and rename delete to deletions', function(done) { var recordsToDelete = [ - { toJSON: function() { return 'a'; } }, - { toJSON: function() { return 'a'; } } + { + toJSON: function() { + return 'a'; + }, + }, + { + toJSON: function() { + return 'a'; + }, + }, ]; var expectedDeletions = ['a', 'a']; @@ -227,7 +243,7 @@ describe('Zone', function() { done(); }; - zone.createChange({ delete: recordsToDelete }, assert.ifError); + zone.createChange({delete: recordsToDelete}, assert.ifError); }); it('should make correct API request', function(done) { @@ -238,12 +254,12 @@ describe('Zone', function() { done(); }; - zone.createChange({ add: [] }, assert.ifError); + zone.createChange({add: []}, assert.ifError); }); describe('error', function() { var error = new Error('Error.'); - var apiResponse = { a: 'b', c: 'd' }; + var apiResponse = {a: 'b', c: 'd'}; beforeEach(function() { zone.request = function(reqOpts, callback) { @@ -252,7 +268,7 @@ describe('Zone', function() { }); it('should execute callback with error & API response', function(done) { - zone.createChange({ add: [] }, function(err, change, apiResponse_) { + zone.createChange({add: []}, function(err, change, apiResponse_) { assert.strictEqual(err, error); assert.strictEqual(apiResponse_, apiResponse); done(); @@ -261,7 +277,7 @@ describe('Zone', function() { }); describe('success', function() { - var apiResponse = { id: 1, a: 'b', c: 'd' }; + var apiResponse = {id: 1, a: 'b', c: 'd'}; beforeEach(function() { zone.request = function(reqOpts, callback) { @@ -277,7 +293,7 @@ describe('Zone', function() { return change; }; - zone.createChange({ add: [] }, function(err, change_, apiResponse_) { + zone.createChange({add: []}, function(err, change_, apiResponse_) { assert.ifError(err); assert.strictEqual(change_, change); @@ -298,7 +314,7 @@ describe('Zone', function() { done(); }; - zone.delete({ force: true }, assert.ifError); + zone.delete({force: true}, assert.ifError); }); it('should try to delete again after emptying', function(done) { @@ -310,7 +326,7 @@ describe('Zone', function() { callback(); }; - zone.delete({ force: true }, assert.ifError); + zone.delete({force: true}, assert.ifError); }); }); @@ -337,7 +353,7 @@ describe('Zone', function() { }); it('should create a change if record objects given', function(done) { - var recordsToDelete = { a: 'b', c: 'd' }; + var recordsToDelete = {a: 'b', c: 'd'}; zone.createChange = function(options, callback) { assert.deepEqual(options.delete, [recordsToDelete]); @@ -376,17 +392,17 @@ describe('Zone', function() { describe('success', function() { var records = [ - { type: 'A' }, - { type: 'AAAA' }, - { type: 'CNAME' }, - { type: 'MX' }, - { type: 'NAPTR' }, - { type: 'NS' }, - { type: 'PTR' }, - { type: 'SOA' }, - { type: 'SPF' }, - { type: 'SRV' }, - { type: 'TXT' } + {type: 'A'}, + {type: 'AAAA'}, + {type: 'CNAME'}, + {type: 'MX'}, + {type: 'NAPTR'}, + {type: 'NS'}, + {type: 'PTR'}, + {type: 'SOA'}, + {type: 'SPF'}, + {type: 'SRV'}, + {type: 'TXT'}, ]; var expectedRecordsToDelete = records.filter(function(record) { @@ -422,10 +438,26 @@ describe('Zone', function() { var path = './zonefile'; var records = [ - { toString: function() { return 'a'; } }, - { toString: function() { return 'a'; } }, - { toString: function() { return 'a'; } }, - { toString: function() { return 'a'; } }, + { + toString: function() { + return 'a'; + }, + }, + { + toString: function() { + return 'a'; + }, + }, + { + toString: function() { + return 'a'; + }, + }, + { + toString: function() { + return 'a'; + }, + }, ]; var expectedZonefileContents = 'a\na\na\na'; @@ -521,7 +553,7 @@ describe('Zone', function() { }); it('should accept a sort', function(done) { - var query = { sort: 'desc' }; + var query = {sort: 'desc'}; zone.request = function(reqOpts) { assert.strictEqual(reqOpts.qs.sortOrder, 'descending'); @@ -534,7 +566,7 @@ describe('Zone', function() { }); it('should make the correct API request', function(done) { - var query = { a: 'b', c: 'd' }; + var query = {a: 'b', c: 'd'}; zone.request = function(reqOpts) { assert.strictEqual(reqOpts.uri, '/changes'); @@ -548,7 +580,7 @@ describe('Zone', function() { describe('error', function() { var error = new Error('Error.'); - var apiResponse = { a: 'b', c: 'd' }; + var apiResponse = {a: 'b', c: 'd'}; beforeEach(function() { zone.request = function(reqOpts, callback) { @@ -567,7 +599,7 @@ describe('Zone', function() { describe('success', function() { var apiResponse = { - changes: [{ id: 1 }] + changes: [{id: 1}], }; beforeEach(function() { @@ -579,10 +611,10 @@ describe('Zone', function() { it('should build a nextQuery if necessary', function(done) { var nextPageToken = 'next-page-token'; var apiResponseWithNextPageToken = extend({}, apiResponse, { - nextPageToken: nextPageToken + nextPageToken: nextPageToken, }); var expectedNextQuery = { - pageToken: nextPageToken + pageToken: nextPageToken, }; zone.request = function(reqOpts, callback) { @@ -623,7 +655,7 @@ describe('Zone', function() { describe('getRecords', function() { describe('error', function() { var error = new Error('Error.'); - var apiResponse = { a: 'b', c: 'd' }; + var apiResponse = {a: 'b', c: 'd'}; beforeEach(function() { zone.request = function(reqOpts, callback) { @@ -649,7 +681,7 @@ describe('Zone', function() { describe('success', function() { var apiResponse = { - rrsets: [{ type: 'NS' }] + rrsets: [{type: 'NS'}], }; beforeEach(function() { @@ -661,9 +693,9 @@ describe('Zone', function() { it('should execute callback with nextQuery if necessary', function(done) { var nextPageToken = 'next-page-token'; var apiResponseWithNextPageToken = extend({}, apiResponse, { - nextPageToken: nextPageToken + nextPageToken: nextPageToken, }); - var expectedNextQuery = { pageToken: nextPageToken }; + var expectedNextQuery = {pageToken: nextPageToken}; zone.request = function(reqOpts, callback) { callback(null, apiResponseWithNextPageToken); @@ -772,7 +804,7 @@ describe('Zone', function() { describe('success', function() { var recordType = 'ns'; var parsedZonefile = {}; - parsedZonefile[recordType] = { a: 'b', c: 'd' }; + parsedZonefile[recordType] = {a: 'b', c: 'd'}; beforeEach(function() { parseOverride = function() { @@ -808,7 +840,7 @@ describe('Zone', function() { describe('record', function() { it('should return a Record object', function() { var type = 'a'; - var metadata = { a: 'b', c: 'd' }; + var metadata = {a: 'b', c: 'd'}; var record = zone.record(type, metadata); @@ -852,15 +884,15 @@ describe('Zone', function() { describe('success', function() { var recordsToCreate = [ - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' } + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, ]; var recordsToDelete = [ - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' } + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, ]; beforeEach(function() { @@ -913,9 +945,9 @@ describe('Zone', function() { describe('success', function() { var recordsToDelete = [ - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' }, - { a: 'b', c: 'd' } + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, + {a: 'b', c: 'd'}, ]; beforeEach(function() {