fog-google 1.8.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.fog.example +1 -3
- data/.rubocop.yml +3 -3
- data/.travis.yml +5 -3
- data/CHANGELOG.md +126 -2
- data/CONTRIBUTING.md +0 -1
- data/README.md +59 -8
- data/SECURITY.md +16 -0
- data/ci/README.md +8 -8
- data/ci/build-head-pipeline.yml +173 -0
- data/ci/credentials.yml.template +0 -2
- data/ci/docker-image/Dockerfile +3 -3
- data/ci/{pipeline.yml → integration-pipeline.yml} +0 -33
- data/ci/pipeline-dev.yml +58 -0
- data/ci/tasks/run-int.sh +20 -3
- data/ci/tasks/run-int.yml +3 -1
- data/examples/sql/flags.rb +10 -6
- data/examples/sql/instances.rb +38 -34
- data/examples/sql/operations.rb +20 -16
- data/examples/sql/ssl_certs.rb +32 -28
- data/examples/sql/tiers.rb +10 -6
- data/fog-google.gemspec +3 -3
- data/lib/fog/compute/google.rb +5 -5
- data/lib/fog/compute/google/mock.rb +2 -1
- data/lib/fog/compute/google/models/address.rb +15 -2
- data/lib/fog/compute/google/models/disk.rb +6 -2
- data/lib/fog/compute/google/models/images.rb +6 -1
- data/lib/fog/compute/google/models/instance_groups.rb +2 -2
- data/lib/fog/compute/google/models/server.rb +33 -9
- data/lib/fog/compute/google/real.rb +2 -1
- data/lib/fog/compute/google/requests/abandon_instances.rb +2 -0
- data/lib/fog/compute/google/requests/add_backend_service_backends.rb +2 -0
- data/lib/fog/compute/google/requests/add_instance_group_instances.rb +2 -0
- data/lib/fog/compute/google/requests/add_server_access_config.rb +2 -0
- data/lib/fog/compute/google/requests/add_target_pool_health_checks.rb +2 -0
- data/lib/fog/compute/google/requests/add_target_pool_instances.rb +2 -0
- data/lib/fog/compute/google/requests/attach_disk.rb +2 -0
- data/lib/fog/compute/google/requests/create_disk_snapshot.rb +2 -0
- data/lib/fog/compute/google/requests/delete_address.rb +2 -0
- data/lib/fog/compute/google/requests/delete_backend_service.rb +2 -0
- data/lib/fog/compute/google/requests/delete_disk.rb +2 -0
- data/lib/fog/compute/google/requests/delete_firewall.rb +2 -0
- data/lib/fog/compute/google/requests/delete_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/delete_global_address.rb +2 -0
- data/lib/fog/compute/google/requests/delete_global_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/delete_global_operation.rb +2 -0
- data/lib/fog/compute/google/requests/delete_http_health_check.rb +2 -0
- data/lib/fog/compute/google/requests/delete_image.rb +2 -0
- data/lib/fog/compute/google/requests/delete_instance_group.rb +2 -0
- data/lib/fog/compute/google/requests/delete_instance_group_manager.rb +2 -0
- data/lib/fog/compute/google/requests/delete_instance_template.rb +2 -0
- data/lib/fog/compute/google/requests/delete_network.rb +2 -0
- data/lib/fog/compute/google/requests/delete_region_operation.rb +2 -0
- data/lib/fog/compute/google/requests/delete_route.rb +2 -0
- data/lib/fog/compute/google/requests/delete_server.rb +2 -0
- data/lib/fog/compute/google/requests/delete_server_access_config.rb +2 -0
- data/lib/fog/compute/google/requests/delete_snapshot.rb +2 -0
- data/lib/fog/compute/google/requests/delete_ssl_certificate.rb +2 -0
- data/lib/fog/compute/google/requests/delete_subnetwork.rb +2 -0
- data/lib/fog/compute/google/requests/delete_target_http_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/delete_target_https_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/delete_target_instance.rb +2 -0
- data/lib/fog/compute/google/requests/delete_target_pool.rb +2 -0
- data/lib/fog/compute/google/requests/delete_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/delete_zone_operation.rb +2 -0
- data/lib/fog/compute/google/requests/deprecate_image.rb +2 -0
- data/lib/fog/compute/google/requests/detach_disk.rb +2 -0
- data/lib/fog/compute/google/requests/expand_subnetwork_ip_cidr_range.rb +2 -0
- data/lib/fog/compute/google/requests/get_address.rb +2 -0
- data/lib/fog/compute/google/requests/get_backend_service_health.rb +2 -0
- data/lib/fog/compute/google/requests/get_disk.rb +2 -0
- data/lib/fog/compute/google/requests/get_disk_type.rb +2 -0
- data/lib/fog/compute/google/requests/get_firewall.rb +2 -0
- data/lib/fog/compute/google/requests/get_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/get_global_address.rb +2 -0
- data/lib/fog/compute/google/requests/get_global_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/get_global_operation.rb +2 -0
- data/lib/fog/compute/google/requests/get_http_health_check.rb +2 -0
- data/lib/fog/compute/google/requests/get_image.rb +2 -0
- data/lib/fog/compute/google/requests/get_image_from_family.rb +2 -0
- data/lib/fog/compute/google/requests/get_instance_group.rb +2 -0
- data/lib/fog/compute/google/requests/get_instance_group_manager.rb +2 -0
- data/lib/fog/compute/google/requests/get_instance_template.rb +2 -0
- data/lib/fog/compute/google/requests/get_machine_type.rb +2 -0
- data/lib/fog/compute/google/requests/get_network.rb +2 -0
- data/lib/fog/compute/google/requests/get_project.rb +2 -0
- data/lib/fog/compute/google/requests/get_region.rb +2 -0
- data/lib/fog/compute/google/requests/get_route.rb +2 -0
- data/lib/fog/compute/google/requests/get_server.rb +2 -0
- data/lib/fog/compute/google/requests/get_server_serial_port_output.rb +2 -0
- data/lib/fog/compute/google/requests/get_snapshot.rb +2 -0
- data/lib/fog/compute/google/requests/get_ssl_certificate.rb +2 -0
- data/lib/fog/compute/google/requests/get_subnetwork.rb +2 -0
- data/lib/fog/compute/google/requests/get_target_http_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/get_target_https_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/get_target_instance.rb +2 -0
- data/lib/fog/compute/google/requests/get_target_pool.rb +2 -0
- data/lib/fog/compute/google/requests/get_target_pool_health.rb +2 -0
- data/lib/fog/compute/google/requests/get_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/get_zone.rb +2 -0
- data/lib/fog/compute/google/requests/get_zone_operation.rb +2 -0
- data/lib/fog/compute/google/requests/insert_address.rb +2 -0
- data/lib/fog/compute/google/requests/insert_backend_service.rb +2 -0
- data/lib/fog/compute/google/requests/insert_disk.rb +8 -5
- data/lib/fog/compute/google/requests/insert_firewall.rb +2 -0
- data/lib/fog/compute/google/requests/insert_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/insert_global_address.rb +2 -0
- data/lib/fog/compute/google/requests/insert_global_forwarding_rule.rb +2 -0
- data/lib/fog/compute/google/requests/insert_http_health_check.rb +2 -0
- data/lib/fog/compute/google/requests/insert_image.rb +2 -0
- data/lib/fog/compute/google/requests/insert_instance_group.rb +2 -0
- data/lib/fog/compute/google/requests/insert_instance_group_manager.rb +2 -0
- data/lib/fog/compute/google/requests/insert_instance_template.rb +2 -0
- data/lib/fog/compute/google/requests/insert_network.rb +2 -0
- data/lib/fog/compute/google/requests/insert_route.rb +2 -0
- data/lib/fog/compute/google/requests/insert_server.rb +6 -0
- data/lib/fog/compute/google/requests/insert_ssl_certificate.rb +2 -0
- data/lib/fog/compute/google/requests/insert_subnetwork.rb +2 -0
- data/lib/fog/compute/google/requests/insert_target_http_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/insert_target_https_proxy.rb +2 -0
- data/lib/fog/compute/google/requests/insert_target_instance.rb +2 -0
- data/lib/fog/compute/google/requests/insert_target_pool.rb +2 -0
- data/lib/fog/compute/google/requests/insert_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/invalidate_url_map_cache.rb +2 -0
- data/lib/fog/compute/google/requests/list_addresses.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_addresses.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_disk_types.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_disks.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_forwarding_rules.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_instance_group_managers.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_instance_groups.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_machine_types.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_servers.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_subnetworks.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_target_instances.rb +2 -0
- data/lib/fog/compute/google/requests/list_aggregated_target_pools.rb +2 -0
- data/lib/fog/compute/google/requests/list_disk_types.rb +2 -0
- data/lib/fog/compute/google/requests/list_disks.rb +2 -0
- data/lib/fog/compute/google/requests/list_firewalls.rb +2 -0
- data/lib/fog/compute/google/requests/list_forwarding_rules.rb +2 -0
- data/lib/fog/compute/google/requests/list_global_addresses.rb +2 -0
- data/lib/fog/compute/google/requests/list_global_forwarding_rules.rb +2 -0
- data/lib/fog/compute/google/requests/list_global_operations.rb +2 -0
- data/lib/fog/compute/google/requests/list_http_health_checks.rb +2 -0
- data/lib/fog/compute/google/requests/list_images.rb +2 -0
- data/lib/fog/compute/google/requests/list_instance_group_instances.rb +2 -0
- data/lib/fog/compute/google/requests/list_instance_group_managers.rb +2 -0
- data/lib/fog/compute/google/requests/list_instance_groups.rb +2 -0
- data/lib/fog/compute/google/requests/list_instance_templates.rb +2 -0
- data/lib/fog/compute/google/requests/list_machine_types.rb +2 -0
- data/lib/fog/compute/google/requests/list_networks.rb +2 -0
- data/lib/fog/compute/google/requests/list_region_operations.rb +2 -0
- data/lib/fog/compute/google/requests/list_regions.rb +2 -0
- data/lib/fog/compute/google/requests/list_routes.rb +2 -0
- data/lib/fog/compute/google/requests/list_servers.rb +2 -0
- data/lib/fog/compute/google/requests/list_snapshots.rb +2 -0
- data/lib/fog/compute/google/requests/list_ssl_certificates.rb +2 -0
- data/lib/fog/compute/google/requests/list_subnetworks.rb +2 -0
- data/lib/fog/compute/google/requests/list_target_http_proxies.rb +2 -0
- data/lib/fog/compute/google/requests/list_target_https_proxies.rb +2 -0
- data/lib/fog/compute/google/requests/list_target_instances.rb +2 -0
- data/lib/fog/compute/google/requests/list_target_pools.rb +2 -0
- data/lib/fog/compute/google/requests/list_url_maps.rb +2 -0
- data/lib/fog/compute/google/requests/list_zone_operations.rb +2 -0
- data/lib/fog/compute/google/requests/list_zones.rb +2 -0
- data/lib/fog/compute/google/requests/patch_firewall.rb +2 -0
- data/lib/fog/compute/google/requests/patch_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/recreate_instances.rb +2 -0
- data/lib/fog/compute/google/requests/remove_instance_group_instances.rb +2 -0
- data/lib/fog/compute/google/requests/remove_target_pool_health_checks.rb +2 -0
- data/lib/fog/compute/google/requests/remove_target_pool_instance.rb +2 -0
- data/lib/fog/compute/google/requests/remove_target_pool_instances.rb +2 -0
- data/lib/fog/compute/google/requests/reset_server.rb +2 -0
- data/lib/fog/compute/google/requests/reset_windows_password.rb +154 -0
- data/lib/fog/compute/google/requests/set_common_instance_metadata.rb +2 -0
- data/lib/fog/compute/google/requests/set_forwarding_rule_target.rb +2 -0
- data/lib/fog/compute/google/requests/set_global_forwarding_rule_target.rb +2 -0
- data/lib/fog/compute/google/requests/set_instance_template.rb +2 -0
- data/lib/fog/compute/google/requests/set_server_disk_auto_delete.rb +2 -0
- data/lib/fog/compute/google/requests/set_server_machine_type.rb +23 -0
- data/lib/fog/compute/google/requests/set_server_metadata.rb +3 -1
- data/lib/fog/compute/google/requests/set_server_scheduling.rb +2 -0
- data/lib/fog/compute/google/requests/set_server_tags.rb +2 -0
- data/lib/fog/compute/google/requests/set_snapshot_labels.rb +2 -0
- data/lib/fog/compute/google/requests/set_subnetwork_private_ip_google_access.rb +2 -0
- data/lib/fog/compute/google/requests/set_target_http_proxy_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/set_target_https_proxy_ssl_certificates.rb +2 -0
- data/lib/fog/compute/google/requests/set_target_https_proxy_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/set_target_pool_backup.rb +2 -0
- data/lib/fog/compute/google/requests/start_server.rb +2 -0
- data/lib/fog/compute/google/requests/stop_server.rb +2 -0
- data/lib/fog/compute/google/requests/update_firewall.rb +2 -0
- data/lib/fog/compute/google/requests/update_http_health_check.rb +2 -0
- data/lib/fog/compute/google/requests/update_url_map.rb +2 -0
- data/lib/fog/compute/google/requests/validate_url_map.rb +2 -0
- data/lib/fog/dns/google.rb +1 -1
- data/lib/fog/dns/google/requests/create_change.rb +2 -0
- data/lib/fog/dns/google/requests/create_managed_zone.rb +2 -0
- data/lib/fog/dns/google/requests/delete_managed_zone.rb +2 -0
- data/lib/fog/dns/google/requests/get_change.rb +2 -0
- data/lib/fog/dns/google/requests/get_managed_zone.rb +2 -0
- data/lib/fog/dns/google/requests/get_project.rb +2 -0
- data/lib/fog/dns/google/requests/list_changes.rb +2 -0
- data/lib/fog/dns/google/requests/list_managed_zones.rb +2 -0
- data/lib/fog/dns/google/requests/list_resource_record_sets.rb +2 -0
- data/lib/fog/google/models/sql/ssl_cert.rb +7 -1
- data/lib/fog/google/models/sql/user.rb +2 -0
- data/lib/fog/google/monitoring.rb +2 -1
- data/lib/fog/google/pubsub.rb +1 -1
- data/lib/fog/google/requests/monitoring/create_metric_descriptor.rb +2 -0
- data/lib/fog/google/requests/monitoring/create_timeseries.rb +3 -1
- data/lib/fog/google/requests/monitoring/delete_metric_descriptor.rb +2 -0
- data/lib/fog/google/requests/monitoring/get_metric_descriptor.rb +2 -0
- data/lib/fog/google/requests/monitoring/list_monitored_resource_descriptors.rb +2 -0
- data/lib/fog/google/requests/monitoring/list_timeseries.rb +2 -0
- data/lib/fog/google/requests/pubsub/pull_subscription.rb +5 -1
- data/lib/fog/google/requests/sql/clone_instance.rb +2 -0
- data/lib/fog/google/requests/sql/delete_backup_run.rb +2 -0
- data/lib/fog/google/requests/sql/delete_instance.rb +2 -0
- data/lib/fog/google/requests/sql/delete_ssl_cert.rb +2 -0
- data/lib/fog/google/requests/sql/delete_user.rb +3 -1
- data/lib/fog/google/requests/sql/export_instance.rb +2 -0
- data/lib/fog/google/requests/sql/get_backup_run.rb +2 -0
- data/lib/fog/google/requests/sql/get_instance.rb +2 -0
- data/lib/fog/google/requests/sql/get_operation.rb +2 -0
- data/lib/fog/google/requests/sql/get_ssl_cert.rb +2 -0
- data/lib/fog/google/requests/sql/import_instance.rb +2 -0
- data/lib/fog/google/requests/sql/insert_backup_run.rb +2 -0
- data/lib/fog/google/requests/sql/insert_instance.rb +2 -0
- data/lib/fog/google/requests/sql/insert_ssl_cert.rb +2 -0
- data/lib/fog/google/requests/sql/insert_user.rb +2 -0
- data/lib/fog/google/requests/sql/list_backup_runs.rb +2 -0
- data/lib/fog/google/requests/sql/list_flags.rb +2 -0
- data/lib/fog/google/requests/sql/list_instances.rb +2 -0
- data/lib/fog/google/requests/sql/list_operations.rb +2 -0
- data/lib/fog/google/requests/sql/list_ssl_certs.rb +2 -0
- data/lib/fog/google/requests/sql/list_tiers.rb +2 -0
- data/lib/fog/google/requests/sql/list_users.rb +2 -0
- data/lib/fog/google/requests/sql/reset_instance_ssl_config.rb +2 -0
- data/lib/fog/google/requests/sql/restart_instance.rb +2 -0
- data/lib/fog/google/requests/sql/restore_instance_backup.rb +2 -0
- data/lib/fog/google/requests/sql/update_instance.rb +2 -0
- data/lib/fog/google/requests/sql/update_user.rb +2 -0
- data/lib/fog/google/shared.rb +115 -55
- data/lib/fog/google/sql.rb +1 -1
- data/lib/fog/google/version.rb +1 -1
- data/lib/fog/storage/google_json.rb +5 -1
- data/lib/fog/storage/google_json/mock.rb +6 -0
- data/lib/fog/storage/google_json/real.rb +106 -3
- data/lib/fog/storage/google_json/requests/copy_object.rb +2 -0
- data/lib/fog/storage/google_json/requests/delete_bucket.rb +2 -0
- data/lib/fog/storage/google_json/requests/delete_object.rb +2 -0
- data/lib/fog/storage/google_json/requests/get_bucket.rb +2 -0
- data/lib/fog/storage/google_json/requests/get_bucket_acl.rb +2 -0
- data/lib/fog/storage/google_json/requests/get_object.rb +2 -0
- data/lib/fog/storage/google_json/requests/get_object_acl.rb +2 -0
- data/lib/fog/storage/google_json/requests/get_object_metadata.rb +2 -0
- data/lib/fog/storage/google_json/requests/list_bucket_acl.rb +2 -0
- data/lib/fog/storage/google_json/requests/list_buckets.rb +2 -0
- data/lib/fog/storage/google_json/requests/list_object_acl.rb +2 -0
- data/lib/fog/storage/google_json/requests/list_objects.rb +2 -0
- data/lib/fog/storage/google_json/requests/put_bucket.rb +2 -0
- data/lib/fog/storage/google_json/requests/put_bucket_acl.rb +2 -0
- data/lib/fog/storage/google_json/requests/put_object.rb +2 -0
- data/lib/fog/storage/google_json/requests/put_object_acl.rb +2 -0
- data/lib/fog/storage/google_json/utils.rb +1 -1
- data/lib/fog/storage/google_xml/models/file.rb +1 -1
- data/lib/fog/storage/google_xml/requests/get_bucket.rb +0 -1
- data/lib/fog/storage/google_xml/requests/head_object.rb +7 -6
- data/lib/fog/storage/google_xml/requests/put_bucket_acl.rb +2 -0
- data/tasks/changelog.rake +37 -0
- data/tasks/test.rake +6 -2
- data/test/helpers/integration_test_helper.rb +17 -6
- data/test/helpers/test_helper.rb +1 -0
- data/test/integration/compute/core_compute/test_servers.rb +40 -0
- data/test/integration/compute/core_compute/test_zones.rb +1 -1
- data/test/integration/compute/core_networking/test_addresses.rb +23 -0
- data/test/integration/factories/{sql_v1_certs_factory.rb → sql_certs_factory.rb} +3 -3
- data/test/integration/factories/{sql_v1_instances_factory.rb → sql_instances_factory.rb} +3 -3
- data/test/integration/factories/{sql_v1_users_factory.rb → sql_users_factory.rb} +6 -3
- data/test/integration/monitoring/test_metric_descriptors.rb +2 -0
- data/test/integration/monitoring/test_timeseries.rb +14 -26
- data/test/integration/pubsub/test_pubsub_models.rb +3 -3
- data/test/integration/pubsub/test_pubsub_requests.rb +2 -2
- data/test/integration/sql/{sqlv1/test_v1_certs.rb → test_certs.rb} +3 -3
- data/test/integration/sql/{sqlv1/test_common_flags.rb → test_common_flags.rb} +0 -0
- data/test/integration/sql/{sqlv1/test_common_tiers.rb → test_common_tiers.rb} +0 -0
- data/test/integration/sql/{sqlv1/test_coverage.rb → test_coverage.rb} +1 -1
- data/test/integration/sql/{sqlv2/test_v2_instances.rb → test_instances.rb} +22 -2
- data/test/integration/sql/{sqlv1/test_v1_users.rb → test_users.rb} +4 -4
- data/test/integration/test_authentication.rb +0 -7
- data/test/unit/storage/test_common_xml_collections.rb +11 -0
- data/test/unit/storage/test_json_requests.rb +0 -1
- metadata +50 -31
- data/test/integration/factories/sql_v2_instances_factory.rb +0 -19
- data/test/integration/sql/sqlv1/test_v1_instances.rb +0 -31
- data/test/integration/sql/sqlv2/test_coverage.rb +0 -6
@@ -0,0 +1,154 @@
|
|
1
|
+
# Copyright 2015 Google Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# Changes:
|
16
|
+
# March 2020: Modified example found here:
|
17
|
+
# https://github.com/GoogleCloudPlatform/compute-image-windows/blob/master/examples/windows_auth_python_sample.py
|
18
|
+
# to enable fog-google to change windows passwords.
|
19
|
+
|
20
|
+
require "openssl"
|
21
|
+
require "base64"
|
22
|
+
require "json"
|
23
|
+
|
24
|
+
module Fog
|
25
|
+
module Compute
|
26
|
+
class Google
|
27
|
+
class Mock
|
28
|
+
def reset_windows_password(_server:, _user:)
|
29
|
+
Fog::Mock.not_implemented
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Real
|
34
|
+
##
|
35
|
+
# Resets Windows passwords for users on Google's Windows based images. Code based on Google provided example.
|
36
|
+
#
|
37
|
+
# @param instance [String] the name of the instance
|
38
|
+
# @param zone [String] the name of the zone of the instance
|
39
|
+
# @param user [String] the user whose password should be reset
|
40
|
+
#
|
41
|
+
# @return [String] new password
|
42
|
+
#
|
43
|
+
# @see https://cloud.google.com/compute/docs/instances/windows/automate-pw-generation
|
44
|
+
def reset_windows_password(server:, user:)
|
45
|
+
# Pull the e-mail address of user authenticated to API
|
46
|
+
email = @compute.request_options.authorization.issuer
|
47
|
+
|
48
|
+
# Create a new key
|
49
|
+
key = OpenSSL::PKey::RSA.new(2048)
|
50
|
+
modulus, exponent = get_modulus_exponent_in_base64(key)
|
51
|
+
|
52
|
+
# Get Old Metadata
|
53
|
+
old_metadata = server.metadata
|
54
|
+
|
55
|
+
# Create JSON Object with needed information
|
56
|
+
metadata_entry = get_json_string(user, modulus, exponent, email)
|
57
|
+
|
58
|
+
# Create new metadata object
|
59
|
+
new_metadata = update_windows_keys(old_metadata, metadata_entry)
|
60
|
+
|
61
|
+
# Set metadata on instance
|
62
|
+
server.set_metadata(new_metadata, false)
|
63
|
+
|
64
|
+
# Get encrypted password from Serial Port 4 Output
|
65
|
+
|
66
|
+
# If machine is booting for the first time, there appears to be a
|
67
|
+
# delay before the password appears on the serial port.
|
68
|
+
sleep(1) until server.ready?
|
69
|
+
serial_port_output = server.serial_port_output(:port => 4)
|
70
|
+
loop_cnt = 0
|
71
|
+
while serial_port_output.empty?
|
72
|
+
if loop_cnt > 12
|
73
|
+
Fog::Logger.warning("Encrypted password never found on Serial Output Port 4")
|
74
|
+
raise "Could not reset password."
|
75
|
+
end
|
76
|
+
sleep(5)
|
77
|
+
serial_port_output = server.serial_port_output(:port => 4)
|
78
|
+
loop_cnt += 1
|
79
|
+
end
|
80
|
+
|
81
|
+
# Parse and decrypt password
|
82
|
+
enc_password = get_encrypted_password_from_serial_port(serial_port_output, modulus)
|
83
|
+
password = decrypt_password(enc_password, key)
|
84
|
+
|
85
|
+
return password
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_modulus_exponent_in_base64(key)
|
89
|
+
mod = [key.n.to_s(16)].pack("H*").strip
|
90
|
+
exp = [key.e.to_s(16)].pack("H*").strip
|
91
|
+
modulus = Base64.strict_encode64(mod).strip
|
92
|
+
exponent = Base64.strict_encode64(exp).strip
|
93
|
+
return modulus, exponent
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_expiration_time_string
|
97
|
+
utc_now = Time.now.utc
|
98
|
+
expire_time = utc_now + 5 * 60
|
99
|
+
return expire_time.strftime("%Y-%m-%dT%H:%M:%SZ")
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_json_string(user, modulus, exponent, email)
|
103
|
+
expire = get_expiration_time_string
|
104
|
+
data = { 'userName': user,
|
105
|
+
'modulus': modulus,
|
106
|
+
'exponent': exponent,
|
107
|
+
'email': email,
|
108
|
+
'expireOn': expire }
|
109
|
+
return ::JSON.dump(data)
|
110
|
+
end
|
111
|
+
|
112
|
+
def update_windows_keys(old_metadata, metadata_entry)
|
113
|
+
if old_metadata[:items]
|
114
|
+
new_metadata = Hash[old_metadata[:items].map { |item| [item[:key], item[:value]] }]
|
115
|
+
else
|
116
|
+
new_metadata = {}
|
117
|
+
end
|
118
|
+
new_metadata["windows-keys"] = metadata_entry
|
119
|
+
return new_metadata
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_encrypted_password_from_serial_port(serial_port_output, modulus)
|
123
|
+
output = serial_port_output.split("\n")
|
124
|
+
output.reverse_each do |line|
|
125
|
+
begin
|
126
|
+
if line.include?("modulus") && line.include?("encryptedPassword")
|
127
|
+
entry = ::JSON.parse(line)
|
128
|
+
if modulus == entry["modulus"]
|
129
|
+
return entry["encryptedPassword"]
|
130
|
+
end
|
131
|
+
else
|
132
|
+
next
|
133
|
+
end
|
134
|
+
rescue ::JSON::ParserError
|
135
|
+
Fog::Logger.warning("Parsing encrypted password from serial output
|
136
|
+
failed. Trying to parse next matching line.")
|
137
|
+
next
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def decrypt_password(enc_password, key)
|
143
|
+
decoded_password = Base64.strict_decode64(enc_password)
|
144
|
+
begin
|
145
|
+
return key.private_decrypt(decoded_password, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
|
146
|
+
rescue OpenSSL::PKey::RSAError
|
147
|
+
Fog::Logger.warning("Error decrypting password received from Google.
|
148
|
+
Maybe check output on Serial Port 4 and Metadata key: windows-keys?")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Google
|
4
|
+
class Mock
|
5
|
+
def set_server_machine_type(_instance, _zone, _machine_type)
|
6
|
+
# :no-coverage:
|
7
|
+
Fog::Mock.not_implemented
|
8
|
+
# :no-coverage:
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Real
|
13
|
+
def set_server_machine_type(instance, zone, machine_type)
|
14
|
+
request = ::Google::Apis::ComputeV1::InstancesSetMachineTypeRequest.new
|
15
|
+
zone = zone.split("/")[-1]
|
16
|
+
machine_type = machine_type.split("/")[-1]
|
17
|
+
request.machine_type = "zones/#{zone}/machineTypes/#{machine_type}"
|
18
|
+
@compute.set_instance_machine_type(@project, zone, instance, request)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,7 +3,9 @@ module Fog
|
|
3
3
|
class Google
|
4
4
|
class Mock
|
5
5
|
def set_server_metadata(_instance, _zone, _fingerprint, _metadata_items = {})
|
6
|
+
# :no-coverage:
|
6
7
|
Fog::Mock.not_implemented
|
8
|
+
# :no-coverage:
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
@@ -19,7 +21,7 @@ module Fog
|
|
19
21
|
# fingerprint = instance.metadata['fingerprint']
|
20
22
|
# @param [Hash] metadata A new metadata object
|
21
23
|
# Should have the following structure:
|
22
|
-
# {
|
24
|
+
# {'foo' => 'bar', 'baz'=>'foo'}
|
23
25
|
#
|
24
26
|
# @returns [::Google::Apis::ComputeV1::Operation] set operation
|
25
27
|
def set_server_metadata(instance, zone, fingerprint, metadata_items = [])
|