Skip to content

Commit

Permalink
Enh/dx 81 gcp na support (#37)
Browse files Browse the repository at this point in the history
* CODEOWNERS update

* Update release-gem.yml

* Update release-gem.yml

* Update release-gem.yml

* Added GCP NA support with testcases

* Removed redundancy yml files

---------

Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: aravindbuilt <[email protected]>
  • Loading branch information
3 people authored May 7, 2024
1 parent 935cfb3 commit 0d90d49
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 77 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/release-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.x
ruby-version: '2.7'

- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## CHANGELOG

## Version 0.6.4
## Version 0.8.0
### Date: 14th-May-2024
### Enhancement
- Region support for GCP-NA added

------------------------------------------------
## Version 0.7.0
### Date: 17th-Apr-2023
### Enhancement
- Include metadata support for Asset, Entry and Query,
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @contentstack/security-admin @contentstack/sdk-admin
* @contentstack/security-admin
49 changes: 27 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
PATH
remote: .
specs:

contentstack (0.7.0)
contentstack (0.8.0)
activesupport (>= 3.2)
contentstack_utils (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4.3)
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.4)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
concurrent-ruby (1.2.2)
contentstack_utils (1.1.3.2)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
contentstack_utils (1.2.0)
activesupport (>= 3.2)
nokogiri (~> 1.11)
crack (0.4.5)
crack (1.0.0)
bigdecimal
rexml
diff-lcs (1.5.0)
diff-lcs (1.5.1)
docile (1.4.0)
hashdiff (1.0.1)
i18n (1.12.0)
drb (2.2.1)
hashdiff (1.1.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
mini_portile2 (2.8.1)
minitest (5.18.0)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.14.3-x64-mingw32)
minitest (5.22.3)
mutex_m (0.2.0)
nokogiri (1.15.6-arm64-darwin)
racc (~> 1.4)
public_suffix (5.0.1)
racc (1.6.2)
rexml (3.2.5)
public_suffix (5.0.5)
racc (1.7.3)
rexml (3.2.6)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -62,11 +68,10 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
yard (0.9.34)
yard (0.9.36)

PLATFORMS
ruby
x64-mingw32
arm64-darwin-22

DEPENDENCIES
contentstack!
Expand Down
26 changes: 15 additions & 11 deletions lib/contentstack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize(api_key, delivery_token, environment, options={})
raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options)
end

def content_types
ContentType.all
end
Expand All @@ -56,21 +56,21 @@ def asset(uid)
def live_preview_query(query={})
API.live_preview_query(query)
end

# Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
#
#
# Stack.sync({'init': true}) // For initializing sync
#
#
# Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
#
#
# Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
#
#
# Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
#
#
# Stack.sync({'init': true, 'type': 'entry_published'}) // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
#
#
# Stack.sync({'pagination_token': '<pagination>'}) // For fetching the next batch of entries using pagination token
#
#
# Stack.sync({'sync_token': '<sync>'}) // For performing subsequent sync after initial sync
#
# @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
Expand All @@ -91,6 +91,8 @@ def get_default_region_hosts(region='us')
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}"
when "azure-eu"
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}"
when "gcp-na"
host = "#{Contentstack::Host::PROTOCOL}gcp-na-cdn.#{Contentstack::Host::HOST}"
end
host
end
Expand All @@ -109,15 +111,17 @@ def get_host_by_region(region, options)
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}"
when "azure-eu"
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{custom_host}"
when "gcp-na"
host = "#{Contentstack::Host::PROTOCOL}gcp-na-cdn.#{custom_host}"
end
elsif options[:host].present? && region.empty?
custom_host = options[:host]
host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
else
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region and host is empty
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region and host is empty
end
host
end

end
end
end
3 changes: 2 additions & 1 deletion lib/contentstack/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ class Region
US='us'
AZURE_NA='azure-na'
AZURE_EU='azure-eu'
GCP_NA='gcp-na'
end

class Host
PROTOCOL='https://'
DEFAULT_HOST='cdn.contentstack.io'
HOST='contentstack.com'
end
end
end
4 changes: 2 additions & 2 deletions lib/contentstack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Contentstack
VERSION = "0.7.0"
end
VERSION = "0.8.0"
end
25 changes: 15 additions & 10 deletions spec/contentstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let(:custom_host_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::EU}) }
let(:custom_host_azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_EU}) }
let(:custom_host_azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_NA}) }
let(:custom_host_gcp_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::GCP_NA}) }

it "has a version number" do
expect(Contentstack::VERSION).not_to be nil
Expand All @@ -23,42 +24,46 @@

it "has default host and region" do
expect(client.region).to eq Contentstack::Region::US
expect(client.host).to eq 'https://cdn.contentstack.io'
expect(client.host).to eq 'https://cdn.contentstack.io'
end

it "has custom region with region host" do
expect(eu_client.region).to eq Contentstack::Region::EU
expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
end

it "has custom region with region host" do
expect(azure_na_client.region).to eq Contentstack::Region::AZURE_NA
expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
end

it "has custom region with region host" do
expect(azure_eu_client.region).to eq Contentstack::Region::AZURE_EU
expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
end

it "has custom host and eu region" do
expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com'
expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com'
end

it "has custom host and azure-eu region" do
expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
end

it "has custom host and azure-na region" do
expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
end

it "has custom host and gcp-na region" do
expect(custom_host_gcp_na_client.host).to eq 'https://gcp-na-cdn.contentstack.com'
end


it "JSON to HTML" do
expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq ''
expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq ''
end

it "JSON to HTML" do
expect(Contentstack::render_content('', ContentstackUtils::Model::Options.new())).to eq ''
expect(Contentstack::render_content('', ContentstackUtils::Model::Options.new())).to eq ''
end
end
end

0 comments on commit 0d90d49

Please sign in to comment.