Commit Graph
128 Commits
Author SHA1 Message Date
Louis Ruch 4ed4575802 chore(fmt): make fmt 2022-02-16 15:52:37 -08:00
Todd 7ee1f74388 fix(hostsets/plugin): Only delete preferred endpoints when there are preferred endpoints to delete. (#1865) 2022-02-16 16:12:34 -07:00
Justen Walker 6166d2240f bug(plugin): Fix incorrect use of WithIpAddrs in Repository.Endpoints (#1849)
When creating the options for the preferencer, this used WithIpAddrs for both the host addresses and also DNS names. This causes errors when a host contains DNS names that are not IP addresses (ie: whenever dns names are present).

This change will:
- Replace WithIpAddrs with WithDNSNames option for DNS Names when constructing options for the preferencer.
- Add a test which includes a DNS name to prevent regressions

Fixes #1848
2022-02-10 13:59:35 -07:00
Louis Ruch aaaf0241ff bug(host): Fix sync job failure blocking other set syncs (#1841)
During the plugin_host_set_sync job, a single set failing to  sync
can cause all following syncs to fail.
2022-02-04 12:02:37 -08:00
Haotian fa00a06bef feat(host): Add host set information to static host (#1828)
* feat(host): Add host set information to static host

Updates LookupHost and ListHost API to include sets a static host is part of, as like with plugin hosts.

* test: updated TestList_Plugin and TestCrud to be more consistent under race conditions
2022-02-01 10:06:13 -08:00
Louis Ruch c4506ec743 feat(scheduler): Add support for run now option 2022-01-13 11:51:53 -08:00
Jim 591ec476e7 refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)
* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
2022-01-05 14:38:38 -05:00
Chris Marchesi bf18555d5e internal/host/plugin: remove custom queries for secrets (#1676)
* internal/host/plugin: remove custom queries for secrets

This removes the custom queries for host catalog secrets, now that #1658
has been merged.

It also does a lot of cleanup surrounding the related oplog entries,
using db.WithOplog natively.

* Simplify conflict actions by replacing SetColumnValues with SetColumns

* Remove unused oplog method
2021-12-07 12:38:34 -08:00
Chris MarchesiandTodd 84febd9983 internal/host/plugin: ensure UpdateCatalog triggers updates for sets (#1736)
* internal/host/plugin: ensure UpdateCatalog triggers updates for sets

This ensures that attribute updates to a host catalog triggers an update
to any of its downstream host sets. This ensures that updates to
elements that affect a host set, such as the region a host catalog is
configured for, take effect immediately instead of requiring a wait of
long as 10m after an update.

* Add WithNextRunIn to test sync job

This is to ensure it doesn't run right away when added. This ensures
that we can accurately test *when* the job is set to run immediately.

* Update internal/host/plugin/repository_host_catalog.go

Co-authored-by: Todd <T.Alan.Knight@gmail.com>

* Change TestRepository_UpdateCatalog_SyncSets to check next run time, not wait for run

* Remove explicit version increment and instead rely on implicit increment

* Fix lanuage for rows updated check when flagging host sets for sync

* remove errant non-zero check when looping over the thing we're checking

* remove scheduler start line from TestRepository_UpdateCatalog_SyncSets

Co-authored-by: Todd <T.Alan.Knight@gmail.com>
2021-11-30 14:37:06 -08:00
Jeff Mitchell 5417cc5cb0 Fix setting nil attributes on host sets (#1746)
This is the analogue of #1743 but for host sets
2021-11-28 15:20:46 -05:00
Jeff Mitchell 1c39691023 Fix setting host catalog attributes to nil (#1743)
Internally attributes are not allowed to be the null value. However, as
currently implemented, this then breaks our normal model of sending an
explicit `null` in the JSON to reset/clear a field. This is a problem
because the CLI doesn't have a way to say "set this but to empty"
without a lot of hoops, and causes some issues for API users and TF as
well.

This changes PatchBytes and PatchStruct to return an empty value (or
marshaled empty value in the case of PatchBytes) if the source is null
or empty. In the host catalog update function we then always set this
value if it's in the db mask (removing the nil check). Together this
means a null value ends up coming out as an empty value (and thus valid
for the DB) from PatchStruct/PatchBytes, and our API translation
function already returns nothing for attributes if the length of the
fields are zero.
2021-11-26 16:58:19 -05:00
Chris Marchesi 9e976cb4ae internal/host/plugin: Fix TestUpdateSet (#1735)
Now asserts on error on the last lookup check and removes the plugin
lookup since we're not asserting on that.
2021-11-22 13:42:19 -08:00
Todd 18de3653f5 Set sync job still syncs when plugin reports no hosts in sets (#1726)
* Allow the set sync job to sync when no hosts are returned by the sync job.
2021-11-17 13:32:23 -07:00
Jeff MitchellandJim 866bfceefc Add secrets_hmac to host catalog output (#1712)
Co-authored-by: Jim <jlambert@hashicorp.com>
2021-11-16 18:54:38 -05:00
Jeff Mitchell 8110e0eab3 Increment version of host during updates (#1707)
Currently host does not use a version, which means it's not protected
against race conditions of either itself or its value objects. This adds
and plumbs through version to ensure that if a host or its value objects
change that they are not going to be affected by a race condition.
2021-11-15 12:22:39 -05:00
Jeff Mitchell b3fd23863f Add external ID to host output (#1705)
This also fixes a bug if no hosts were returned where the job would run
over and over in a loop, and some other cleanup.
2021-11-13 17:18:20 -05:00
Todd 78dc6cf370 OnConflict constraints for adding host ip and dns names in upsertHosts (#1700)
* Ignore constraint violations when adding ip addresses and dns addresses that already exist.
2021-11-12 16:17:43 -07:00
Todd 5d2b0e94aa Update sync interval seconds field. (#1698)
* Update sync interval seconds field.

* If the sync interval was updated, schedule the next sync job wakeup immediately.

* Calculate the next sync time for the scheduler should wake up if we only updated the sync interval.
2021-11-12 14:55:22 -07:00
Todd b16ce175e5 Fix secrets clearing bug in update. Changes to update count behavior for catalogs (#1691)
* Fix secret clearing bug in update.  Always return 1 catalog updated if we can find a catalog w/ a matching version.
2021-11-12 09:46:40 -07:00
Todd 5cfcc41f00 Fix bug for adding preferred endpoint when non existed prior. (#1692) 2021-11-12 09:04:48 -07:00
Todd Knight f41bceda83 Merge from main and make gen 2021-11-12 08:57:10 -07:00
Todd 61f9d1f6af Add update set handler and sdk functionality (#1684) 2021-11-11 14:32:15 -07:00
Todd 29b4537d3b Reference PreferredEndpoints by top level struct name (#1688)
* Reference PreferredEndpoints by top level struct name instead of embedded proto GetPreferredEndpoint method.

Reorganize the sql files a little.

* Make PreferredEndpoints replayable. Test refactoring to remove variables that persist across test calls. DeleteItems instead of trying to use WithWhere.
2021-11-11 13:51:52 -07:00
Jeff Mitchell 30e9f944a2 Add sync interval to host sets (#1680)
This adds a parameter to host sets allowing the sync interval to be
user-specified on a per-host-set basis. A value of -1 disables syncing;
a value of null uses the current default.
2021-11-11 11:28:08 -05:00
Todd Knight dba7c6b531 Fix value of op constant for syncSets 2021-11-11 08:29:13 -07:00
Chris Marchesi c2cd6febca internal/host/plugin: add UpdateSet (#1686)
* internal/host/plugin: add UpdateSet

This adds the UpdateSet repository function.

UpdateSet runs the OnUpdateSet plugin call within the transaction as per
the changes in #1683.

The plugin call returns the updated set, the hosts in the set, the rows
updated, and any error.

* Ensure that attributes can be cleared by supplying a full null

* move version increment to the end and track perferred endpoint update separately

* move plugin call to end of transaction

* only clone returned set once, and move host fetch call out of transaction

* Request a sync when attributes are updated

* Add test to assert that old preferred endpoints are being removed correctly
2021-11-10 17:08:42 -08:00
Todd 2229d1a819 Call OnCreate or OnUpdate on the plugin after db constraints are checked (#1683)
* Only call the Plugin at create/update time after the db has been partially updated. This allows more constraints to be checked prior to calling the plugin.
2021-11-10 09:04:29 -07:00
Todd 050553ffcf Add update catalog support for plugin based catalogs in handler and go sdk (#1673)
* Create catalog service handler for updating plugin.  Add tests for handler and run make fmt. Silently drop attributes where the value is nil when creating the catalog or set.
2021-11-09 14:42:48 -07:00
Chris Marchesi 157f1a091b internal/host/plugin: add update catalog test for empty/same description (#1672)
This is to mainly get coverage on the empty description case, but it
follows the same logic as the "update name to same" test.
2021-11-05 14:05:52 -07:00
Chris MarchesiandTodd 0670e272e3 internal/host/plugin: Add UpdateCatalog (#1634)
* internal/host/plugin: Add UpdateCatalog

This adds support for updating plugin-based host catalogs.

The workflow is:

* The existing catalog is fetched.
* Any attribute changes are patched against it, along with other changes
  such as name and description.
* Both the existing catalog, and the state of the catalog as it will
  exist post-update, along with any persisted secrets, are sent to the
  plugin via an OnUpdateCatalog request.

Upon success, the following is done:

* The record is updated if non-secret updates need to be made.
* Secrets are updated if they still exist.
* If an empty secret set was sent back, secrets are instead deleted.
* If the secrets field was instead null, secret update is skipped
  altogether.

There has also been a lot of helper code added to the tests to help make
the update tests more readable and reduce boilerplate. While the create
tests have not been updated to use these new helpers, it might be a good
idea to do so for consistency.

* move secret/persisted state closer to plugin call

* Update internal/host/plugin/repository_host_catalog.go

Co-authored-by: Todd <T.Alan.Knight@gmail.com>

* Update internal/host/plugin/repository_host_catalog_test.go

Co-authored-by: Todd <T.Alan.Knight@gmail.com>

* move all test helpers for UpdateCatalog inline

* WIP - transparent attributes struct/wire conversion

* Revert "WIP - transparent attributes struct/wire conversion"

This reverts commit 31af1b1b7e535119aa23bd0aa936da1a80eb5aa2.

* deal with multiple attribute masks

* Note TODO for upsertQuery for HostCatalogSecret

* add version check guard

* Update internal/host/plugin/host_catalog_secret.go

Co-authored-by: Todd <T.Alan.Knight@gmail.com>

* remove redundant JIRA reference

* don't separate number of updated catalogs and secrets

* increment version when secrets is the only thing being updated

* add another test for updating both catalog and secrets at once

* correct comment for mock plugin manager section

* add first-part path matching for secrets

* update plugin lookup error to return errors.Internal

* only add name/description to plugin request if they are non-empty

* update duplicate tests to use two project scopes

* remove unused test checks

* return plugin record along with host catalog in update

* move away from using passed in catalog after patching newCatalog

* use t.Cleanup() instead of defer

Co-authored-by: Todd <T.Alan.Knight@gmail.com>
2021-11-05 10:43:58 -07:00
Chris Marchesi 165cc5ef1b fix ineffectual assignment to err in DeleteCatalog (#1664)
Was being caught by my linters. Looks like the error wasn't being
checked after getCatalog.
2021-11-04 17:09:32 -07:00
Chris Marchesi 1bc9a07316 populate correct field for host catalog secret (#1661) 2021-11-03 13:16:45 -07:00
Todd 808b986834 Read and List Plugin based Hosts (#1655)
* Add ability to read and list hosts.  Tests to follow.

* Add tests for reading and listing as well as validation checks to not modify hosts.

* Add IpAddress and DnsNames to the api resource.  Populate the plugin info.

* Adding go sdk tests for reading and listing hosts and ensuring update and deleting is disallowed.
2021-11-02 14:06:20 -07:00
Todd 1312628a1e Add plugin set sync and orphaned host cleanup jobs (#1647) 2021-11-01 09:07:56 -07:00
Jeff Mitchell 5e782b6ecc Update view to return host IDs in a set on set lookup (#1646)
This removes the optional call to the plugin.
2021-10-29 15:35:06 -04:00
Todd 6eba8a4787 Lookups Catalogs and Persisted data together (#1643)
* Fixed a number of TODOs:
1. Create a catalog/persisted data view.
2. Pass all sets to the plugin when deleting a catalog.
2021-10-28 12:46:42 -07:00
Jeff MitchellandTodd b64761f38f Add repository and functions around plugin host set membership (#1629)
Co-authored-by: Todd <T.Alan.Knight@gmail.com>
2021-10-28 10:09:43 -04:00
Todd 8795b20fe2 Delete actions for plugin based catalogs and sets (#1622)
* Add ability to delete plugin based host catalogs and host sets

* Add plugin host catalog and set tests for API.
2021-10-25 09:37:05 -07:00
Jeff Mitchell 804cb22699 Remove priority values from host_ip_address/host_dns_name (#1633) 2021-10-22 15:45:46 -04:00
23baaac36b Add DB changes for host, set members, and host addresses for plugins. (#1584)
* Add DB changes for host, set members, and host addresses for plugins.

* Add priority, address review feedback, update tests, naming, protos

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
2021-10-20 12:20:28 -07:00
Jeff Mitchell 70e6536919 Swap server interface for client (#1580) 2021-10-07 11:56:39 -04:00
Jeff Mitchell 098c3e1f22 Update sdk dep from proper branch and fix building 2021-10-05 21:18:42 -04:00
Jeff Mitchell 158ab09952 Merge branch 'main' into plugin-hostcatalogs 2021-10-05 16:27:28 -04:00
Jim 8d6dee09a9 refact: Add db.DB wrapper and refact all test fixtures to use it. (#1535)
* refact: Changes required for gorm v2

* refact: Add db.DB wrapper and refact all test fixtures to use it

Stop leaking the gorm abstraction within our unit tests.

* refact: Migrate direct calls to pq to pgx driver

The refactor will remove the remaining direct dependencies on
the pq driver which has been deprecated in favor of the pgx
driver.

It includes the addition of common.SqlOpen which is a wrapper around
sql.Open, which is needed to deal with the driver name changing from
"postgres" to "pgx" but in our code base the dialect and driver are
synonyms.
2021-09-30 09:17:27 -04:00
Jim 136ac00b49 refact: Changes required for gorm v2 (#1528) 2021-09-30 08:47:34 -04:00
Todd e11a481256 Register Azure and AWS at controller start up (#1570)
* Register Plugins.

* Pass catalogs and persisted data when listing hosts for host sets.  Register azure plugin at startup if not present.
2021-09-29 15:46:42 -07:00
Jeff Mitchell 8b1ca4b0b8 Add host IDs to plugin host sets read response (#1568)
This also includes tweaks here and there within the service and repos.
2021-09-28 16:19:32 -04:00
Jeff MitchellandTodd 7d71618df0 Add more host-catalog and host-set CLI support (#1567)
Add more host-catalog and host-set CLI support

Co-authored-by: Todd <T.Alan.Knight@gmail.com>
2021-09-28 09:40:12 -04:00
Jeff Mitchell a834a14785 Add attribute flag building and parsing (#1562)
This adds a few command sketches but that's not the main point of the PR
and filling those out will come in a different PR. This adds a new flag
type that can combine inputs to a single target slice, retaining the
ability to distinguish where it came from but also keep ordering across
different flag names. It also implements a function that does the
heuristic parsing with fallback.
2021-09-26 11:48:43 -04:00
ToddandJeff Mitchell 14cc97b645 Add authorize session for plugin based host sets. (#1559)
Added a new Endpoint struct at the top level host package level to capture host, set, and address chosen.
Temporarily add a host_plugin_host table to capture the hosts returned by the plugins.  This ensures the datawarehouse is able to query the table to decide what host was chosen.  The view used to update the datawarehouse dimension table provides rows with host set ids and hosts which are not in that host set.  This is ok since the function which updates the dimension table provides the host set and host id chosen so that relationship doesn't need to be captured in the view itself.

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-09-26 11:17:21 -04:00