-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] POC for using ETag to verify screens config version (#234)
* Fix default config bug * Start returning etag when getting config and add put operation * Add and delete logic * credo * Update lib/screenplay/config/config.ex Co-authored-by: Christian Maddox <[email protected]> * Remove edit action * Return more specific error messages --------- Co-authored-by: Christian Maddox <[email protected]>
- Loading branch information
Showing
5 changed files
with
109 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
defmodule Screenplay.Config.PermanentConfig do | ||
@moduledoc false | ||
alias Screenplay.Config.S3Fetch | ||
|
||
def add_new_screen do | ||
@spec add_new_screen(binary(), map(), binary()) :: | ||
{:error, :etag_mismatch | :config_not_fetched | :config_not_written} | :ok | ||
def add_new_screen(screen_id, screen, etag) do | ||
case get_current_config(etag) do | ||
{:ok, config} -> | ||
config | ||
|> Map.put(screen_id, Jason.decode!(screen)) | ||
|> S3Fetch.put_screens_config() | ||
|
||
error -> | ||
error | ||
end | ||
end | ||
|
||
def edit_screen do | ||
@spec delete_screen(binary(), binary()) :: | ||
{:error, :etag_mismatch | :config_not_fetched | :config_not_written} | :ok | ||
def delete_screen(screen_id, etag) do | ||
case get_current_config(etag) do | ||
{:ok, config} -> | ||
config | ||
|> Map.delete(screen_id) | ||
|> S3Fetch.put_screens_config() | ||
|
||
error -> | ||
error | ||
end | ||
end | ||
|
||
def delete_screen do | ||
defp get_current_config(etag) do | ||
case S3Fetch.get_screens_config() do | ||
{:ok, config, ^etag} -> | ||
{:ok, config} | ||
|
||
:error -> | ||
{:error, :config_not_fetched} | ||
|
||
_ -> | ||
{:error, :etag_mismatch} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters