├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── funding.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── cmd └── cup │ ├── cup-configure.go │ ├── cup-update.go │ ├── cup-version.go │ ├── cup.go │ └── shared.go ├── docs ├── README.md ├── api-key.md ├── configuration.md ├── img │ └── token_settings.png └── update.md ├── go.mod ├── go.sum └── internal ├── cfutils ├── check-token-active.go └── zone.go ├── commands ├── configure-ui.go ├── configure.go └── update.go ├── config ├── config.go ├── loglevels.go └── loglevels_test.go ├── externalip ├── clients │ ├── clients.go │ └── generic-ip-as-body-svc.go ├── externalip.go └── externalip_test.go ├── types ├── cup-info.go └── external-ip.go └── util ├── file.go ├── retry-timer.go ├── retry-timer_test.go ├── stdin.go ├── stringslice.go ├── stringslice_test.go ├── time.go ├── time_test.go ├── user-agent.go ├── user-agent_test.go ├── user-prompt.go ├── viper.go ├── yaml.go └── yaml_test.go /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are welcome! Please feel free to open a PR or an issue on GitHub. 4 | 5 | Convention for this repository is to fork it, create a branch `feature/` on your fork, and commit changes 6 | there. Once your changes are ready to merge back into this repository, open a PR from your repository's feature branch 7 | into the `main` branch of this repository. Please be sure to rebase onto the main branch before submitting a PR to keep 8 | a clean history. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | **Version** 10 | Please include the version you are experiencing issues with. 11 | 12 | **Describe the bug** 13 | A clear and concise description of what the bug is. 14 | 15 | **To Reproduce** 16 | Steps to reproduce the behavior: 17 | 1. Go to '...' 18 | 2. Click on '....' 19 | 3. Scroll down to '....' 20 | 4. See error 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Screenshots** 26 | If applicable, add screenshots to help explain your problem. 27 | 28 | **Additional context** 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: [viertaxa] 2 | custom: 'https://paypal.me/viertaxa' -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to creating a positive environment 12 | include: 13 | 14 | * Using welcoming and inclusive language 15 | * Being respectful of differing viewpoints and experiences 16 | * Gracefully accepting constructive criticism 17 | * Focusing on what is best for the community 18 | * Showing empathy towards other community members 19 | 20 | Examples of unacceptable behavior by participants include: 21 | 22 | * The use of sexualized language or imagery and unwelcome sexual attention or 23 | advances 24 | * Trolling, insulting/derogatory comments, and personal or political attacks 25 | * Public or private harassment 26 | * Publishing others' private information, such as a physical or electronic 27 | address, without explicit permission 28 | * Other conduct which could reasonably be considered inappropriate in a 29 | professional setting 30 | 31 | ## Our Responsibilities 32 | 33 | Project maintainers are responsible for clarifying the standards of acceptable 34 | behavior and are expected to take appropriate and fair corrective action in 35 | response to any instances of unacceptable behavior. 36 | 37 | Project maintainers have the right and responsibility to remove, edit, or 38 | reject comments, commits, code, wiki edits, issues, and other contributions 39 | that are not aligned to this Code of Conduct, or to ban temporarily or 40 | permanently any contributor for other behaviors that they deem inappropriate, 41 | threatening, offensive, or harmful. 42 | 43 | ## Scope 44 | 45 | This Code of Conduct applies both within project spaces and in public spaces 46 | when an individual is representing the project or its community. Examples of 47 | representing a project or community include using an official project e-mail 48 | address, posting via an official social media account, or acting as an appointed 49 | representative at an online or offline event. Representation of a project may be 50 | further defined and clarified by project maintainers. 51 | 52 | ## Enforcement 53 | 54 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 55 | reported by contacting the project team at conduct@viertaxa.com. All 56 | complaints will be reviewed and investigated and will result in a response that 57 | is deemed necessary and appropriate to the circumstances. The project team is 58 | obligated to maintain confidentiality with regard to the reporter of an incident. 59 | Further details of specific enforcement policies may be posted separately. 60 | 61 | Project maintainers who do not follow or enforce the Code of Conduct in good 62 | faith may face temporary or permanent repercussions as determined by other 63 | members of the project's leadership. 64 | 65 | ## Attribution 66 | 67 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 68 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 69 | 70 | [homepage]: https://www.contributor-covenant.org 71 | 72 | For answers to common questions about this code of conduct, see 73 | https://www.contributor-covenant.org/faq 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CUP 2 | 3 | The **C**loudflare (DNS) **Up**dater 4 | 5 | CUP is a tool to turn CloudFlare DNS into a Dynamic DNS service. 6 | 7 | # Documentation 8 | 9 | Documentation can be found in the [docs folder](docs/README.md). 10 | 11 | # Contributing 12 | 13 | Contributions are welcome! Please feel free to open a PR or an issue on GitHub. 14 | 15 | Convention for this repository is to fork it, create a branch `feature/` on your fork, 16 | and commit changes there. Once your changes are ready to merge back into this repository, squash your feature 17 | branch into one commit with a descriptive commit message and open a PR from your repository's feature branch into the 18 | `main` branch of this repository. Please also be sure to make sure your `main` branch is up to date with `main` on this 19 | repo, and rebase your feature onto the tip of `main`. 20 | 21 | ## Special Thanks 22 | 23 | Special thanks goes to the following services, which are used by default by CUP: 24 | - [ipify](https://www.ipify.org/) 25 | - [SeeIP](https://seeip.org/) 26 | - [WhatIsMyIPAddress](https://whatismyipaddress.com/) 27 | 28 | # Sponsoring 29 | 30 | Your sponsorship is appreciated and helps to directly fund further development on projects like this. 31 | 32 | You can sponsor on a recurring basis through GitHub sponsors in the right sidebar, just hit the :heart: icon. 33 | 34 | Alternately, you can do sponsorships through PayPal, Bitcoin, or Ethereum. 35 | 36 | PayPal: [https://paypal.me/viertaxa](https://paypal.me/viertaxa) 37 | 38 | BTC: `bc1qev8rmfmrmxlzdhvp3p76na86gk883c5nxwa9rc` 39 | 40 | ETH: `0xb4a77daDB218cAd59A9cfe02B252282091CbdFA4` 41 | 42 | # License Information 43 | 44 | > Copyright 2021 Taylor Vierrether 45 | > 46 | > This program is free software: you can redistribute it and/or modify 47 | > it under the terms of the GNU General Public License as published by 48 | > the Free Software Foundation, either version 3 of the License, or 49 | > (at your option) any later version. 50 | > 51 | > This program is distributed in the hope that it will be useful, 52 | > but WITHOUT ANY WARRANTY; without even the implied warranty of 53 | > MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 54 | > GNU General Public License for more details. 55 | > 56 | > A full copy of the GNU GPL v3 license is provided within the LICENSE file at the root of the repository. 57 | 58 | ## Additional Disclaimer 59 | 60 | I have no association with Cloudflare, other than being a happy free-tier customer for many years. 61 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | To report a security vulnerability, please **do not** open an issue. Instead, please email security_reports@viertaxa.com with a subject beginning with `[SECURITY REPORT]`. All other emails are subject to be ignored. 6 | -------------------------------------------------------------------------------- /cmd/cup/cup-configure.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/spf13/cobra" 23 | "github.com/spf13/viper" 24 | "github.com/viertaxa/cup/internal/commands" 25 | "github.com/viertaxa/cup/internal/config" 26 | "github.com/viertaxa/cup/internal/util" 27 | "os" 28 | ) 29 | 30 | // Define the `configure` command. It's used to generate or update the configuration file. 31 | var configureCmd = &cobra.Command{ 32 | Use: "configure [domain]", 33 | Short: "Configure CUP.", 34 | Long: "Configure CUP with Cloudflare credentials and tell it what hosts on what domains should be updated to the " + 35 | "current public IP.", 36 | Run: executeConfigure, 37 | // Enable flags from the root command 38 | TraverseChildren: true, 39 | } 40 | 41 | // Register the subcommand on the root command 42 | func init() { 43 | rootCmd.AddCommand(configureCmd) 44 | } 45 | 46 | // Update or Create the configuration 47 | func executeConfigure(_ *cobra.Command, _ []string) { 48 | // Check if we're interactive, exit if not. Configure is only supported interactively. 49 | isStdIn, err := util.CheckIsStdin() 50 | if err != nil { 51 | // There was an error checking if we're interactive, but we'll continue in case there's some weird terminal that 52 | // is interactive but doesn't act like it. 53 | log.Errorf("Determining if we're in an interactive shell failed. Assuming interactive\nError: %s", err) 54 | } 55 | if !isStdIn { 56 | log.Fatal("We only support running the configure command in an interactive session.") 57 | } 58 | // Attempt to read in an existing config. If one is not found at the specified path, create it, otherwise update it. 59 | // The config file was set earlier in execution in the initConfig() function 60 | if err := viper.ReadInConfig(); err != nil { 61 | // There was an error reading the config file, but that error might be that it wasn't there. 62 | // TODO: play around with passing in the config file option and testing these failure catching mechanisms 63 | if _, ok := err.(viper.ConfigFileNotFoundError); ok { 64 | // The error reading the config file was indeed that it wasn't found. 65 | // NOTE: This error only gets returned when we're using the automatic config file locating system of 66 | // viper. If the user passes in a specific file, a general error will be returned. 67 | // We'll set the loglevel now. There's no config file to read from, so we'll just use what the user passed 68 | // in on the command line, or the default value if that was not done. 69 | log.Warnf("No config file found at specified path! Creating a new one.\nError:%s", err) 70 | createConfig() 71 | } else { 72 | // Something went wrong when reading the specified file, or the user passed in a config file that doesn't 73 | // exist yet. 74 | // Let's check to see if the file specified exists. If it doesn't we'll create it. If it does, we'll log a 75 | // fatal error. 76 | exists, err := util.CheckFileExists(config.FilePath) 77 | if err != nil { 78 | log.Fatalf("Error reading configuration file specified.\nError:%s", err) 79 | } else { 80 | if !exists { 81 | log.Warnf("No config file found at specified path! Creating a new one.\nError:%s", err) 82 | createConfig() 83 | } else { 84 | log.Fatalf("Config file found at %s, but we were unable to read it. Has it been hand edited?"+ 85 | "\nError: %s", config.FilePath, err) 86 | } 87 | } 88 | } 89 | } else { 90 | // The configuration was loaded successfully 91 | modifyConfig() 92 | } 93 | // Configuration struct should be up to date now, regardless of if it was there to begin with or not. 94 | 95 | // Actually write the configuration to disk. 96 | log.Infof("Writing configuration file %s to disk.", config.FilePath) 97 | if err := viper.WriteConfigAs(config.FilePath); err != nil { 98 | // Something went wrong writing the configuration file to disk. Prompt to dump the struct in JSON format to the 99 | // terminal in case the user went through a log of effort creating it, and would like to make the file manually. 100 | log.Errorf("Error writing configuration to disk!\nError: %s", err) 101 | dumpConfigIfDesired() 102 | // Wrap things up with a fatal error and exit 103 | log.Fatalf("Exiting.") 104 | } else { 105 | // Updating the config and config file seems to have gone well. We're done now. 106 | log.Infof("Successfully wrote config file to %s", config.FilePath) 107 | // Exit with a success exit code. 108 | os.Exit(0) 109 | } 110 | } 111 | 112 | func dumpConfigIfDesired() { 113 | if shouldDump, err := util.AskUserForBool("Should we dump the config to the shell for you?", 114 | false); err != nil { 115 | // Error prompting if we should dump the config. Defaulting to false for security purposes. 116 | log.Errorf("Error getting your response. We will not dump the config for security reasons."+ 117 | "\nError:%s", err) 118 | } else { 119 | // Got a valid response, act accordingly 120 | if shouldDump { 121 | // User wants a config dump 122 | // Get the YAML 123 | if yaml, err := util.PrettyPrintSYaml(config.C); err != nil { 124 | // Error getting the YAML 125 | log.Errorf("Error when attempting to marshal config to YAML.\nError: %s", err) 126 | } else { 127 | // Got YAML back 128 | log.Printf("\n%s\n", yaml) 129 | } 130 | } 131 | } 132 | } 133 | 134 | func createConfig() { 135 | setLogLevel() 136 | 137 | // Config file was not found at given path, let's create it and warn the user that this is the case. 138 | // Generate the configuration file 139 | if createErr := commands.ConfigurationCreate(); createErr != nil { 140 | // Something went wrong when creating the new configuration struct. Log it and exit. 141 | log.Fatalf("Unable to create configuration.\nError:%s", createErr) 142 | } 143 | // Configuration struct was created successfully 144 | log.Info("Config created successfully.") 145 | } 146 | 147 | func modifyConfig() { 148 | // Config file was found, lets modify it. 149 | 150 | // First we copy the defaults into the config struct. This handles the case where we add new config options in the 151 | // future 152 | config.C = config.GetDefaultCupConfig() 153 | 154 | // Next we unmarshal the configuration loaded from the file into our config struct since we prefer to use that 155 | // over the viper methods to query configuration. 156 | unmarshalErr := viper.Unmarshal(&config.C) 157 | if unmarshalErr != nil { 158 | // There was some sort of error unmarshalling the configuration loaded from the file into our struct. 159 | // This was likely caused by a config file that was missing properties due to hand editing. 160 | log.Fatalf("Unable to unmarshal config. Has it been hand edited?\nError: %s", unmarshalErr) 161 | } 162 | // Now that we have loaded the user's preferences from file, set the log level appropriately. 163 | setLogLevel() 164 | 165 | // Update the configuration struct that we loaded previously 166 | log.Info("Configuration file located. Modifying...") 167 | // Set the actual used configuration file path in our configuration 168 | config.FilePath = viper.ConfigFileUsed() 169 | if err := commands.ConfigurationEdit(); err != nil { 170 | // Something went wrong updating the configuration struct. 171 | log.Fatalf("Error updating configuration file.\nError:%s", err) 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /cmd/cup/cup-update.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/spf13/cobra" 23 | "github.com/spf13/viper" 24 | "github.com/viertaxa/cup/internal/commands" 25 | "github.com/viertaxa/cup/internal/config" 26 | "os" 27 | ) 28 | 29 | // Define the `update` command. It's the `main` command that does the DNS update. 30 | var updateCmd = &cobra.Command{ 31 | Use: "update", 32 | Short: "Update the specified DNS record on Cloudflare", 33 | Long: "Queries several `What is my IP` type services for your public IP, and if there's a quorum, update the " + 34 | "record in Cloudflare.", 35 | Run: executeUpdate, 36 | // Enable flags from the root command 37 | TraverseChildren: true, 38 | } 39 | 40 | // Register the subcommand on the root command 41 | func init() { 42 | rootCmd.AddCommand(updateCmd) 43 | } 44 | 45 | // Attempt to update the DNS record with the current public IP 46 | func executeUpdate(_ *cobra.Command, _ []string) { 47 | // Lets read in the configuration 48 | if err := viper.ReadInConfig(); err != nil { 49 | // There was an error reading in the configuration 50 | if _, ok := err.(viper.ConfigFileNotFoundError); ok { 51 | // The error reading in the configuration was that it wasn't there. 52 | log.Fatalf("Config file not found! Please run 'cup configure' if you haven't already.\n%s", 53 | config.FilePath) 54 | } else { 55 | // There was some other error reading in the configuration file 56 | log.Fatalf("Error reading in the configuration file!\nError: %s", err) 57 | } 58 | } 59 | // Config loaded successfully 60 | // Unmarshal the config to our config struct, since we prefer using that over the viper interface 61 | unmarshalErr := viper.Unmarshal(&config.C) 62 | if unmarshalErr != nil { 63 | // Error unmarshalling the config into our struct. 64 | log.Fatalf("Unable to unmarshal config. Has it been hand edited?\nError: %s", unmarshalErr) 65 | } 66 | // Now that we have the full config, set the user's preferred log level. 67 | setLogLevel() 68 | 69 | // Attempt to update the DNS records specified 70 | if err := commands.Update(CupInfo); err != nil { 71 | // Error updating the records 72 | log.Fatalf("Error updating DNS records!\nError: %s", err) 73 | } else { 74 | // Records updated successfully. Inform the user. 75 | log.Info("Successfully updated all DNS records. Goodbye.") 76 | // Exit success 77 | os.Exit(0) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /cmd/cup/cup-version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/spf13/cobra" 23 | ) 24 | 25 | // Define the `version` command. It's just prints some compile time variables. 26 | var versionCmd = &cobra.Command{ 27 | Use: "version", 28 | Short: "Print the version information", 29 | Run: executeVersion, 30 | } 31 | 32 | // Register the subcommand with the root command 33 | func init() { 34 | rootCmd.AddCommand(versionCmd) 35 | } 36 | 37 | // Print some version information 38 | func executeVersion(_ *cobra.Command, _ []string) { 39 | log.Printf("Version: %s\nCommit: %s\nBuild Type: %s\n", version, commit, buildType) 40 | } 41 | -------------------------------------------------------------------------------- /cmd/cup/cup.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/spf13/cobra" 23 | "github.com/spf13/viper" 24 | "github.com/viertaxa/cup/internal/config" 25 | "github.com/viertaxa/cup/internal/types" 26 | "os" 27 | ) 28 | 29 | const envPrefix = "CUP" 30 | 31 | // To be set by the compiler/linker at build time. 32 | var version = "0.0.0" 33 | var commit = "x" 34 | var buildType string 35 | 36 | // To be set during Init 37 | var CupInfo types.CupInfo 38 | 39 | // Create the "root command" for cobra. It doesn't do anything but print usage info. 40 | var rootCmd = &cobra.Command{ 41 | Use: "cup [command]", 42 | Short: "CUP - Cloudflare (DNS) Updater Program", 43 | Long: "CUP is a Cloudflare (DNS) Updater Program that uses the Cloudflare API and a quorum of public " + 44 | "'What is my IP' services to create what amounts to a dynamic DNS service.", 45 | } 46 | 47 | func init() { 48 | // Generate a new CupInfo for us to inject 49 | CupInfo = types.CupInfo{ 50 | Version: version, 51 | Commit: commit, 52 | BuildType: buildType, 53 | } 54 | 55 | // logrus configuration 56 | // If we're building a development build, include the calling function in logging for debugging purposes. 57 | if buildType == "development" { 58 | log.SetReportCaller(true) 59 | } 60 | // Log to stdout rather than stderr as is the default. 61 | log.SetOutput(os.Stdout) 62 | // Use detailed timestamps rather than execution time. 63 | formatter := &log.TextFormatter{ 64 | FullTimestamp: true, 65 | TimestampFormat: "2006-01-02-15-04-05.000-0700", 66 | } 67 | log.SetFormatter(formatter) 68 | 69 | // Cobra configuration 70 | // Add root level flags to the root command 71 | rootCmd.PersistentFlags().StringVar(&config.FilePath, "config", "", "Configuration "+ 72 | "file path (default \"./cupconf.{yaml, json, toml}\")") 73 | rootCmd.PersistentFlags().StringVar(&config.C.LogLevel, "loglevel", "", "Set the maximum log "+ 74 | "level.") 75 | 76 | // Initialize Cobra/Viper 77 | cobra.OnInitialize(initConfig) 78 | } 79 | 80 | func main() { 81 | if err := rootCmd.Execute(); err != nil { 82 | log.Fatal(err) 83 | } 84 | } 85 | 86 | func initConfig() { 87 | // Enable environment variable input 88 | viper.SetEnvPrefix(envPrefix) 89 | viper.AutomaticEnv() 90 | 91 | // if the config file path was not passed in, set it to the default config file path 92 | if config.FilePath == "" { 93 | viper.SetConfigFile(config.DefaultCupConfigPath) 94 | config.FilePath = config.DefaultCupConfigPath 95 | } else { 96 | // If the config file path was passed in, tell viper look for it there. 97 | viper.SetConfigFile(config.FilePath) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /cmd/cup/shared.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/viertaxa/cup/internal/config" 23 | "github.com/viertaxa/cup/internal/util" 24 | "strings" 25 | ) 26 | 27 | // Set up the log levels. Called by sub-commands 28 | func setLogLevel() { 29 | // Check that the user passed in a valid log level and act accordingly. 30 | if config.C.LogLevel == "" { 31 | // If no log level was set on the command line, and there was no config file specifying this value, go with 32 | // something sane by default. 33 | log.SetLevel(log.InfoLevel) 34 | config.C.LogLevel = config.LogLevelToString(log.InfoLevel) 35 | } else if util.StringSliceContains(config.GetValidLogLevels(), strings.ToLower(config.C.LogLevel)) { 36 | // User's passed in log level was valid, so we use it. 37 | // Note: We avoid logging anything other than an Error or Fatal log message prior to this call 38 | // to avoid giving the user unwanted logs. 39 | log.SetLevel(config.StringToLogLevel(config.C.LogLevel)) 40 | log.Infof("Setting log level to %s", config.C.LogLevel) 41 | } else { 42 | // User passed in an invalid log level identifier. We don't know how to log in this case! 43 | log.Fatalf("Error, you specified an invalid log level (%s)! Exiting.", config.C.LogLevel) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # CUP 2 | 3 | The **C**loudflare (DNS) **Up**dater 4 | 5 | CUP is a tool to turn CloudFlare DNS into a Dynamic DNS service. 6 | 7 | # Pages 8 | 9 | - [Configuration](configuration.md) 10 | - [Updating Records](update.md) 11 | - [API Key](api-key.md) -------------------------------------------------------------------------------- /docs/api-key.md: -------------------------------------------------------------------------------- 1 | # API Key 2 | 3 | CUP requires a cloudflare API key to update your DNS records. Here, you'll find information on how to create that key. 4 | 5 | ## Creation 6 | 7 | - Log in to your Cloudflare dashboard. 8 | - Click the account menu in the upper-right corner 9 | - Click "My Profile" 10 | - Select the "API Tokens" tab 11 | - Select "Create Token" 12 | - Select "Get Started" on the "Create Custom Token" option at the bottom 13 | - Generate a token with the below settings. 14 | - Select "Continue to Summary" 15 | - Select "Create Token" 16 | - Save this token somewhere safe! 17 | - Treat it like a password 18 | - Cloudflare won't show it to you again 19 | 20 | ## Permissions 21 | 22 | ![token_settings](img/token_settings.png) 23 | 24 | ### Explanation 25 | 26 | #### Permissions 27 | 28 | Zone - DNS - Edit: Required to update DNS records 29 | Zone - Zone - Read: Required to list the domains you control in Cloudflare to get their API ID 30 | 31 | #### Zone Resources 32 | Include - All zones: Required to be able to list the domains you control. 33 | 34 | NOTE: You can't restrict this beyond All Zones due to what many would perceive as a long-standing bug in the Cloudflare API. 35 | If you select just the domains you wish to update, the list action on the API fails, even if querying against just that domain. 36 | 37 | -------------------------------------------------------------------------------- /docs/configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | To configure CUP, simply run `./cup configure` on Linux or Mac, or `.\cup.exe configure` on Windows. You will then be prompted for several bits of information that are required to get CUP running. 3 | 4 | Alternately, advanced users may manually create or modify a YAML, TOML, or JSON file with the appropriate values. 5 | 6 | ## Updating a configuration 7 | 8 | To update a configuration, just run the `configure` command again. You will be guided through the configuration you had previously set. 9 | 10 | ## Creating a configuration 11 | 12 | Need to create a new configuration? Run the `configure` command and we'll guide you through setting up CUP. At the end, we'll save your configuration file to disk. 13 | 14 | ## Defaults 15 | 16 | ### Config File Location 17 | 18 | The default configuration file path for CUP is `./cupconf.yaml`. If you wish to run CUP with a minimum of flags, stick to this location. 19 | 20 | To override this, specify the `--config ` flag 21 | 22 | ### Log Level 23 | 24 | The default log level is INFO. We suggest leaving this as is, especially for `./cup configure` 25 | 26 | To override this, specify the `--loglevel ` flag with your choice of the following: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic` 27 | 28 | ## Options 29 | 30 | As you are guided through the configuration, you will encounter the following configuration options: 31 | 32 | ### Overall settings 33 | 34 | - `Level` - This sets the log level as defined above. The same options apply, but we suggest just hitting the ENTER/RETURN key to accept the default value of `info` 35 | - `API Base` - This sets the API base that we use for Cloudflare. Unless you really *really* know what you're doing, just hit the ENTER/RETURN key to accept the default. 36 | - `API Key` - This is your Cloudflare API Key used to query and update the Cloudflare API. Enter it here. The default will not work and is just an example. 37 | 38 | ### IP determination Services 39 | 40 | After setting up the overall settings, you will be guided through the default IP determination services. 41 | 42 | If you don't have a reason to change them, it's best to just hit ENTER/RETURN and accept the defaults. There are three services entered by default, ipify, SeeIP, and WhatIsMyIPAddress. This should provide more than enough fault tolerance and validation that one site is not wrong. 43 | 44 | - `Service Name` - The name of the service you will be using 45 | - `API Base` - The API URL that we query to get your public IP 46 | 47 | ### Domains and Hosts 48 | 49 | After setting up the IP determination services, you will be guided through setting up the domains and hosts you wish to update with your public IP when you run the `update` command. 50 | 51 | You **must** enter your own values here, the defaults will not work. 52 | 53 | - `Domain` - The domain you wish to update records on 54 | 55 | Each *domain* represents the domain name you purchased and added to Cloudflare. For example, `example.com`, `example.co.uk`, `example.io`. do not enter hosts here, such as `www.example.com`, or `dynamic.example.com`. You'll configure the hosts later. 56 | 57 | - `Hosts` - A comma separated list of each host record you wish to update the IP address of 58 | 59 | There are several options here: 60 | 61 | - To update the root domain, use the `@` keyword. 62 | - To update a subdomain, enter just the subdomain. For example to update `www.example.com`, you would enter `www` 63 | - To update a subdomain on a subdomain, just chain together the subdomains separated by `.`s. For example to update `www.foo.dynamic.example.com`, you would enter `www.foo.dynamic` 64 | - to update a wildcard record, use the `*` keyword. For example to update your wildcard record `*.dynamic.example.com` you would enter `*.dynamic` -------------------------------------------------------------------------------- /docs/img/token_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viertaxa/cup/d3d5d31dd9698a30f5192573f0d189b7c720efd0/docs/img/token_settings.png -------------------------------------------------------------------------------- /docs/update.md: -------------------------------------------------------------------------------- 1 | # Updating Records 2 | To update records, simply run `./cup update` on Linux or Mac, or `.\cup.exe update` on Windows. 3 | 4 | ## Defaults 5 | 6 | ### Config File Location 7 | 8 | The default configuration file path for CUP is `./cupconf.yaml`. If you wish to run CUP with a minimum of flags, stick to this location. 9 | 10 | To override this, specify the `--config ` flag 11 | 12 | ### Log Level 13 | 14 | The default log level is whatever was set during configuration. 15 | 16 | To override this, specify the `--loglevel ` flag with your choice of the following: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic` 17 | 18 | ## Update Process 19 | 20 | CUP will iterate on each domain you have configured, updating each host listed within it. 21 | 22 | CUP will only update the content of an existing DNS record. It will not create one, or update any other setting, such as TTL. 23 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/viertaxa/cup 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/cloudflare/cloudflare-go v0.13.6 7 | github.com/sirupsen/logrus v1.2.0 8 | github.com/spf13/cobra v1.1.1 9 | github.com/spf13/viper v1.7.0 10 | gopkg.in/errgo.v2 v2.1.0 11 | gopkg.in/yaml.v2 v2.2.8 12 | ) 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 9 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 10 | cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= 11 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 12 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 13 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 14 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 15 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 16 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 17 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 18 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 19 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 20 | github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= 21 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= 22 | github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= 23 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 24 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 25 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= 26 | github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= 27 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 28 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 29 | github.com/cloudflare/cloudflare-go v0.13.6 h1:G6aw092fOkvkHODCxf8EHLPqHN2BVxHU4RoTFjS51xo= 30 | github.com/cloudflare/cloudflare-go v0.13.6/go.mod h1:gNGW6MkPPVLhjgaXq4vaS7WnTaQpCfl6DE1W9JuWyt8= 31 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 32 | github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 33 | github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 34 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 35 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 36 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 37 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 38 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 39 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 40 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 41 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 42 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 43 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 44 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= 45 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 46 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 47 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 48 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 49 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 50 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 51 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 52 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 53 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 54 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 55 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 56 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 57 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 58 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 59 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 60 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 61 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 62 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 63 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 64 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 65 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 66 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 67 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 68 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 69 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 70 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 71 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 72 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= 73 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 74 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 75 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 76 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 77 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 78 | github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= 79 | github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= 80 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 81 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 82 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 83 | github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 84 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 85 | github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= 86 | github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= 87 | github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= 88 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 89 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 90 | github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= 91 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 92 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 93 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 94 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 95 | github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= 96 | github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= 97 | github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= 98 | github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= 99 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 100 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 101 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 102 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 103 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 104 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 105 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 106 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 107 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 108 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 109 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 110 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 111 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 112 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 113 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 114 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 115 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 116 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 117 | github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= 118 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 119 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 120 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 121 | github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 122 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 123 | github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= 124 | github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 125 | github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 126 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 127 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 128 | github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= 129 | github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= 130 | github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 131 | github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= 132 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 133 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 134 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 135 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 136 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 137 | github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= 138 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 139 | github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= 140 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 141 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 142 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 143 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 144 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 145 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 146 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 147 | github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= 148 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 149 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 150 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 151 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 152 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 153 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 154 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 155 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 156 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 157 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 158 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 159 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 160 | github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= 161 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 162 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 163 | github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= 164 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 165 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= 166 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 167 | github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= 168 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 169 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 170 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 171 | github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= 172 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 173 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= 174 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 175 | github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= 176 | github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= 177 | github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= 178 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 179 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 180 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 181 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 182 | github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= 183 | github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 184 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 185 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 186 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 187 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 188 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 189 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 190 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 191 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= 192 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 193 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 194 | github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= 195 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 196 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 197 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 198 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 199 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 200 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 201 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 202 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 203 | golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 204 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 205 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 206 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= 207 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 208 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= 209 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 210 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 211 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 212 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 213 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 214 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 215 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 216 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 217 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 218 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 219 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 220 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 221 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 222 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 223 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 224 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 225 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 226 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 227 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 228 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 229 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 230 | golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 231 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 232 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 233 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 234 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 235 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 236 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 237 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 238 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 239 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 240 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 241 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 242 | golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= 243 | golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 244 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 245 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 246 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 247 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 248 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 249 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 250 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 251 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 252 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 253 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 254 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 255 | golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 256 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 257 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 258 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 259 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 260 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 261 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 262 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 263 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 264 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= 265 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 266 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= 267 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 268 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 269 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 270 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 271 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 272 | golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= 273 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 274 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 275 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 276 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= 277 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 278 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 279 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 280 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 281 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 282 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 283 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 284 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 285 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 286 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 287 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 288 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 289 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 290 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 291 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 292 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 293 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 294 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 295 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 296 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 297 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 298 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 299 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 300 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 301 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 302 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 303 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 304 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 305 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 306 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 307 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 308 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 309 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 310 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 311 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 312 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 313 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 314 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 315 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 316 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 317 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 318 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 319 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 320 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 321 | gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8= 322 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 323 | gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= 324 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 325 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 326 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 327 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 328 | gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 329 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 330 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 331 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 332 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 333 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 334 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 335 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 336 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 337 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 338 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 339 | -------------------------------------------------------------------------------- /internal/cfutils/check-token-active.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package cfutils 19 | 20 | import ( 21 | "github.com/cloudflare/cloudflare-go" 22 | log "github.com/sirupsen/logrus" 23 | "time" 24 | ) 25 | 26 | const cfActiveTokenStatus = "active" 27 | 28 | func CheckKeyIsActive(cf *cloudflare.API) (bool, error) { 29 | token, err := cf.VerifyAPIToken() 30 | if err != nil { 31 | return false, err 32 | } 33 | log.Debugf("API Token %s is %s, became valid on %s, and expires/expired on %s", token.ID, token.Status, 34 | token.NotBefore.Format(time.RFC1123), token.ExpiresOn.Format(time.RFC1123)) 35 | 36 | if token.Status != cfActiveTokenStatus { 37 | return false, nil 38 | } 39 | return true, nil 40 | } 41 | -------------------------------------------------------------------------------- /internal/cfutils/zone.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package cfutils 19 | 20 | import ( 21 | "github.com/cloudflare/cloudflare-go" 22 | log "github.com/sirupsen/logrus" 23 | "github.com/viertaxa/cup/internal/config" 24 | "gopkg.in/errgo.v2/fmt/errors" 25 | ) 26 | 27 | func GetZoneID(domain config.DomainConfig, cf *cloudflare.API) (string, error) { 28 | // Get the zone object so we can get it's ID 29 | zones, err := cf.ListZones(domain.Domain) 30 | if err != nil { 31 | return "", err 32 | } 33 | log.Debugf("Got %d zones matching %s", len(zones), domain.Domain) 34 | if len(zones) != 1 { 35 | return "", errors.Newf("got %d zones matching %s. Please file a bug report on GitHub if you believe "+ 36 | "this to be incorrect", len(zones), domain.Domain) 37 | } 38 | zone := zones[0] 39 | log.Debugf("Got zone ID %s for domain %s", zone.ID, zone.Name) 40 | return zone.ID, nil 41 | } -------------------------------------------------------------------------------- /internal/commands/configure-ui.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package commands 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/viertaxa/cup/internal/config" 23 | "github.com/viertaxa/cup/internal/util" 24 | "strings" 25 | ) 26 | 27 | // Get the user's desired loglevel 28 | func promptLogLevel(existingOrDefault string) string { 29 | // Loop until we get something satisfactory 30 | for { 31 | log.Println("Please enter the log level you would like cup to operate at.") 32 | log.Printf("Valid values are: %s", strings.Join(config.GetValidLogLevels(), ", ")) 33 | response, err := util.AskUserForString("Level", existingOrDefault) 34 | if err != nil { 35 | log.Errorf("Error getting your response. Please try again.\n%s", err) 36 | } else if util.StringSliceContains(config.GetValidLogLevels(), strings.ToLower(response)) { 37 | return strings.ToLower(response) 38 | } else { 39 | log.Errorf("%s is not a valid log level. Please try again.", response) 40 | } 41 | } 42 | } 43 | 44 | // Get the desired baseurl 45 | func promptApiBaseUrl(existingOrDefault string) string { 46 | //Loop until we get something satisfactory 47 | for { 48 | log.Println("Please enter the base URL for the CloudFlare API.") 49 | log.Println("Unless you really know what you're doing, please leave the default by pressing the " + 50 | "ENTER/RETURN key. If you provide a value, do not include a trailing `/`.") 51 | response, err := util.AskUserForString("API Base", existingOrDefault) 52 | if err != nil { 53 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 54 | } 55 | // Check for HTTPS. Not only is it a good idea, but Cloudflare rejects http connections. 56 | if strings.HasPrefix(strings.ToLower(response), "https://") { 57 | return strings.ToLower(response) 58 | } else { 59 | log.Warnf("%s does not begin with 'https://'. This will not work with the cloudflare API. "+ 60 | "Continue anyways?", response) 61 | shouldContinue, err := util.AskUserForBool("Continue?", false) 62 | if err != nil { 63 | log.Errorf("Error getting your response.\nError:%s", err) 64 | } else { 65 | if shouldContinue { 66 | return strings.ToLower(response) 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | // Get the user's API key 74 | func promptAPIKey(existingOrDefault string) string { 75 | // Loop until we get something satisfactory 76 | for { 77 | log.Println("Please enter the API Key you will be using") 78 | response, err := util.AskUserForString("API Key", existingOrDefault) 79 | if err != nil { 80 | log.Errorf("Error getting your response. Please try again.\n%s", err) 81 | } else { 82 | return response 83 | } 84 | } 85 | } 86 | 87 | // Get the list of hosts and their domains to update 88 | func promptDomainsAndHosts(existingOrDefault []config.DomainConfig) []config.DomainConfig { 89 | var newDomainsAndHosts []config.DomainConfig 90 | 91 | // Loop over the existing or example configuration. 92 | for index, domainConfig := range existingOrDefault { 93 | // Loop on the domain entry until it is successfully updated or the user deletes it. 94 | for { 95 | var updatedDomain string 96 | var updatedHosts []string 97 | 98 | // If we're configuring a domain of index 1 or higher, allow the user to remove the domain from the config 99 | if index != 0 { 100 | log.Printf("Moving on to domain #%d, %s, with hosts: %s", index+1, domainConfig.Domain, 101 | strings.Join(domainConfig.Hosts, ",")) 102 | keep, err := util.AskUserForBool("Should we keep this domain in the config?", true) 103 | if err != nil { 104 | log.Errorf("Error getting your response, please try again.\nError: %s", err) 105 | continue 106 | } else { 107 | if !keep { 108 | // Move on to the next domain without appending this domain to newDomainsAndHosts 109 | break 110 | } 111 | } 112 | } 113 | // Gather info on the domain we're iterating on 114 | log.Println("Please enter the domain you will be controlling records on.") 115 | domainResponse, err := util.AskUserForString("Domain", domainConfig.Domain) 116 | if err != nil { 117 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 118 | continue 119 | } else { 120 | updatedDomain = strings.ToLower(domainResponse) 121 | } 122 | 123 | // Move on to getting the list of hosts 124 | log.Println("Please enter a comma separated list of hosts that should be updated. Use @ for the " + 125 | "root domain") 126 | hostResponse, err := util.AskUserForString("Hosts", strings.Join(domainConfig.Hosts, ",")) 127 | if err != nil { 128 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 129 | continue 130 | } else { 131 | updatedHosts = strings.Split(strings.ReplaceAll(hostResponse, " ", ""), ",") 132 | } 133 | // Add the information to the new list of domains to be updated 134 | newDomainsAndHosts = append(newDomainsAndHosts, config.DomainConfig{ 135 | Domain: updatedDomain, 136 | Hosts: updatedHosts, 137 | }) 138 | // We're done with this domain, so move on. 139 | break 140 | } 141 | } 142 | // Allow user to enter additional domains 143 | for { 144 | add, err := util.AskUserForBool("Should we add an additional domain?", false) 145 | if err != nil { 146 | log.Errorf("Error getting your response, please try again.\n%s", err) 147 | continue 148 | } else { 149 | if !add { 150 | // Don't want to add another, move on. 151 | break 152 | } 153 | } 154 | 155 | // Does want to add another 156 | var thisDomain string 157 | var thisHosts []string 158 | 159 | var exampleDomainConfig = config.GetDefaultCupConfig().Domains[0] 160 | 161 | // Gather info on the new domain to be added 162 | log.Println("Please enter the domain you will be controlling records on.") 163 | domainResponse, err := util.AskUserForString("Domain", exampleDomainConfig.Domain) 164 | if err != nil { 165 | log.Errorf("Error getting your response. Please try again.\n%s", err) 166 | continue 167 | } else { 168 | thisDomain = strings.ToLower(domainResponse) 169 | } 170 | 171 | // Gather the info on the hosts to be added 172 | log.Println("Please enter a comma separated list of hosts that should be updated. Use @ for the root " + 173 | "domain") 174 | hostResponse, err := util.AskUserForString("Hosts", strings.Join(exampleDomainConfig.Hosts, ",")) 175 | if err != nil { 176 | log.Errorf("Error getting your response. Please try again.\n%s", err) 177 | continue 178 | } else { 179 | thisHosts = strings.Split(strings.ReplaceAll(hostResponse, " ", ""), ",") 180 | } 181 | newDomainsAndHosts = append(newDomainsAndHosts, config.DomainConfig{ 182 | Domain: thisDomain, 183 | Hosts: thisHosts, 184 | }) 185 | } 186 | return newDomainsAndHosts 187 | } 188 | 189 | // Get the list of hosts and their domains to update 190 | func promptSimpleIPServices(existingOrDefault []config.SimpleIPReporterConfig) []config.SimpleIPReporterConfig { 191 | var newSimpleIPReporterServices []config.SimpleIPReporterConfig 192 | 193 | // Loop over the existing or example configuration. 194 | for index, svc := range existingOrDefault { 195 | // Loop on the domain entry until it is successfully updated or the user deletes it. 196 | for { 197 | var updatedApiUrl string 198 | var updatedSvcName string 199 | 200 | // If we're configuring a service of index 1 or higher, allow the user to remove the service from the config 201 | if index != 0 { 202 | log.Printf("Moving on to service #%d, %s", index+1, svc.ServiceName) 203 | keep, err := util.AskUserForBool("Should we keep this service in the config?", true) 204 | if err != nil { 205 | log.Errorf("Error getting your response, please try again.\nError: %s", err) 206 | continue 207 | } else { 208 | if !keep { 209 | // Move on to the next service without appending this one to newSimpleIPReporterServices 210 | break 211 | } 212 | } 213 | } 214 | // Gather info on the domain we're iterating on 215 | log.Println("Please enter the name of the IP Reporting Service.") 216 | serviceNameResponse, err := util.AskUserForString("Service Name", svc.ServiceName) 217 | if err != nil { 218 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 219 | continue 220 | } else { 221 | updatedSvcName = serviceNameResponse 222 | } 223 | 224 | // Get the API Base 225 | log.Println("Please enter the API Base URL for this service.") 226 | hostResponse, err := util.AskUserForString("API Base", svc.IPv4ApiBase) 227 | if err != nil { 228 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 229 | continue 230 | } else { 231 | // Check for HTTPS. Not only is it a good idea, but Cloudflare rejects http connections. 232 | if strings.HasPrefix(strings.ToLower(hostResponse), "https://") { 233 | updatedApiUrl = strings.ToLower(hostResponse) 234 | } else { 235 | log.Warnf("%s does not begin with 'https://'. This is highly insecure. "+ 236 | "Continue anyways?", hostResponse) 237 | shouldContinue, err := util.AskUserForBool("Continue?", false) 238 | if err != nil { 239 | log.Errorf("Error getting your response.\nError:%s", err) 240 | } else { 241 | if shouldContinue { 242 | updatedApiUrl = strings.ToLower(hostResponse) 243 | } 244 | } 245 | } 246 | } 247 | // Add the information to the new list of domains to be updated 248 | newSimpleIPReporterServices = append(newSimpleIPReporterServices, config.SimpleIPReporterConfig{ 249 | ServiceName: updatedSvcName, 250 | IPv4ApiBase: updatedApiUrl, 251 | }) 252 | // We're done with this service, so move on. 253 | break 254 | } 255 | } 256 | // Allow user to enter additional services 257 | for { 258 | add, err := util.AskUserForBool("Should we add an additional service?", false) 259 | if err != nil { 260 | log.Errorf("Error getting your response, please try again.\n%s", err) 261 | continue 262 | } else { 263 | if !add { 264 | // Don't want to add another, move on. 265 | break 266 | } 267 | } 268 | 269 | // Does want to add another 270 | var updatedApiUrl string 271 | var updatedSvcName string 272 | 273 | // Gather info on the domain we're iterating on 274 | log.Println("Please enter the name of the IP Reporting Service you wish to use.") 275 | serviceNameResponse, err := util.AskUserForString("Service Name", config.GetDefaultCupConfig(). 276 | SimpleIPReportServices[0].ServiceName) 277 | if err != nil { 278 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 279 | continue 280 | } else { 281 | updatedSvcName = serviceNameResponse 282 | } 283 | 284 | // Get the API Base 285 | log.Println("Please enter the API Base URL for this service.") 286 | hostResponse, err := util.AskUserForString("API Base", config.GetDefaultCupConfig(). 287 | SimpleIPReportServices[0].IPv4ApiBase) 288 | if err != nil { 289 | log.Errorf("Error getting your response. Please try again.\nError: %s", err) 290 | continue 291 | } else { 292 | // Check for HTTPS. 293 | if strings.HasPrefix(strings.ToLower(hostResponse), "https://") { 294 | updatedApiUrl = strings.ToLower(hostResponse) 295 | } else { 296 | log.Warnf("%s does not begin with 'https://'. This is highly insecure. "+ 297 | "Continue anyways?", hostResponse) 298 | shouldContinue, err := util.AskUserForBool("Continue?", false) 299 | if err != nil { 300 | log.Errorf("Error getting your response.\nError:%s", err) 301 | } else { 302 | if shouldContinue { 303 | updatedApiUrl = strings.ToLower(hostResponse) 304 | } 305 | } 306 | } 307 | } 308 | // Add the information to the new list of domains to be updated 309 | newSimpleIPReporterServices = append(newSimpleIPReporterServices, config.SimpleIPReporterConfig{ 310 | ServiceName: updatedSvcName, 311 | IPv4ApiBase: updatedApiUrl, 312 | }) 313 | // We're done with this service, so move on. 314 | } 315 | return newSimpleIPReporterServices 316 | } -------------------------------------------------------------------------------- /internal/commands/configure.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package commands 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "github.com/viertaxa/cup/internal/config" 23 | "github.com/viertaxa/cup/internal/util" 24 | ) 25 | 26 | // Populate the configuration struct 27 | func ConfigurationCreate() error { 28 | log.Info("Creating a new configuration") 29 | 30 | // Start prompting the user for overall configuration values 31 | config.C.LogLevel = promptLogLevel(config.C.LogLevel) 32 | config.C.API.ApiBaseUrl = promptApiBaseUrl(config.GetDefaultCupConfig().API.ApiBaseUrl) 33 | config.C.API.ApiKey = promptAPIKey(config.GetDefaultCupConfig().API.ApiKey) 34 | 35 | log.Info("We will now begin setting up the services we will use to determine your public IP.") 36 | // Prompt user for what IP Reporting services we should use 37 | config.C.SimpleIPReportServices = promptSimpleIPServices(config.GetDefaultCupConfig().SimpleIPReportServices) 38 | 39 | // Start prompting for domain/host configuration 40 | log.Info("We will now begin setting up domains and hosts.") 41 | config.C.Domains = promptDomainsAndHosts(config.GetDefaultCupConfig().Domains) 42 | 43 | // Back-populate viper with the configuration struct so we can later save it to disk 44 | if err := util.LoadViperConfigFromStruct(config.C); err != nil { 45 | // Error populating viper, pass the error along. 46 | return err 47 | } else { 48 | // Config struct populated and viper populated successfully 49 | return nil 50 | } 51 | } 52 | 53 | // Update an existing configuration 54 | func ConfigurationEdit() error { 55 | log.Infof("Modifying existing configuration at %s.", config.FilePath) 56 | 57 | // Start prompting the user for overall configuration values 58 | config.C.LogLevel = promptLogLevel(config.C.LogLevel) 59 | config.C.API.ApiBaseUrl = promptApiBaseUrl(config.C.API.ApiBaseUrl) 60 | config.C.API.ApiKey = promptAPIKey(config.C.API.ApiKey) 61 | 62 | log.Info("We will now begin setting up the services we will use to determine your public IP.") 63 | // Prompt user for what IP Reporting services we should use 64 | config.C.SimpleIPReportServices = promptSimpleIPServices(config.C.SimpleIPReportServices) 65 | 66 | // Start prompting for domain/host configuration 67 | log.Println("We will now begin setting up domains and hosts.") 68 | config.C.Domains = promptDomainsAndHosts(config.C.Domains) 69 | 70 | // Back-populate viper with the configuration struct so we can later save it to disk 71 | if err := util.LoadViperConfigFromStruct(config.C); err != nil { 72 | // Error populating viper, pass the error along. 73 | return err 74 | } else { 75 | // Config struct populated and viper populated successfully 76 | return nil 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /internal/commands/update.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package commands 19 | 20 | import ( 21 | "errors" 22 | "github.com/cloudflare/cloudflare-go" 23 | log "github.com/sirupsen/logrus" 24 | "github.com/viertaxa/cup/internal/cfutils" 25 | "github.com/viertaxa/cup/internal/config" 26 | "github.com/viertaxa/cup/internal/externalip" 27 | "github.com/viertaxa/cup/internal/types" 28 | ) 29 | 30 | func Update(cupInfo types.CupInfo) error { 31 | // Get our external IP 32 | ip, err := externalip.GetExternalIP(cupInfo) 33 | if err != nil || ip == nil { 34 | log.Error("Error getting external IP.") 35 | return err 36 | } 37 | log.Debugf("Successfully got public IP: %s", ip.IPv4) 38 | 39 | // Create a CloudFlare API Client 40 | cf, err := cloudflare.NewWithAPIToken(config.C.API.ApiKey, 41 | func(api *cloudflare.API) error { 42 | api.BaseURL = config.C.API.ApiBaseUrl 43 | return nil 44 | }) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | // Check that the provided API Key is valid 50 | valid, err := cfutils.CheckKeyIsActive(cf) 51 | if err != nil { 52 | log.Error("Unable to check API key validity") 53 | return err 54 | } 55 | if !valid { 56 | log.Error("API Key is not active. Can't continue.") 57 | return errors.New("api key is not active") 58 | } 59 | 60 | // For each configured Domain, updated the specified hosts 61 | // We'll not bubble up and errors in an attempt to updates as many hosts as possible in the event of a failure 62 | for _, domain := range config.C.Domains { 63 | // Get the zone ID for the domain 64 | zoneID, err := cfutils.GetZoneID(domain, cf) 65 | if err != nil { 66 | log.Errorf("Error listing zone for domain `%s\nError:%s`", domain.Domain, err) 67 | continue 68 | } 69 | 70 | // Update each host record 71 | for _, host := range domain.Hosts { 72 | // Get the host ID for each host 73 | 74 | // The CF API has the whole domain as the name value for hosts. Generate that value. 75 | var apiNameValue string 76 | if host == "@" { 77 | apiNameValue = domain.Domain 78 | } else { 79 | apiNameValue = host + "." + domain.Domain 80 | } 81 | log.Debugf("API Name Value for %s is %s", host, apiNameValue) 82 | 83 | // Generate a DNSRecord for us to use as filter parameters 84 | filterRecord := cloudflare.DNSRecord{ 85 | // Get only A records 86 | Type: "A", 87 | Name: apiNameValue, 88 | } 89 | 90 | // Request the records matching the host 91 | // Note that multiple are able to be returned if the user has defined multiple IPs (i.e. for round robin) 92 | // within Cloudflare. 93 | records, err := cf.DNSRecords(zoneID, filterRecord) 94 | if err != nil { 95 | log.Errorf("Error getting DNS records matching %s\nError: %s", host, err) 96 | continue 97 | } 98 | 99 | // Make sure we only got back one record. 100 | if len(records) != 1 { 101 | log.Errorf("There were %d records found for %s. We only support hosts with a single record in "+ 102 | "this tool.", len(records), host) 103 | continue 104 | } 105 | record := records[0] 106 | log.Debugf("Got host record with ID %s for host %s, current value %s", 107 | record.ID, record.Name, record.Content) 108 | 109 | // If the value that's currently in Cloudflare does not match the public IP that we determined, update it 110 | if record.Content != ip.IPv4 { 111 | // Generate a partial record to update with 112 | newRecord := cloudflare.DNSRecord{ 113 | Content: ip.IPv4, 114 | } 115 | 116 | // Send the record to Cloudflare 117 | err = cf.UpdateDNSRecord(zoneID, record.ID, newRecord) 118 | if err != nil { 119 | log.Errorf("Error updating IP for host\nError: %s", err) 120 | continue 121 | } else { 122 | log.Infof("Succsfully updated record for host %s with ip %s", host, ip.IPv4) 123 | } 124 | } else { 125 | // Don't need to update, won't try to not be abusive to the API 126 | log.Info("DNS Record already matches the public IP. Not updating.") 127 | } 128 | } 129 | } 130 | return nil 131 | } 132 | -------------------------------------------------------------------------------- /internal/config/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package config 19 | 20 | var C CupConfig 21 | var FilePath string 22 | 23 | const DefaultCupConfigPath = "./cupconf.yaml" 24 | 25 | type ( 26 | CupConfig struct { 27 | LogLevel string `json:"logLevel"` 28 | API ApiConfig `json:"api"` 29 | Domains []DomainConfig `json:"domains"` 30 | SimpleIPReportServices []SimpleIPReporterConfig `json:"simpleIpReportServices"` 31 | } 32 | ApiConfig struct { 33 | ApiBaseUrl string `json:"apiBaseUrl"` 34 | ApiKey string `json:"apiKey"` 35 | } 36 | DomainConfig struct { 37 | Domain string `json:"domain"` 38 | Hosts []string `json:"hosts"` 39 | } 40 | SimpleIPReporterConfig struct { 41 | IPv4ApiBase string `json:"ipv4ApiBase"` 42 | ServiceName string `json:"serviceName"` 43 | } 44 | ) 45 | 46 | func GetDefaultCupConfig() CupConfig { 47 | return CupConfig{ 48 | LogLevel: "info", 49 | API: ApiConfig{ 50 | ApiBaseUrl: "https://api.cloudflare.com/client/v4", 51 | ApiKey: "1234567893feefc5f0q5000bfo0c38d90bbeb", 52 | }, 53 | Domains: []DomainConfig{ 54 | { 55 | Domain: "example.com", 56 | Hosts: []string{"dynamic1", "subdynamic.host", "@"}, 57 | }, 58 | }, 59 | SimpleIPReportServices: []SimpleIPReporterConfig{ 60 | { 61 | IPv4ApiBase: "https://api.ipify.org", 62 | ServiceName: "ipify", 63 | }, 64 | { 65 | IPv4ApiBase: "https://ip4.seeip.org", 66 | ServiceName: "SeeIP", 67 | }, 68 | { 69 | IPv4ApiBase: "https://ipv4bot.whatismyipaddress.com", 70 | ServiceName: "WhatIsMyIPAddress", 71 | }, 72 | }, 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /internal/config/loglevels.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package config 19 | 20 | import ( 21 | log "github.com/sirupsen/logrus" 22 | "strings" 23 | ) 24 | 25 | const traceConfigKey = "trace" 26 | const debugConfigKey = "debug" 27 | const infoConfigKey = "info" 28 | const warnConfigKey = "warn" 29 | const errorConfigKey = "error" 30 | const fatalConfigKey = "fatal" 31 | const panicConfigKey = "panic" 32 | 33 | func GetValidLogLevels() []string { 34 | return []string{ 35 | traceConfigKey, 36 | debugConfigKey, 37 | infoConfigKey, 38 | warnConfigKey, 39 | errorConfigKey, 40 | fatalConfigKey, 41 | panicConfigKey, 42 | } 43 | } 44 | 45 | func StringToLogLevel(str string) log.Level { 46 | lowerStr := strings.ToLower(str) 47 | switch lowerStr { 48 | case traceConfigKey: 49 | return log.TraceLevel 50 | case debugConfigKey: 51 | return log.DebugLevel 52 | case infoConfigKey: 53 | return log.InfoLevel 54 | case warnConfigKey: 55 | return log.WarnLevel 56 | case errorConfigKey: 57 | return log.ErrorLevel 58 | case fatalConfigKey: 59 | return log.FatalLevel 60 | case panicConfigKey: 61 | return log.PanicLevel 62 | default: 63 | // If we incorrectly check the input and end up here, return the program default of `info` 64 | return log.InfoLevel 65 | } 66 | } 67 | 68 | func LogLevelToString(level log.Level) string { 69 | switch level { 70 | case log.TraceLevel: 71 | return traceConfigKey 72 | case log.DebugLevel: 73 | return debugConfigKey 74 | case log.InfoLevel: 75 | return infoConfigKey 76 | case log.WarnLevel: 77 | return warnConfigKey 78 | case log.ErrorLevel: 79 | return errorConfigKey 80 | case log.FatalLevel: 81 | return fatalConfigKey 82 | case log.PanicLevel: 83 | return panicConfigKey 84 | default: 85 | // If we somehow get a different value, just return the application default log level, `info` 86 | return infoConfigKey 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /internal/config/loglevels_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package config 19 | 20 | import ( 21 | "github.com/sirupsen/logrus" 22 | "testing" 23 | ) 24 | 25 | func TestLogLevelToString(t *testing.T) { 26 | type args struct { 27 | level logrus.Level 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | want string 33 | }{ 34 | { 35 | name: "Trace", 36 | args: args{ 37 | level: logrus.TraceLevel, 38 | }, 39 | want: "trace", 40 | }, 41 | { 42 | name: "Debug", 43 | args: args{ 44 | level: logrus.DebugLevel, 45 | }, 46 | want: "debug", 47 | }, 48 | { 49 | name: "Info", 50 | args: args{ 51 | level: logrus.InfoLevel, 52 | }, 53 | want: "info", 54 | }, 55 | { 56 | name: "Warn", 57 | args: args{ 58 | level: logrus.WarnLevel, 59 | }, 60 | want: "warn", 61 | }, 62 | { 63 | name: "Error", 64 | args: args{ 65 | level: logrus.ErrorLevel, 66 | }, 67 | want: "error", 68 | }, 69 | { 70 | name: "Fatal", 71 | args: args{ 72 | level: logrus.FatalLevel, 73 | }, 74 | want: "fatal", 75 | }, 76 | { 77 | name: "Panic", 78 | args: args{ 79 | level: logrus.PanicLevel, 80 | }, 81 | want: "panic", 82 | }, 83 | } 84 | for _, tt := range tests { 85 | t.Run(tt.name, func(t *testing.T) { 86 | if got := LogLevelToString(tt.args.level); got != tt.want { 87 | t.Errorf("LogLevelToString() = %v, want %v", got, tt.want) 88 | } 89 | }) 90 | } 91 | } 92 | 93 | func TestStringToLogLevel(t *testing.T) { 94 | type args struct { 95 | str string 96 | } 97 | tests := []struct { 98 | name string 99 | args args 100 | want logrus.Level 101 | }{ 102 | { 103 | name: "Trace", 104 | args: args{ 105 | str: "Trace", 106 | }, 107 | want: logrus.TraceLevel, 108 | }, 109 | { 110 | name: "trace", 111 | args: args{ 112 | str: "trace", 113 | }, 114 | want: logrus.TraceLevel, 115 | }, 116 | { 117 | name: "Debug", 118 | args: args{ 119 | str: "Debug", 120 | }, 121 | want: logrus.DebugLevel, 122 | }, 123 | { 124 | name: "debug", 125 | args: args{ 126 | str: "debug", 127 | }, 128 | want: logrus.DebugLevel, 129 | }, 130 | { 131 | name: "Info", 132 | args: args{ 133 | str: "Info", 134 | }, 135 | want: logrus.InfoLevel, 136 | }, 137 | { 138 | name: "info", 139 | args: args{ 140 | str: "info", 141 | }, 142 | want: logrus.InfoLevel, 143 | }, 144 | { 145 | name: "Warn", 146 | args: args{ 147 | str: "Warn", 148 | }, 149 | want: logrus.WarnLevel, 150 | }, 151 | { 152 | name: "warn", 153 | args: args{ 154 | str: "warn", 155 | }, 156 | want: logrus.WarnLevel, 157 | }, 158 | { 159 | name: "Error", 160 | args: args{ 161 | str: "Error", 162 | }, 163 | want: logrus.ErrorLevel, 164 | }, 165 | { 166 | name: "error", 167 | args: args{ 168 | str: "error", 169 | }, 170 | want: logrus.ErrorLevel, 171 | }, 172 | { 173 | name: "Fatal", 174 | args: args{ 175 | str: "Fatal", 176 | }, 177 | want: logrus.FatalLevel, 178 | }, 179 | { 180 | name: "fatal", 181 | args: args{ 182 | str: "fatal", 183 | }, 184 | want: logrus.FatalLevel, 185 | }, 186 | { 187 | name: "Panic", 188 | args: args{ 189 | str: "Panic", 190 | }, 191 | want: logrus.PanicLevel, 192 | }, 193 | { 194 | name: "panic", 195 | args: args{ 196 | str: "panic", 197 | }, 198 | want: logrus.PanicLevel, 199 | }, 200 | { 201 | name: "Default", 202 | args: args{ 203 | str: "foo", 204 | }, 205 | want: logrus.InfoLevel, 206 | }, 207 | 208 | } 209 | for _, tt := range tests { 210 | t.Run(tt.name, func(t *testing.T) { 211 | if got := StringToLogLevel(tt.args.str); got != tt.want { 212 | t.Errorf("StringToLogLevel() = %v, want %v", got, tt.want) 213 | } 214 | }) 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /internal/externalip/clients/clients.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package clients 19 | 20 | const userAgentHeaderKey = "User-Agent" 21 | const maxRetries = 5 22 | -------------------------------------------------------------------------------- /internal/externalip/clients/generic-ip-as-body-svc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package clients 19 | 20 | import ( 21 | "errors" 22 | log "github.com/sirupsen/logrus" 23 | "github.com/viertaxa/cup/internal/types" 24 | "github.com/viertaxa/cup/internal/util" 25 | "io/ioutil" 26 | "net" 27 | "net/http" 28 | "time" 29 | ) 30 | 31 | func GetHttpIpAsBodySvcIP(url string, ua string) (*types.ExternalIP, error) { 32 | httpClient := http.Client{} 33 | req, err := http.NewRequest(http.MethodGet, url, nil) 34 | if err != nil { 35 | return nil, err 36 | } 37 | req.Header.Add(userAgentHeaderKey, ua) 38 | 39 | //IPv4 request 40 | retryDelay := util.NewRetryTimer(3, 600*time.Second) 41 | for tries := 0; tries < maxRetries; tries++ { 42 | if tries != 0 { 43 | log.Warnf("Waiting %d before continuing after a failure.", int(retryDelay.GetRetryDelay().Seconds())) 44 | } 45 | time.Sleep(retryDelay.GetRetryDelay()) 46 | resp, err := httpClient.Do(req) 47 | if err != nil { 48 | log.Errorf("Error encountered getting IP from service.\nError: %s", err) 49 | retryDelay.AttemptFailed() 50 | continue 51 | } else { 52 | body, err := ioutil.ReadAll(resp.Body) 53 | if err != nil { 54 | log.Error("Error decoding the response body.") 55 | retryDelay.AttemptFailed() 56 | continue 57 | } 58 | if resp.StatusCode != 200 { 59 | 60 | log.Errorf("Bad Response from the service.\n%d - %s", resp.StatusCode, body) 61 | retryDelay.AttemptFailed() 62 | continue 63 | } else { 64 | ip := net.ParseIP(string(body)) 65 | if ip != nil { 66 | return &types.ExternalIP{IPv4: ip.String()}, nil 67 | } else { 68 | log.Errorf("Could not parse body as IP.\nBody: %s", body) 69 | retryDelay.AttemptFailed() 70 | continue 71 | } 72 | } 73 | } 74 | } 75 | return nil, errors.New("error getting ip from service, retries exceeded") 76 | } 77 | -------------------------------------------------------------------------------- /internal/externalip/externalip.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package externalip 19 | 20 | import ( 21 | "errors" 22 | log "github.com/sirupsen/logrus" 23 | "github.com/viertaxa/cup/internal/config" 24 | "github.com/viertaxa/cup/internal/externalip/clients" 25 | "github.com/viertaxa/cup/internal/types" 26 | "github.com/viertaxa/cup/internal/util" 27 | ) 28 | 29 | func GetExternalIP(cupInfo types.CupInfo) (*types.ExternalIP, error) { 30 | // Generate a user agent specific to this configuration, but identifiable as CUP 31 | ua := util.GenUserAgent(cupInfo, &config.C) 32 | 33 | var externalIPs []types.ExternalIP 34 | // Loop on provided Simple IP Reporting Services 35 | for _, svc := range config.C.SimpleIPReportServices { 36 | ip, err := clients.GetHttpIpAsBodySvcIP(svc.IPv4ApiBase, ua) 37 | if err != nil { 38 | log.Errorf("Error getting IP from %s.\nError: %s",svc.ServiceName, err) 39 | } 40 | if ip != nil { 41 | externalIPs = append(externalIPs, *ip) 42 | log.Debugf("Got public IP %s from ipify.", ip.IPv4) 43 | } 44 | } 45 | 46 | // Get what the consensus is for the public IP 47 | ipv4, err := getIPConsensus(externalIPs) 48 | if err != nil { 49 | log.Errorf("Error getting public IP\nError: %s", err) 50 | return nil, err 51 | } 52 | 53 | return &types.ExternalIP{IPv4: ipv4}, nil 54 | } 55 | 56 | // Get the consensus for what the public IP is 57 | func getIPConsensus(externalIps []types.ExternalIP) (string, error) { 58 | var extractedIPv4Addresses []string 59 | 60 | // Pull the IPv4 addresses out. 61 | // Note: this is a bit odd for now because my IPv6 setup is broken, and I can't develop/test that part of the tool 62 | for _, externalIp := range externalIps { 63 | extractedIPv4Addresses = append(extractedIPv4Addresses, externalIp.IPv4) 64 | } 65 | 66 | ipConsensus := util.GetStringSliceMode(extractedIPv4Addresses) 67 | if len(ipConsensus) == 1 { 68 | log.Infof("It's agreed, your IP is %s", ipConsensus[0]) 69 | if util.CountOccurrences(extractedIPv4Addresses, ipConsensus[0]) != len(extractedIPv4Addresses) { 70 | log.Warnf("Warning, not everyone agreed, though. only %d of %d thought that was the case.", 71 | util.CountOccurrences(extractedIPv4Addresses, ipConsensus[0]), len(extractedIPv4Addresses)) 72 | } 73 | return ipConsensus[0], nil 74 | } else { 75 | return "", errors.New("could not come to a consensus on what the public IP address is") 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /internal/externalip/externalip_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package externalip 19 | 20 | import ( 21 | "github.com/viertaxa/cup/internal/types" 22 | "testing" 23 | ) 24 | 25 | func Test_getIPConsensus(t *testing.T) { 26 | type args struct { 27 | externalIps []types.ExternalIP 28 | } 29 | tests := []struct { 30 | name string 31 | args args 32 | want string 33 | wantErr bool 34 | }{ 35 | { 36 | name: "Is Consensus", 37 | args: args{ 38 | externalIps: []types.ExternalIP{ 39 | { 40 | IPv4: "1.1.1.1", 41 | }, 42 | { 43 | IPv4: "1.1.1.1", 44 | }, 45 | { 46 | IPv4: "2.2.2.2", 47 | }, 48 | }, 49 | }, 50 | want: "1.1.1.1", 51 | wantErr: false, 52 | }, 53 | { 54 | name: "Isn't Consensus", 55 | args: args{ 56 | externalIps: []types.ExternalIP{ 57 | { 58 | IPv4: "1.1.1.1", 59 | }, 60 | { 61 | IPv4: "3.3.3.3", 62 | }, 63 | { 64 | IPv4: "2.2.2.2", 65 | }, 66 | }, 67 | }, 68 | want: "", 69 | wantErr: true, 70 | }, 71 | { 72 | name: "No values", 73 | args: args{ 74 | externalIps: []types.ExternalIP{}, 75 | }, 76 | want: "", 77 | wantErr: true, 78 | }, 79 | } 80 | for _, tt := range tests { 81 | t.Run(tt.name, func(t *testing.T) { 82 | got, err := getIPConsensus(tt.args.externalIps) 83 | if (err != nil) != tt.wantErr { 84 | t.Errorf("getIPConsensus() error = %v, wantErr %v", err, tt.wantErr) 85 | return 86 | } 87 | if got != tt.want { 88 | t.Errorf("getIPConsensus() got = %v, want %v", got, tt.want) 89 | } 90 | }) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /internal/types/cup-info.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package types 19 | 20 | type CupInfo struct { 21 | Version string 22 | Commit string 23 | BuildType string 24 | } 25 | -------------------------------------------------------------------------------- /internal/types/external-ip.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package types 19 | 20 | type ExternalIP struct { 21 | IPv4 string 22 | } 23 | -------------------------------------------------------------------------------- /internal/util/file.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import "os" 21 | 22 | func CheckFileExists(path string) (bool, error) { 23 | // Attempt to get file stats on the file. 24 | if _, err := os.Stat(path); os.IsNotExist(err) { 25 | // There was an error getting the file stats, but that error was that the file isn't there. 26 | return false, nil 27 | } else if err != nil { 28 | // There was some other error getting the file stats, but the file may be there. 29 | return false, err 30 | } else { 31 | // The file was there and we were able to get the stats on it 32 | return true, nil 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /internal/util/retry-timer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "math" 22 | "time" 23 | ) 24 | 25 | type RetryTimer struct { 26 | attemptNo int 27 | factor int 28 | max time.Duration 29 | } 30 | 31 | func NewRetryTimer(backoffFactor int, maxWaitTime time.Duration) RetryTimer { 32 | return RetryTimer{ 33 | attemptNo: 0, 34 | factor: backoffFactor, 35 | max: maxWaitTime, 36 | } 37 | } 38 | 39 | func (r *RetryTimer) GetRetryDelay() time.Duration { 40 | if r.attemptNo == 0 { 41 | return time.Duration(0) 42 | } 43 | delay := time.Duration(int64(math.Pow(float64(r.attemptNo), float64(r.factor)))) * time.Second 44 | return GetSmallerDuration(r.max, delay) 45 | } 46 | 47 | func (r *RetryTimer) AttemptFailed() { 48 | r.attemptNo++ 49 | } 50 | -------------------------------------------------------------------------------- /internal/util/retry-timer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "testing" 22 | "time" 23 | ) 24 | 25 | func TestNewRetryTimer(t *testing.T) { 26 | timer := NewRetryTimer(3, 600*time.Second) 27 | 28 | if timer.attemptNo != 0 { 29 | t.Errorf("New timer instantiated with intial counter other than 0. Actual value: %d", timer.attemptNo) 30 | } 31 | } 32 | 33 | func TestGetRetryDelay(t *testing.T) { 34 | timer := NewRetryTimer(3, 600*time.Second) 35 | 36 | // RetryDelay should be 0 to begin with. 37 | if timer.GetRetryDelay() != time.Duration(0) { 38 | t.Errorf("Timer initial retry delay should be 0. Actual value in seconds: %d", 39 | timer.GetRetryDelay()/time.Second) 40 | } 41 | 42 | // with a factor of 3 and a max time of 600s, we should see retry delays of 1, 8, 27, 64, 125, 216, 343, 512, 600 43 | 44 | expected := map[int]time.Duration{ 45 | 0: 0 * time.Second, 46 | 1: 1 * time.Second, 47 | 2: 8 * time.Second, 48 | 3: 27 * time.Second, 49 | 4: 64 * time.Second, 50 | 5: 125 * time.Second, 51 | 6: 216 * time.Second, 52 | 7: 343 * time.Second, 53 | 8: 512 * time.Second, 54 | 9: 600 * time.Second, 55 | 10: 600 * time.Second, 56 | 11: 600 * time.Second, 57 | 12: 600 * time.Second, 58 | 13: 600 * time.Second, 59 | 14: 600 * time.Second, 60 | } 61 | 62 | for tr := 0; tr < 15; tr++ { 63 | if timer.GetRetryDelay() != expected[tr] { 64 | t.Errorf("Timer retry delay should be %d seconds for attempt %d. Actual value in seconds: %d", 65 | expected[tr]/time.Second, tr+1, timer.GetRetryDelay()/time.Second) 66 | } 67 | timer.AttemptFailed() 68 | } 69 | } 70 | 71 | func TestAttemptFailed(t *testing.T) { 72 | timer := NewRetryTimer(3, 600*time.Second) 73 | timer.AttemptFailed() 74 | if timer.attemptNo != 1 { 75 | t.Errorf("Timer incrimented once did not have counter of 1. Actual value: %d", timer.attemptNo) 76 | } 77 | } -------------------------------------------------------------------------------- /internal/util/stdin.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import "os" 21 | 22 | func CheckIsStdin() (bool,error){ 23 | // Grab stdin and check the properties of it 24 | if fileInfo, err := os.Stdin.Stat(); err != nil { 25 | // We weren't able to grab stdin for some reason. 26 | return false, err 27 | } else { 28 | // Since we were able to grab stdin, do the actual check. 29 | // Do a binary AND on the ModeCharDevice bit. If it's 0/false, return false. 30 | if (fileInfo.Mode() & os.ModeCharDevice) == 0 { 31 | return false, nil 32 | } else { 33 | return true, nil 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /internal/util/stringslice.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | //StringSliceContains returns `true` if the passed in string slice contains the 21 | //passed in string, otherwise returns false. 22 | func StringSliceContains(s []string, str string) bool { 23 | for _, v := range s { 24 | if v == str { 25 | return true 26 | } 27 | } 28 | return false 29 | } 30 | 31 | func GetStringSliceMode(sl []string) []string { 32 | if len(sl) == 0 { 33 | return nil 34 | } 35 | valueMap := make(map[string]int) 36 | for _, s := range sl { 37 | valueMap[s]++ 38 | } 39 | 40 | var maxFrequency int 41 | for _, v := range valueMap { 42 | if v > maxFrequency { 43 | maxFrequency = v 44 | } 45 | } 46 | 47 | var maxValues []string 48 | for k, v := range valueMap { 49 | if v == maxFrequency { 50 | maxValues = append(maxValues, k) 51 | } 52 | } 53 | return maxValues 54 | } 55 | 56 | func CountOccurrences(sl []string, s string) int { 57 | if len(sl) == 0 { 58 | return 0 59 | } 60 | 61 | var occurrences int 62 | for _, v := range sl { 63 | if v == s { 64 | occurrences++ 65 | } 66 | } 67 | return occurrences 68 | } 69 | -------------------------------------------------------------------------------- /internal/util/stringslice_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "reflect" 22 | "sort" 23 | "testing" 24 | ) 25 | 26 | func TestCountOccurrences(t *testing.T) { 27 | type args struct { 28 | sl []string 29 | s string 30 | } 31 | tests := []struct { 32 | name string 33 | args args 34 | want int 35 | }{ 36 | { 37 | name: "No Occurrences", 38 | args: args{ 39 | sl: []string{"bar", "baz"}, 40 | s: "foo", 41 | }, 42 | want: 0, 43 | }, 44 | { 45 | name: "1 Occurrence", 46 | args: args{ 47 | sl: []string{"bar", "baz", "foo"}, 48 | s: "foo", 49 | }, 50 | want: 1, 51 | }, 52 | { 53 | name: "3 Occurrences", 54 | args: args{ 55 | sl: []string{"foo", "bar", "foo", "baz", "foo"}, 56 | s: "foo", 57 | }, 58 | want: 3, 59 | }, 60 | } 61 | for _, tt := range tests { 62 | t.Run(tt.name, func(t *testing.T) { 63 | if got := CountOccurrences(tt.args.sl, tt.args.s); got != tt.want { 64 | t.Errorf("CountOccurrences() = %v, want %v", got, tt.want) 65 | } 66 | }) 67 | } 68 | } 69 | 70 | func TestGetStringSliceMode(t *testing.T) { 71 | type args struct { 72 | sl []string 73 | } 74 | tests := []struct { 75 | name string 76 | args args 77 | want []string 78 | }{ 79 | { 80 | name: "All the same value", 81 | args: args{ 82 | sl: []string{"foo", "foo", "foo"}, 83 | }, 84 | want: []string{"foo"}, 85 | }, 86 | { 87 | name: "Two different values with winner", 88 | args: args{ 89 | sl: []string{"foo", "foo", "bar"}, 90 | }, 91 | want: []string{"foo"}, 92 | }, 93 | { 94 | name: "All different values", 95 | args: args{ 96 | sl: []string{"foo", "bar", "baz"}, 97 | }, 98 | want: []string{"foo", "bar", "baz"}, 99 | }, 100 | { 101 | name: "Two winners with one loser", 102 | args: args{ 103 | sl: []string{"foo", "foo", "bar", "bar", "baz"}, 104 | }, 105 | want: []string{"foo", "bar"}, 106 | }, 107 | } 108 | for _, tt := range tests { 109 | t.Run(tt.name, func(t *testing.T) { 110 | got := GetStringSliceMode(tt.args.sl) 111 | sort.Strings(got) 112 | sort.Strings(tt.want) 113 | if !reflect.DeepEqual(got, tt.want) { 114 | t.Errorf("GetStringSliceMode() = %v, want %v", got, tt.want) 115 | } 116 | }) 117 | } 118 | } 119 | 120 | func TestStringSliceContains(t *testing.T) { 121 | type args struct { 122 | s []string 123 | str string 124 | } 125 | tests := []struct { 126 | name string 127 | args args 128 | want bool 129 | }{ 130 | { 131 | name: "Does contain", 132 | args: args{ 133 | s: []string{"foo", "bar", "baz"}, 134 | str: "bar", 135 | }, 136 | want: true, 137 | }, 138 | { 139 | name: "Does not contain", 140 | args: args{ 141 | s: []string{"foo", "bar", "baz"}, 142 | str: "bang", 143 | }, 144 | want: false, 145 | }, 146 | { 147 | name: "Does not contain (wrong case)", 148 | args: args{ 149 | s: []string{"foo", "Bar", "baz"}, 150 | str: "bar", 151 | }, 152 | want: false, 153 | }, 154 | } 155 | for _, tt := range tests { 156 | t.Run(tt.name, func(t *testing.T) { 157 | if got := StringSliceContains(tt.args.s, tt.args.str); got != tt.want { 158 | t.Errorf("StringSliceContains() = %v, want %v", got, tt.want) 159 | } 160 | }) 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /internal/util/time.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import "time" 21 | 22 | func GetSmallerDuration(d1, d2 time.Duration) time.Duration { 23 | if d1-d2 < 0 { 24 | return d1 25 | } else { 26 | return d2 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /internal/util/time_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "testing" 22 | "time" 23 | ) 24 | 25 | func TestGetSmallerDuration(t *testing.T) { 26 | type args struct { 27 | d1 time.Duration 28 | d2 time.Duration 29 | } 30 | tests := []struct { 31 | name string 32 | args args 33 | want time.Duration 34 | }{ 35 | { 36 | name: "Different Times", 37 | args: args{d1: time.Second * 1, d2: time.Second * 2}, 38 | want: time.Second * 1, 39 | }, 40 | { 41 | name: "Same Times", 42 | args: args{d1: time.Second * 2, d2: time.Second * 2}, 43 | want: time.Second * 2, 44 | }, 45 | } 46 | for _, tt := range tests { 47 | t.Run(tt.name, func(t *testing.T) { 48 | if got := GetSmallerDuration(tt.args.d1, tt.args.d2); got != tt.want { 49 | t.Errorf("GetSmallerDuration() = %v, want %v", got, tt.want) 50 | } 51 | }) 52 | } 53 | } -------------------------------------------------------------------------------- /internal/util/user-agent.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "crypto/sha256" 22 | "encoding/json" 23 | "fmt" 24 | "github.com/viertaxa/cup/internal/config" 25 | "github.com/viertaxa/cup/internal/types" 26 | ) 27 | 28 | const ConfigBytesStandin = "I am but a poor cup executable that was unable to marshal my config." 29 | 30 | func GenUserAgent(cupInfo types.CupInfo, cupConfig *config.CupConfig) string { 31 | hasher := sha256.New() 32 | configBytes, err := json.Marshal(cupConfig) 33 | if err != nil { 34 | hasher.Write([]byte(ConfigBytesStandin)) 35 | } else { 36 | hasher.Write(configBytes) 37 | } 38 | shaHash := hasher.Sum(nil) 39 | 40 | return fmt.Sprintf("cup/%s-%s (%s) instance/%x", 41 | cupInfo.Version, 42 | cupInfo.Commit, 43 | cupInfo.BuildType, 44 | shaHash) 45 | } 46 | -------------------------------------------------------------------------------- /internal/util/user-agent_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "github.com/viertaxa/cup/internal/config" 22 | "github.com/viertaxa/cup/internal/types" 23 | "testing" 24 | ) 25 | 26 | func TestGenUserAgent(t *testing.T) { 27 | type args struct { 28 | cupInfo types.CupInfo 29 | cupConfig *config.CupConfig 30 | } 31 | tests := []struct { 32 | name string 33 | args args 34 | want string 35 | }{ 36 | { 37 | name: "Unable to marshal config", 38 | args: args{ 39 | cupInfo: types.CupInfo{ 40 | Version: "1.0.0", 41 | Commit: "deadbeef", 42 | BuildType: "testing", 43 | }, 44 | cupConfig: nil, 45 | }, 46 | want: "cup/1.0.0-deadbeef (testing) instance/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b", 47 | }, 48 | { 49 | name: "Valid Config", 50 | args: args{ 51 | cupInfo: types.CupInfo{ 52 | Version: "1.0.0", 53 | Commit: "deadbeef", 54 | BuildType: "testing", 55 | }, 56 | cupConfig: &config.CupConfig{ 57 | LogLevel: "trace", 58 | API: config.ApiConfig{ 59 | ApiBaseUrl: "https://foo.bar/", 60 | ApiKey: "dfsadsdsafdfsdfa", 61 | }, 62 | Domains: []config.DomainConfig{ 63 | { 64 | Domain: "foo.com", 65 | Hosts: []string{ 66 | "bar", 67 | }, 68 | }, 69 | }, 70 | SimpleIPReportServices: []config.SimpleIPReporterConfig{ 71 | { 72 | IPv4ApiBase: "https://ip.foo.bar", 73 | ServiceName: "FooBarIPReporter", 74 | }, 75 | }, 76 | }, 77 | }, 78 | want: "cup/1.0.0-deadbeef (testing) instance/7b80fdc9cb0a664c2333cc41bb8875c5821fe1d7b4257a26c13661c363368f99", 79 | }, 80 | } 81 | for _, tt := range tests { 82 | t.Run(tt.name, func(t *testing.T) { 83 | if got := GenUserAgent(tt.args.cupInfo, tt.args.cupConfig); got != tt.want { 84 | t.Errorf("GenUserAgent() = %v, want %v", got, tt.want) 85 | } 86 | }) 87 | } 88 | } -------------------------------------------------------------------------------- /internal/util/user-prompt.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "bufio" 22 | "fmt" 23 | "os" 24 | "strings" 25 | ) 26 | 27 | func AskUserForString(question string, defaultValue string) (string, error) { 28 | reader := bufio.NewReader(os.Stdin) 29 | 30 | fmt.Printf("%s [%s]:", question, defaultValue) 31 | 32 | response, err := reader.ReadString('\n') 33 | if err != nil { 34 | return "", err 35 | } 36 | if strings.TrimSpace(response) == "" { 37 | return defaultValue, nil 38 | } 39 | return strings.TrimSpace(response), nil 40 | } 41 | 42 | func AskUserForBool(question string, defaultValue bool) (bool, error) { 43 | var defaultWord string 44 | var trueResponses = []string{"y", "yes", "t", "true"} 45 | switch defaultValue { 46 | case true: 47 | defaultWord = "Y" 48 | case false: 49 | defaultWord = "N" 50 | } 51 | 52 | reader := bufio.NewReader(os.Stdin) 53 | 54 | fmt.Printf("%s [%s]:", question, defaultWord) 55 | response, err := reader.ReadString('\n') 56 | if err != nil { 57 | return false, err 58 | } 59 | if strings.TrimSpace(response) == "" { 60 | return defaultValue, nil 61 | } 62 | if StringSliceContains(trueResponses, strings.ToLower(strings.TrimSpace(response))) { 63 | return true, nil 64 | } 65 | return false, nil 66 | } 67 | -------------------------------------------------------------------------------- /internal/util/viper.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "bytes" 22 | "encoding/json" 23 | "github.com/spf13/viper" 24 | ) 25 | 26 | // LoadViperConfigFromStruct back-populates viper with the content of a struct. 27 | func LoadViperConfigFromStruct(cfg interface{}) error { 28 | cfgJsonBytes, err := json.Marshal(cfg) 29 | if err != nil { 30 | return err 31 | } 32 | 33 | viper.SetConfigType("json") 34 | err = viper.ReadConfig(bytes.NewReader(cfgJsonBytes)) 35 | if err != nil { 36 | return err 37 | } 38 | 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /internal/util/yaml.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import "gopkg.in/yaml.v2" 21 | 22 | // PrettyPrintSYaml generates a pretty-ish YAML string 23 | func PrettyPrintSYaml(t interface{}) (string, error) { 24 | document, err := yaml.Marshal(t) 25 | if err != nil { 26 | return "", err 27 | } 28 | return string(document), nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/util/yaml_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Taylor Vierrether 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package util 19 | 20 | import ( 21 | "github.com/viertaxa/cup/internal/config" 22 | "strings" 23 | "testing" 24 | ) 25 | 26 | func TestPrettyPrintSYaml(t *testing.T) { 27 | type args struct { 28 | t interface{} 29 | } 30 | tests := []struct { 31 | name string 32 | args args 33 | want string 34 | wantErr bool 35 | }{ 36 | { 37 | name: "Print a sample config", 38 | args: args{ 39 | t: config.CupConfig{ 40 | LogLevel: "trace", 41 | API: config.ApiConfig{ 42 | ApiBaseUrl: "https://foo.bar/", 43 | ApiKey: "dfsadsdsafdfsdfa", 44 | }, 45 | Domains: []config.DomainConfig{ 46 | { 47 | Domain: "foo.com", 48 | Hosts: []string{ 49 | "bar", 50 | }, 51 | }, 52 | }, 53 | SimpleIPReportServices: []config.SimpleIPReporterConfig{ 54 | { 55 | IPv4ApiBase: "https://ip.foo.bar", 56 | ServiceName: "FooBarIPReporter", 57 | }, 58 | }, 59 | }, 60 | }, 61 | want: ` 62 | loglevel: trace 63 | api: 64 | apibaseurl: https://foo.bar/ 65 | apikey: dfsadsdsafdfsdfa 66 | domains: 67 | - domain: foo.com 68 | hosts: 69 | - bar 70 | simpleipreportservices: 71 | - ipv4apibase: https://ip.foo.bar 72 | servicename: FooBarIPReporter`, 73 | wantErr: false, 74 | }, 75 | } 76 | for _, tt := range tests { 77 | t.Run(tt.name, func(t *testing.T) { 78 | got, err := PrettyPrintSYaml(tt.args.t) 79 | if (err != nil) != tt.wantErr { 80 | t.Errorf("PrettyPrintSYaml() error = %v, wantErr %v", err, tt.wantErr) 81 | return 82 | } 83 | if strings.TrimSpace(got) != strings.TrimSpace(tt.want) { 84 | t.Errorf("PrettyPrintSYaml() got = %v, want %v", got, tt.want) 85 | } 86 | }) 87 | } 88 | } 89 | --------------------------------------------------------------------------------