fastlyctl 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/fastlyctl/commands/dictionary.rb +55 -1
- data/lib/fastlyctl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3ff6e61fc266fedb6875186c971f06296b055d2bb02a8e9c90fd432086c16df
|
4
|
+
data.tar.gz: c2f3e3245be9b049184bc72baae907009773d1f89ba5c69aba669f195c397305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 615b36475eff2a4511a0219823ef6aff66be34a1e03edce842651f951f225ab4473ca7eaf70afe99a7bbfb54fafb0a0d61ecc65ea77a45f975cf4b8e989a9714
|
7
|
+
data.tar.gz: ca36f9bcf1ad670c10ee70addaa7165f7efeb8c5260c1da78d3f6870633f8ac4f284652b8a709f6d2bceef55305927d42fbe974b8918c9be1993d8c8618c8038
|
data/README.md
CHANGED
@@ -137,11 +137,13 @@ Available Actions:
|
|
137
137
|
* upsert: Inserts a new item into a dictionary. If the item exists, its value will be updated.
|
138
138
|
* remove: Removes an item from a dictionary.
|
139
139
|
* list_items: Lists all items in a dictionary.
|
140
|
+
* sync: Synchronizes a dictionary with a comma separated list of key/value pairs. Will create, delete, or update keys as needed. Separate keys and values with `=` or `:`.
|
140
141
|
* bulk_add: Adds multiple items to a dictionary. See [this documentation](https://docs.fastly.com/api/config#dictionary_item_dc826ce1255a7c42bc48eb204eed8f7f) for information on the format.
|
141
142
|
|
142
143
|
Flags:
|
143
144
|
* --s: The service ID to use. Current working directory is assumed.
|
144
145
|
* --v: The version to use. Latest writable version is assumed.
|
146
|
+
* --wo: When used with `create`, flags the dictionary as write-only.
|
145
147
|
|
146
148
|
### diff
|
147
149
|
|
@@ -6,9 +6,11 @@ module FastlyCTL
|
|
6
6
|
upsert: Update a key in a dictionary if it exists. Add the key if it does not.\n
|
7
7
|
remove: Remove a key from a dictionary\n
|
8
8
|
list_items: List all keys in the dictionary\n
|
9
|
+
sync: Synchronizes a dictionary with a comma separated list of key/value pairs. Will create, delete, or update keys as needed. Separate keys and values with = or :.\n
|
9
10
|
bulk_add: Perform operations on the dictionary in bulk. A list of operations in JSON format should be specified in the key field. Documentation on this format can be found here: https://docs.fastly.com/api/config#dictionary_item_dc826ce1255a7c42bc48eb204eed8f7f"
|
10
11
|
method_option :service, :aliases => ["--s"]
|
11
12
|
method_option :version, :aliases => ["--v"]
|
13
|
+
method_option :write_only, :aliases => ["--wo"]
|
12
14
|
def dictionary(action, name=false, key=false, value=false)
|
13
15
|
id = FastlyCTL::Utils.parse_directory unless options[:service]
|
14
16
|
id ||= options[:service]
|
@@ -23,7 +25,11 @@ module FastlyCTL
|
|
23
25
|
case action
|
24
26
|
when "create"
|
25
27
|
abort "Must specify name for dictionary" unless name
|
26
|
-
|
28
|
+
|
29
|
+
params = { name: name }
|
30
|
+
params[:write_only] = true if options.key?(:write_only)
|
31
|
+
|
32
|
+
FastlyCTL::Fetcher.api_request(:post, "/service/#{id}/version/#{version}/dictionary", params: params)
|
27
33
|
|
28
34
|
say("Dictionary #{name} created.")
|
29
35
|
when "delete"
|
@@ -62,6 +68,54 @@ module FastlyCTL
|
|
62
68
|
resp.each do |i|
|
63
69
|
puts "#{i["item_key"]} : #{i["item_value"]}"
|
64
70
|
end
|
71
|
+
when "sync"
|
72
|
+
abort "Must specify name for dictionary" unless name
|
73
|
+
abort "Must supply comma separated list of keys and values as the \"key\" parameter. " unless key
|
74
|
+
|
75
|
+
pairs = {}
|
76
|
+
key.split(',').to_set.to_a.each do |kv|
|
77
|
+
kv = kv.split("=") if kv.include?("=")
|
78
|
+
kv = kv.split(":") if kv.include?(":")
|
79
|
+
abort "Keys and values must be separated by an = or : symbol. Found \"#{kv}\"" unless kv.is_a?(Array)
|
80
|
+
pairs[kv[0]] = kv[1]
|
81
|
+
end
|
82
|
+
item_ids = Hash.new
|
83
|
+
bulk = []
|
84
|
+
|
85
|
+
dictionary = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/version/#{version}/dictionary/#{encoded_name}")
|
86
|
+
items = FastlyCTL::Fetcher.api_request(:get, "/service/#{id}/dictionary/#{dictionary["id"]}/items")
|
87
|
+
items.each do |item|
|
88
|
+
unless pairs.key?(item["item_key"])
|
89
|
+
bulk.push({
|
90
|
+
"op" => "delete",
|
91
|
+
"item_key" => item["item_key"]
|
92
|
+
})
|
93
|
+
next
|
94
|
+
end
|
95
|
+
|
96
|
+
if (pairs[item["item_key"]] != item["item_value"])
|
97
|
+
bulk.push({
|
98
|
+
"op": "upsert",
|
99
|
+
"item_key": item["item_key"],
|
100
|
+
"item_value": item["item_value"]
|
101
|
+
})
|
102
|
+
end
|
103
|
+
|
104
|
+
pairs.delete(item["item_key"])
|
105
|
+
end
|
106
|
+
|
107
|
+
pairs.each do |k,v|
|
108
|
+
bulk.push({
|
109
|
+
"op": "create",
|
110
|
+
"item_key": k,
|
111
|
+
"item_value": v
|
112
|
+
})
|
113
|
+
end
|
114
|
+
|
115
|
+
FastlyCTL::Fetcher.api_request(:patch, "/service/#{id}/dictionary/#{dictionary["id"]}/items", {body: {items: bulk}.to_json, headers: {"Content-Type" => "application/json"}})
|
116
|
+
|
117
|
+
say("Sync operation completed successfully with #{bulk.length} operations.")
|
118
|
+
|
65
119
|
when "bulk_add"
|
66
120
|
abort "Must specify name for dictionary" unless name
|
67
121
|
abort "Must specify JSON blob of operations in key field. Documentation on this can be found here: https://docs.fastly.com/api/config#dictionary_item_dc826ce1255a7c42bc48eb204eed8f7f" unless key
|
data/lib/fastlyctl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlyctl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Basile
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|