forked from googleapis/google-cloud-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
setup bucket with ip filter #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shubhangi-google
wants to merge
11
commits into
main
Choose a base branch
from
set_bucket_ip_filter_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
56b0425
wip-- create bucket with ip filter working
shubhangi-google 6c1fe37
wip
shubhangi-google dcfdafb
wip
shubhangi-google 4d2bbe7
check samples
shubhangi-google e4877d3
adding tests and samples
shubhangi-google e6ccd0c
remove pry
shubhangi-google 6e8951c
updating comments
shubhangi-google 326947d
Merge branch 'main' into set_bucket_ip_filter_1
shubhangi-google febdecf
fix syntax
shubhangi-google 447bd86
remove pry
shubhangi-google 49f3eb3
debugging kokoro
shubhangi-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
google-cloud-storage/acceptance/storage/bucket_ip_filter_test.rb
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| require_relative "../storage_helper" | ||
| describe Google::Cloud::Storage::Bucket, :storage do | ||
| let(:ip_filter_disabled) do | ||
| { | ||
| mode: "Disabled", | ||
| public_network_source: { | ||
| allowed_ip_cidr_ranges: ["0.0.0.0/0", "::/0"] | ||
| } | ||
| } | ||
| end | ||
|
|
||
| let(:ip_filter_disabled_update) do | ||
| { | ||
| mode: "Disabled", | ||
| public_network_source: { | ||
| allowed_ip_cidr_ranges: ["8.8.8.8/32"] | ||
| } | ||
| } | ||
| end | ||
| let(:bucket_name) { "#{$bucket_names.first}-ip-filter" } | ||
| let :bucket do | ||
| storage.bucket(bucket_name) || | ||
| storage.create_bucket(bucket_name, ip_filter: ip_filter_disabled) | ||
| end | ||
|
|
||
| after(:all) do | ||
| safe_gcs_execute { bucket.delete } | ||
| end | ||
|
|
||
| it "creates, gets, updates, and deletes a bucket with ip_filter" do | ||
| # Create a bucket with ip_filter | ||
| puts "*************************Bucket Name**************************" | ||
| puts bucket.ip_filter | ||
| puts "*************************Bucket Name**************************" | ||
|
|
||
| # bucket = storage.bucket(bucket_name) || | ||
| # safe_gcs_execute {storage.create_bucket bucket_name, ip_filter: ip_filter_disabled} | ||
|
|
||
| # _(bucket.ip_filter).wont_be_nil | ||
| _(bucket.ip_filter.mode).must_equal "Disabled" | ||
| _(bucket.ip_filter.public_network_source.allowed_ip_cidr_ranges).must_equal ["0.0.0.0/0", "::/0"] | ||
|
|
||
| # Get the bucket and verify ip_filter | ||
| bucket = storage.bucket bucket_name | ||
| _(bucket.ip_filter).wont_be_nil | ||
| _(bucket.ip_filter.mode).must_equal "Disabled" | ||
| _(bucket.ip_filter.public_network_source.allowed_ip_cidr_ranges).must_equal ["0.0.0.0/0", "::/0"] | ||
|
|
||
| # Update the ip_filter | ||
| safe_gcs_execute do | ||
| bucket.update do |b| | ||
| b.ip_filter = ip_filter_disabled_update | ||
| end | ||
| end | ||
|
|
||
| _(bucket.ip_filter.mode).must_equal "Disabled" | ||
| _(bucket.ip_filter.public_network_source.allowed_ip_cidr_ranges).must_equal ["8.8.8.8/32"] | ||
|
|
||
| # Disable ip_filter | ||
| safe_gcs_execute do | ||
| bucket.ip_filter = { | ||
| mode: "Disabled", | ||
| public_network_source: { | ||
| allowed_ip_cidr_ranges: [] | ||
| } | ||
| } | ||
| end | ||
|
|
||
| _(bucket.ip_filter.public_network_source.allowed_ip_cidr_ranges).must_be_nil | ||
|
|
||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
google-cloud-storage/samples/storage_create_bucket_with_ip_filter.rb
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START storage_create_bucket_with_ip_filter] | ||
| def create_bucket_with_ip_filter bucket_name: | ||
| # The ID to give your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| ip_filter = { | ||
| mode: "Disabled", | ||
| public_network_source: { | ||
| allowed_ip_cidr_ranges: [ | ||
| "0.0.0.0/0", "::/0" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| bucket = storage.create_bucket bucket_name do |b| | ||
| b.ip_filter = ip_filter | ||
| b.uniform_bucket_level_access = true | ||
| end | ||
| puts "Created bucket #{bucket_name} with IP filter." | ||
| end | ||
| # [END storage_create_bucket_with_ip_filter] | ||
|
|
||
| if $PROGRAM_NAME == __FILE__ | ||
| create_bucket_with_ip_filter bucket_name: ARGV.shift | ||
| end |
41 changes: 41 additions & 0 deletions
41
google-cloud-storage/samples/storage_delete_bucket_ip_filter.rb
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START storage_delete_ip_filtering_rules] | ||
| def delete_bucket_ip_filter bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| require "google/cloud/storage" | ||
|
|
||
| storage = Google::Cloud::Storage.new | ||
| bucket = storage.bucket bucket_name | ||
|
|
||
| # Clear IP filter configuration by setting it to empty/disabled | ||
| bucket.update do |b| | ||
| b.ip_filter = { | ||
| mode: "Disabled", | ||
| public_network_source: { | ||
| allowed_ip_cidr_ranges: [] | ||
| } | ||
| } | ||
| end | ||
|
|
||
| puts "Deleted IP filter for bucket #{bucket_name}." | ||
| end | ||
| # [END storage_delete_ip_filtering_rules] | ||
|
|
||
| if $PROGRAM_NAME == __FILE__ | ||
| delete_bucket_ip_filter bucket_name: ARGV.shift | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check this if you pass empty and using patch API make the API remove the existing IP filter instead of patching, check this logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked, if we are trying set ip_filter as nil or {}
the ip_filter is not changing at all also no error