wcc-contentful 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.gitignore +5 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +8 -1
- data/Guardfile +23 -1
- data/app/controllers/wcc/contentful/application_controller.rb +7 -0
- data/app/controllers/wcc/contentful/webhook_controller.rb +30 -0
- data/app/jobs/wcc/contentful/delayed_sync_job.rb +14 -0
- data/bin/rails +14 -0
- data/config/initializers/mime_types.rb +3 -0
- data/config/routes.rb +5 -0
- data/lib/generators/wcc/menu_generator.rb +4 -4
- data/lib/generators/wcc/templates/contentful_shell_wrapper +109 -68
- data/lib/generators/wcc/templates/menu/menu.rb +4 -6
- data/lib/generators/wcc/templates/menu/menu_button.rb +4 -6
- data/lib/generators/wcc/templates/release +2 -2
- data/lib/generators/wcc/templates/wcc_contentful.rb +0 -1
- data/lib/wcc/contentful/client_ext.rb +1 -1
- data/lib/wcc/contentful/configuration.rb +76 -35
- data/lib/wcc/contentful/engine.rb +13 -0
- data/lib/wcc/contentful/exceptions.rb +6 -0
- data/lib/wcc/contentful/graphql/builder.rb +8 -3
- data/lib/wcc/contentful/helpers.rb +6 -0
- data/lib/wcc/contentful/indexed_representation.rb +31 -0
- data/lib/wcc/contentful/model.rb +82 -1
- data/lib/wcc/contentful/model_builder.rb +18 -8
- data/lib/wcc/contentful/model_validators.rb +69 -18
- data/lib/wcc/contentful/simple_client/http_adapter.rb +15 -0
- data/lib/wcc/contentful/simple_client/typhoeus_adapter.rb +30 -0
- data/lib/wcc/contentful/simple_client.rb +67 -18
- data/lib/wcc/contentful/store/base.rb +89 -0
- data/lib/wcc/contentful/store/cdn_adapter.rb +13 -19
- data/lib/wcc/contentful/store/lazy_cache_store.rb +76 -0
- data/lib/wcc/contentful/store/memory_store.rb +17 -23
- data/lib/wcc/contentful/store/postgres_store.rb +32 -19
- data/lib/wcc/contentful/store.rb +62 -0
- data/lib/wcc/contentful/version.rb +1 -1
- data/lib/wcc/contentful.rb +113 -24
- data/wcc-contentful.gemspec +4 -0
- metadata +75 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a9e00e55f441463939d98fd8b8542120976dc4
|
4
|
+
data.tar.gz: 5eac07eb53c3e3a8b943c56c072c2f0cde90afe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9bc2e68d9d4159a87284d8c90a7262539a057962682b605e608a602344e2d5aff2d3e1738961324175b93423c6fa82a221fca9b36277172d50c6a246e36eed9
|
7
|
+
data.tar.gz: d5458f48090f6a234d035e6cd4b0887ffeab7024ebff4502a49559d0f98c9e5a969bbfc7516d4b61d6067e68f74ada91b9bd389393ebb3c36b2b12f921ed0dd0
|
data/.circleci/config.yml
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -16,4 +16,11 @@
|
|
16
16
|
|
17
17
|
* Models are built dynamically from downloading the content_types via Contentful CDN
|
18
18
|
* 'Menu' and 'MenuItem' are defined and their structures are enforced via validation
|
19
|
-
* A GraphQL schema can optionally be generated to execute queries against Contentful
|
19
|
+
* A GraphQL schema can optionally be generated to execute queries against Contentful
|
20
|
+
|
21
|
+
# v0.2.0
|
22
|
+
|
23
|
+
* Application models can be registered to be instantiated for a given content type
|
24
|
+
* New 'lazy sync' delivery method acts as a cache that is kept up to date by the sync API
|
25
|
+
* 'eager sync' is now hooked up to a webhook which can be mounted to receive publish events
|
26
|
+
* Major changes to configuration methods
|
data/Guardfile
CHANGED
@@ -11,13 +11,35 @@ group :red_green_refactor, halt_on_fail: true do
|
|
11
11
|
# RSpec files
|
12
12
|
rspec = dsl.rspec
|
13
13
|
watch(rspec.spec_helper) { rspec.spec_dir }
|
14
|
-
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
# watch(rspec.spec_support) { rspec.spec_dir }
|
15
15
|
watch(rspec.spec_files)
|
16
16
|
|
17
17
|
# Ruby files
|
18
18
|
ruby = dsl.ruby
|
19
19
|
watch(%r{lib/wcc/(.+)\.rb$}) { |m| rspec.spec.call("wcc/#{m[1]}") }
|
20
20
|
watch(%r{lib/generators/(.+)\.rb$}) { |m| rspec.spec.call("generators/#{m[1]}") }
|
21
|
+
|
22
|
+
# Rails files
|
23
|
+
rails = dsl.rails(view_extensions: %w[erb haml slim])
|
24
|
+
dsl.watch_spec_files_for(rails.app_files)
|
25
|
+
dsl.watch_spec_files_for(rails.views)
|
26
|
+
|
27
|
+
watch(rails.controllers) do |m|
|
28
|
+
[
|
29
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
30
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
31
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Rails config changes
|
36
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
37
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
38
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
39
|
+
|
40
|
+
# Capybara features specs
|
41
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
42
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
21
43
|
end
|
22
44
|
|
23
45
|
guard :rubocop, cli: ['--display-cop-names'] do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'wcc/contentful/application_controller'
|
4
|
+
|
5
|
+
module WCC::Contentful
|
6
|
+
class WebhookController < ApplicationController
|
7
|
+
before_action :authorize_contentful
|
8
|
+
|
9
|
+
def receive
|
10
|
+
WCC::Contentful.sync!(up_to_id: params.dig('sys', 'id'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def authorize_contentful
|
14
|
+
config = WCC::Contentful.configuration
|
15
|
+
|
16
|
+
if config.webhook_username.present? && config.webhook_password.present?
|
17
|
+
unless authenticate_with_http_basic do |u, p|
|
18
|
+
u == config.webhook_username &&
|
19
|
+
p == config.webhook_password
|
20
|
+
end
|
21
|
+
request_http_basic_authentication
|
22
|
+
return
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
return if request.content_type == 'application/vnd.contentful.management.v1+json'
|
27
|
+
render json: { msg: 'This endpoint only responds to webhooks from Contentful' }, status: 406
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_job'
|
4
|
+
|
5
|
+
module WCC::Contentful
|
6
|
+
class DelayedSyncJob < ActiveJob::Base
|
7
|
+
queue_as :default
|
8
|
+
|
9
|
+
def perform(*args)
|
10
|
+
sync_options = args.first || {}
|
11
|
+
WCC::Contentful.sync!(**sync_options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/bin/rails
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/wcc/contentful/engine', __FILE__)
|
7
|
+
APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require 'rails/all'
|
14
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
@@ -17,7 +17,7 @@ module Wcc
|
|
17
17
|
deps = package['dependencies']
|
18
18
|
|
19
19
|
unless deps.try(:[], 'contentful-migration-cli').present?
|
20
|
-
run 'npm install --save watermarkchurch/migration-cli'
|
20
|
+
run 'npm install --save watermarkchurch/migration-cli ts-node typescript'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -59,9 +59,9 @@ module Wcc
|
|
59
59
|
copy_file 'wcc_contentful.rb', 'config/initializers/wcc_contentful.rb'
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
63
|
-
copy_file 'menu/menu.rb', '
|
64
|
-
copy_file 'menu/menu_button.rb', '
|
62
|
+
def drop_model_overrides_in_app_models
|
63
|
+
copy_file 'menu/menu.rb', 'app/models/menu.rb'
|
64
|
+
copy_file 'menu/menu_button.rb', 'app/models/menu_button.rb'
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -8,13 +8,26 @@ COLOR_YELLOW='\033[1;33m'
|
|
8
8
|
COLOR_LGREEN='\033[1;32m'
|
9
9
|
|
10
10
|
logv() {
|
11
|
-
|
11
|
+
[[ -z "$VERBOSE" ]] && return 0;
|
12
|
+
|
13
|
+
local msg=$(echo "$@" | sed "s/$CONTENTFUL_MANAGEMENT_TOKEN/\*\*\*\*\*/" )
|
14
|
+
>&2 echo -e "${COLOR_GRAY}$msg${COLOR_NC}" || true
|
12
15
|
}
|
13
16
|
|
14
17
|
logerr() {
|
15
18
|
>&2 echo -e "${COLOR_RED}$@${COLOR_NC}"
|
16
19
|
}
|
17
20
|
|
21
|
+
curlv() {
|
22
|
+
logv "curl" $@
|
23
|
+
curl "$@"
|
24
|
+
}
|
25
|
+
|
26
|
+
execv() {
|
27
|
+
logv "$@"
|
28
|
+
"$@"
|
29
|
+
}
|
30
|
+
|
18
31
|
## *** Argument Parsing & validation ***
|
19
32
|
|
20
33
|
usage() {
|
@@ -41,10 +54,9 @@ usage() {
|
|
41
54
|
restores a given backup file into the current space
|
42
55
|
* [file] optional - default: the most recent backup file in the current directory
|
43
56
|
|
44
|
-
|
45
|
-
|
46
|
-
*
|
47
|
-
* -s [to space ID] optional - the current working space. Default: \$CONTENTFUL_SPACE_ID
|
57
|
+
new_env
|
58
|
+
deletes the current working environment if it exists and makes a new clone of 'master'.
|
59
|
+
* -e [to environment ID] optional - the current working environment. Default: \$USER
|
48
60
|
|
49
61
|
generate [name]
|
50
62
|
Creates a sample migration in the db/migrate directory
|
@@ -61,14 +73,14 @@ parse_args() {
|
|
61
73
|
OPTIND=1
|
62
74
|
local s=$(echo "$1" | tr '[:upper:]' '[:lower:]')
|
63
75
|
case "$s" in
|
64
|
-
migrate|setup|backup|export|restore|
|
76
|
+
migrate|setup|backup|export|restore|new_env|import|generate|clean|help|h|\?)
|
65
77
|
export subcommand=$s
|
66
78
|
OPTIND=2
|
67
79
|
;;
|
68
80
|
esac
|
69
81
|
|
70
82
|
# Parse flags
|
71
|
-
while getopts ":
|
83
|
+
while getopts ":hyvse:a:" arg; do
|
72
84
|
case $arg in
|
73
85
|
y) # Yes - skip prompts
|
74
86
|
export YES="-y"
|
@@ -79,6 +91,9 @@ parse_args() {
|
|
79
91
|
a) # Contentful Mgmt Token - overrides env var CONTENTFUL_MANAGEMENT_TOKEN
|
80
92
|
export CONTENTFUL_MANAGEMENT_TOKEN=$OPTARG
|
81
93
|
;;
|
94
|
+
e) # Contentful environment ID - overrides env var CONTENTFUL_ENVIRONMENT
|
95
|
+
export CONTENTFUL_ENVIRONMENT=$OPTARG
|
96
|
+
;;
|
82
97
|
v) # Verbose mode - extra output
|
83
98
|
export VERBOSE=true
|
84
99
|
;;
|
@@ -106,8 +121,7 @@ require_environment() {
|
|
106
121
|
[[ -z "$CONTENTFUL_MANAGEMENT_TOKEN" ]] && logerr "Please set CONTENTFUL_MANAGEMENT_TOKEN environment variable or use '-a' flag." && exit -1;
|
107
122
|
if [[ ! -f node_modules/.bin/contentful-migration ]]; then
|
108
123
|
command -v npm >/dev/null 2>&1 || (logerr "I require 'npm' but it's not installed. Please install nodejs."; exit -1)
|
109
|
-
|
110
|
-
npm install
|
124
|
+
execv npm install
|
111
125
|
[[ -f node_modules/.bin/contentful-migration ]] || (logerr "Failed installing node modules - please ensure contentful CLI is installed"; exit -1)
|
112
126
|
fi
|
113
127
|
}
|
@@ -133,8 +147,20 @@ confirm() {
|
|
133
147
|
}
|
134
148
|
|
135
149
|
get_space_name() {
|
136
|
-
|
137
|
-
|
150
|
+
curlv -s https://api.contentful.com/spaces/$1?access_token=$CONTENTFUL_MANAGEMENT_TOKEN | jq -r .name | tr '[:upper:]' '[:lower:]'
|
151
|
+
}
|
152
|
+
|
153
|
+
# Man I wish I understood sed... https://stackoverflow.com/a/29060802
|
154
|
+
# $1 File
|
155
|
+
# $2 Find
|
156
|
+
# $3 Replace / Append
|
157
|
+
replace_append() {
|
158
|
+
if grep -q "^$2" "$1"
|
159
|
+
then
|
160
|
+
sed -i.bak "s/^$2.*$/$3/" "$1"
|
161
|
+
else
|
162
|
+
echo "\n$3" >> "$1"
|
163
|
+
fi
|
138
164
|
}
|
139
165
|
|
140
166
|
set -e
|
@@ -150,14 +176,12 @@ migrate() {
|
|
150
176
|
|
151
177
|
require_environment
|
152
178
|
|
153
|
-
|
154
|
-
node_modules/.bin/ts-node node_modules/.bin/contentful-migration \
|
179
|
+
execv node_modules/.bin/ts-node node_modules/.bin/contentful-migration \
|
155
180
|
-s $CONTENTFUL_SPACE_ID -a $CONTENTFUL_MANAGEMENT_TOKEN \
|
156
181
|
$YES -p $ARG
|
157
182
|
|
158
183
|
mkdir -p db
|
159
|
-
|
160
|
-
node_modules/.bin/contentful-export --export-dir db --content-file contentful-schema.json \
|
184
|
+
execv node_modules/.bin/contentful-export --export-dir db --content-file contentful-schema.json \
|
161
185
|
--space-id $CONTENTFUL_SPACE_ID --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
162
186
|
--query-entries 'content_type=migrationHistory' \
|
163
187
|
--query-assets 'sys.id=false'
|
@@ -177,9 +201,10 @@ backup() {
|
|
177
201
|
|
178
202
|
require_environment
|
179
203
|
|
180
|
-
|
181
|
-
|
182
|
-
|
204
|
+
[[ ! -z "$CONTENTFUL_ENVIRONMENT" ]] && ENV="--environment-id $CONTENTFUL_ENVIRONMENT"
|
205
|
+
|
206
|
+
execv node_modules/.bin/contentful-export $FILE \
|
207
|
+
--space-id $CONTENTFUL_SPACE_ID $ENV --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
183
208
|
$@
|
184
209
|
}
|
185
210
|
|
@@ -192,13 +217,17 @@ restore() {
|
|
192
217
|
[[ -z "$FILE" ]] && logerr "No file given on command line" && exit -1
|
193
218
|
fi
|
194
219
|
|
195
|
-
|
220
|
+
name=$(get_space_name $CONTENTFUL_SPACE_ID)
|
221
|
+
if [[ ! -z "$CONTENTFUL_ENVIRONMENT" ]]; then
|
222
|
+
ENV="--environment-id $CONTENTFUL_ENVIRONMENT"
|
223
|
+
name="$name/$CONTENTFUL_ENVIRONMENT"
|
224
|
+
fi
|
225
|
+
confirm "Import $FILE into $name?" || exit -1
|
196
226
|
|
197
227
|
require_environment
|
198
228
|
|
199
|
-
|
200
|
-
|
201
|
-
--space-id $CONTENTFUL_SPACE_ID --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
229
|
+
execv node_modules/.bin/contentful-import \
|
230
|
+
--space-id $CONTENTFUL_SPACE_ID $ENV --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
202
231
|
--content-file $FILE
|
203
232
|
}
|
204
233
|
|
@@ -208,13 +237,18 @@ setup() {
|
|
208
237
|
FILE="$1"
|
209
238
|
[[ -z "$FILE" ]] && FILE=db/contentful-schema.json
|
210
239
|
|
211
|
-
|
240
|
+
name=$(get_space_name $CONTENTFUL_SPACE_ID)
|
241
|
+
if [[ ! -z "$CONTENTFUL_ENVIRONMENT" ]]; then
|
242
|
+
ENV="--environment-id $CONTENTFUL_ENVIRONMENT"
|
243
|
+
name="$name/$CONTENTFUL_ENVIRONMENT"
|
244
|
+
fi
|
245
|
+
|
246
|
+
confirm "Initialize space $name from seed file $FILE?" || exit -1
|
212
247
|
|
213
248
|
require_environment
|
214
249
|
|
215
|
-
|
216
|
-
|
217
|
-
--space-id $CONTENTFUL_SPACE_ID --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
250
|
+
execv node_modules/.bin/contentful-import \
|
251
|
+
--space-id $CONTENTFUL_SPACE_ID $ENV --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
|
218
252
|
--content-file $FILE
|
219
253
|
|
220
254
|
migrate
|
@@ -226,60 +260,67 @@ clean() {
|
|
226
260
|
|
227
261
|
require_environment
|
228
262
|
|
263
|
+
[[ -z "$CONTENTFUL_ENVIRONMENT" ]] && CONTENTFUL_ENVIRONMENT="$USER"
|
264
|
+
[[ "$CONTENTFUL_ENVIRONMENT" == "master" ]] && logerr "cannot delete the master environment" && exit -1
|
265
|
+
|
229
266
|
name=$(get_space_name $CONTENTFUL_SPACE_ID)
|
267
|
+
code=$(curlv -s -o /dev/null -w "%{http_code}" https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/environments/$CONTENTFUL_ENVIRONMENT\?access_token\=$CONTENTFUL_MANAGEMENT_TOKEN)
|
268
|
+
[[ $code == "404" ]] && logerr "$CONTENTFUL_ENVIRONMENT does not exist in $name" && return 0;
|
230
269
|
|
231
|
-
confirm "This will delete
|
232
|
-
|
233
|
-
|
234
|
-
local bkup_file="contentful-export-$CONTENTFUL_SPACE_ID-`date +"%Y-%m-%dT%H-%M-%S"`.json"
|
270
|
+
confirm "This will delete the '$CONTENTFUL_ENVIRONMENT' environment from $name. Are you sure?" || exit -1
|
271
|
+
|
272
|
+
local bkup_file="contentful-export-$CONTENTFUL_SPACE_ID-${CONTENTFUL_ENVIRONMENT}-`date +"%Y-%m-%dT%H-%M-%S"`.json"
|
235
273
|
backup $bkup_file
|
236
|
-
|
237
|
-
|
238
|
-
assets=$(cat $bkup_file | jq -r '.assets[].sys.id')
|
239
|
-
|
240
|
-
delete() {
|
241
|
-
logv "curl -XDELETE https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/$1/$2/published\?access_token\=*****"
|
242
|
-
curl -s --fail -XDELETE https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/$1/$2/published\?access_token\=$CONTENTFUL_MANAGEMENT_TOKEN > /dev/null
|
243
|
-
logv "curl -XDELETE https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/$1/$2\?access_token\=*****"
|
244
|
-
curl -s --fail -XDELETE https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/$1/$2\?access_token\=$CONTENTFUL_MANAGEMENT_TOKEN > /dev/null
|
245
|
-
}
|
246
|
-
|
247
|
-
[[ ! -z "$assets" ]] && while read -r id; do delete 'assets' $id; done <<< "${assets}"
|
248
|
-
[[ ! -z "$entries" ]] && while read -r id; do delete 'entries' $id; done <<< "${entries}"
|
249
|
-
[[ ! -z "$content_types" ]] && while read -r id; do delete 'content_types' $id; done <<< "${content_types}"
|
250
|
-
|
251
|
-
echo -e "${COLOR_LGREEN}All content deleted - prior content saved at${COLOR_NC} $bkup_file"
|
252
|
-
[[ "$1" == "no-init" ]] || (setup || logerr "Error setting up space $name!")
|
274
|
+
|
275
|
+
curlv --fail -XDELETE https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/environments/$CONTENTFUL_ENVIRONMENT\?access_token\=$CONTENTFUL_MANAGEMENT_TOKEN
|
253
276
|
}
|
254
277
|
|
255
|
-
# Example: bin/contentful
|
256
|
-
|
278
|
+
# Example: bin/contentful new_env -e gordon_dev
|
279
|
+
new_env() {
|
257
280
|
command -v jq >/dev/null 2>&1 || (logerr "I require 'jq' but it's not installed. Please run 'brew install jq'"; exit -1)
|
258
281
|
|
259
282
|
require_environment
|
283
|
+
name=$(get_space_name $CONTENTFUL_SPACE_ID)
|
284
|
+
[[ -z "$CONTENTFUL_ENVIRONMENT" ]] && CONTENTFUL_ENVIRONMENT="$USER"
|
285
|
+
[[ "$CONTENTFUL_ENVIRONMENT" == "master" ]] && logerr "cannot delete the master environment" && exit -1
|
260
286
|
|
261
|
-
|
262
|
-
[[ -z "$from_space_id" ]] && logerr "Please provide the space ID from which to restore data" && exit -1
|
263
|
-
to_space_id=$CONTENTFUL_SPACE_ID
|
264
|
-
|
265
|
-
from_name=$(get_space_name $from_space_id)
|
266
|
-
to_name=$(get_space_name $CONTENTFUL_SPACE_ID)
|
267
|
-
|
268
|
-
echo -e "${COLOR_LCYAN}This will backup all data from $from_name, delete all data in $to_name, and then write the $from_name data over it.${COLOR_NC}"
|
287
|
+
echo -e "${COLOR_LCYAN}This will delete '$CONTENTFUL_ENVIRONMENT' and recreate it from master.${COLOR_NC}"
|
269
288
|
confirm "Continue?" || exit -1
|
270
289
|
export YES='-y' # don't keep bugging the user
|
271
290
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
291
|
+
clean
|
292
|
+
|
293
|
+
# make the environment
|
294
|
+
resp=$(curlv -s --fail -XPUT https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/environments/$CONTENTFUL_ENVIRONMENT \
|
295
|
+
-H "Authorization: Bearer ${CONTENTFUL_MANAGEMENT_TOKEN}" \
|
296
|
+
-H "Content-Type: application/vnd.contentful.management.v1+json" \
|
297
|
+
-d "{ \"name\": \"${CONTENTFUL_ENVIRONMENT}\" }")
|
298
|
+
|
299
|
+
while [ ! $(echo "$resp" | jq -r .sys.status.sys.id) == "ready" ]
|
300
|
+
do
|
301
|
+
logv "waiting for environment $CONTENTFUL_ENVIRONMENT to be ready..."
|
302
|
+
sleep 1
|
303
|
+
resp=$(curlv -s https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/environments/$CONTENTFUL_ENVIRONMENT \
|
304
|
+
-H "Authorization: Bearer ${CONTENTFUL_MANAGEMENT_TOKEN}")
|
305
|
+
done
|
306
|
+
|
307
|
+
logv "get the API keys and update the one matching ours to point to the new environment"
|
308
|
+
keys=$(curlv -s --fail https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/api_keys\?access_token\=$CONTENTFUL_MANAGEMENT_TOKEN)
|
309
|
+
my_key=$(echo "$keys" | jq -r ".items[] | select(.accessToken == \"$CONTENTFUL_ACCESS_TOKEN\")")
|
310
|
+
my_key_id=$(echo "$my_key" | jq -r ".sys.id")
|
311
|
+
my_key_version=$(echo "$my_key" | jq -r ".sys.version")
|
312
|
+
new_env_links=$(echo "$my_key" | jq ".environments + [{ \"sys\": { \"id\": \"$CONTENTFUL_ENVIRONMENT\", \"type\": \"Link\", \"linkType\": \"Environment\" } }] | { \"environments\": . }")
|
313
|
+
|
314
|
+
curlv -s -o /dev/null --fail -XPUT https://api.contentful.com/spaces/$CONTENTFUL_SPACE_ID/api_keys/$my_key_id \
|
315
|
+
-H "Authorization: Bearer ${CONTENTFUL_MANAGEMENT_TOKEN}" \
|
316
|
+
-H "Content-Type: application/vnd.contentful.management.v1+json" \
|
317
|
+
-H "X-Contentful-Version: ${my_key_version}" \
|
318
|
+
-d "${new_env_links}"
|
276
319
|
|
277
|
-
|
278
|
-
|
279
|
-
clean no-init
|
320
|
+
execv replace_append .env.local "CONTENTFUL_ENVIRONMENT\=" "CONTENTFUL_ENVIRONMENT=$CONTENTFUL_ENVIRONMENT"
|
321
|
+
execv replace_append .env.test.local "CONTENTFUL_ENVIRONMENT\=" "CONTENTFUL_ENVIRONMENT=$CONTENTFUL_ENVIRONMENT"
|
280
322
|
|
281
|
-
|
282
|
-
restore $bkup_file
|
323
|
+
echo "Environment ${CONTENTFUL_ENVIRONMENT} successfully created!"
|
283
324
|
}
|
284
325
|
|
285
326
|
# Example: bin/contentful generate add content type dog
|
@@ -328,8 +369,8 @@ case $subcommand in
|
|
328
369
|
clean)
|
329
370
|
clean $@
|
330
371
|
;;
|
331
|
-
|
332
|
-
|
372
|
+
new_env)
|
373
|
+
new_env $@
|
333
374
|
;;
|
334
375
|
help|h|\?)
|
335
376
|
usage
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
class WCC::Contentful::Model::Menu < WCC::Contentful::Model
|
8
|
-
|
3
|
+
# This model represents the 'menu' content type in Contentful. Any linked
|
4
|
+
# entries of the 'menu' content type will be resolved as instances of this class.
|
5
|
+
# It exposes #find, #find_by, and #find_all methods to query Contentful.
|
6
|
+
class Menu < WCC::Contentful::Model::Menu
|
9
7
|
# Add custom validations to ensure that app-specific properties exist:
|
10
8
|
# validate_field :foo, :String, :required
|
11
9
|
# validate_field :bar_links, :Array, link_to: %w[bar baz]
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
class WCC::Contentful::Model::MenuButton < WCC::Contentful::Model
|
8
|
-
|
3
|
+
# This model represents the 'menuButton' content type in Contentful. Any linked
|
4
|
+
# entries of the 'menuButton' content type will be resolved as instances of this class.
|
5
|
+
# It exposes #find, #find_by, and #find_all methods to query Contentful.
|
6
|
+
class MenuButton < WCC::Contentful::Model::MenuButton
|
9
7
|
# Add custom validations to ensure that app-specific properties exist:
|
10
8
|
# validate_field :foo, :String, :required
|
11
9
|
# validate_field :bar_links, :Array, link_to: %w[bar baz]
|
@@ -8,7 +8,6 @@ WCC::Contentful.configure do |config|
|
|
8
8
|
config.management_token = # Contentful API management token
|
9
9
|
config.default_locale = # Set default locale, if left blank this is 'en-US'
|
10
10
|
config.content_delivery = # :direct, :eager_sync, or :lazy_sync
|
11
|
-
config.sync_store = # :memory, :postgres, or a custom implementation
|
12
11
|
end
|
13
12
|
|
14
13
|
# Download content types, build models, and sync content
|
@@ -6,7 +6,7 @@ class Contentful::Client
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.get_http(url, query, headers = {}, proxy = {})
|
9
|
-
if override = WCC::Contentful.configuration.
|
9
|
+
if override = WCC::Contentful.configuration.http_adapter
|
10
10
|
override.call(url, query, headers, proxy)
|
11
11
|
else
|
12
12
|
old_get_http(url, query, headers, proxy)
|