HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4...

13
HYCU Data Protection as a Service for GCP Service update date: April 2, 2020 Document edition: First API QUICK START

Transcript of HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4...

Page 1: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

HYCU Data Protection as a Service for GCP

Service update date: April 2, 2020

Document edition: First

API QUICK START

Page 2: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

2

Legal noticesCopyright notice© 2020 HYCU. All rights reserved.

This document contains proprietary information, which is protected by copyright. No part of this document may be photocopied, reproduced, distributed, transmitted, stored in a retrieval system, modified or translated to another language in any form by any means, without the prior written consent of HYCU.

TrademarksHYCU logos, names, trademarks and/or service marks and combinations thereof are the property of HYCU or its affiliates. Other product names are the property of their respective trademark or service mark holders and are hereby acknowledged.

GCP™ and Google Cloud Platform™ are trademarks of Google LLC.

DisclaimerThe details and descriptions contained in this document are believed to have been accurate and up to date at the time the document was written. The information contained in this document is subject to change without notice.

HYCU provides this material "as is" and makes no warranty of any kind, expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. HYCU shall not be liable for errors and omissions contained herein. In no event shall HYCU be liable for any direct, indirect, consequential, punitive, special or incidental damages, including, without limitation, damages for loss and profits, loss of anticipated savings, business interruption, or loss of information arising out of the use or inability to use this document, or any action taken based on the information contained herein, even if it has been advised of the possibility of such damages, whether based on warranty, contract, or any other legal theory.

The only warranties for HYCU products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty.

NoticeThis document is provided in connection with HYCU products. HYCU may have copyright, patents, patent applications, trademark, or other intellectual property rights covering the subject matter of this document.

www.hycu.com

Page 3: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

3

Except as expressly provided in any written license agreement from HYCU, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property on HYCU products. Use of underlying HYCU product(s) is governed by their respective Software License and Support Terms.

Important: Please read Software License and Support Terms before using the accompanying software product(s).

 

HYCUwww.hycu.com

www.hycu.com

Page 4: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

4

Introduction to HYCU for GCP APIHYCU Data Protection as a Service for GCP (HYCU for GCP) enables you to automate all of your data protection activities by using its REST-based application programming interface (API). This document helps you start exploring automation possibilities provided by the solution.

The process of using the HYCU for GCP API includes the following sequence of phases:

 1. Familiarize yourself with the available API methods. See “Accessing API reference documentation” below.

 2. Fulfill prerequisites for using the API. See “Prerequisites for using the API” below.

 3. Authorize the API requests that you will invoke. See “Authorizing API requests” on the next page.

i Important  Make sure that you do this regularly before the validity of the bearer token expires.

 4. Invoke your API requests.

Accessing API reference documentationDocumentation of the HYCU for GCP API is based on the standard OpenAPI specification format, and available through Swagger UI. To access the documentation, open a web browser and go to the solution's central HYCU Data Protection as a Service for GCP API webpage. From this webpage you can also invoke API requests once your access is authorized.

Prerequisites for using the APIThe prerequisites are as follows:

 l You have a fair understanding of the HYCU for GCP operating principles. Reading chapter About HYCU for GCP of the HYCU Data Protection as a Service for GCP User Guide is recommended.

 l Make sure that access to the HYCU for GCP functionality through API is enabled.

To enable the access, configure a protection set service account in HYCU for GCP. For instructions, see the HYCU Data Protection as a Service for GCP User Guide.

i Important  Keep in mind that the chosen service account must fulfill all

www.hycu.com

Page 5: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

5

applicable prerequisites documented in the listed section, including the prerequisites for using the HYCU for GCP API.

Authorizing API requestsFollow these steps:

 1. Acquire a valid OAuth 2.0 bearer token. For instructions, see “Acquiring bearer tokens” below.

 2. Apply the bearer token to authorize API requests that you will invoke. For instructions, see “Applying bearer tokens” on the next page.

Bearer tokens are valid for the duration of 60 minutes. To keep API access authorized without interruption, you must apply a new valid token in time before validity of the current token expires.

Acquiring bearer tokensFor general information on bearer tokens (API keys) for APIs of Google Cloud Platform apps, see the Using API Keys  |  Authentication  |  Google Cloud webpage and other parts of Google Cloud Platform documentation.

The following example includes a program in the Python programming language that you can use to acquire a new bearer token for HYCU for GCP API.

Example   To be able to run this program, replace <PathToServiceAccountJSONFile> with pathname of the actual file that stores the service account information, including its private key, in the JSON format.

import json from google.oauth2 import service_account from googleapiclient import discovery SCOPES = ['https://www.googleapis.com/auth/cloud-platform'] SERVICE_ACCOUNT_FILE = '<PathToServiceAccountJSONFile>' CLIENT_ID = '225038073315-sbrhk8s4hgucmhk1hnd2h2t6ofp0ff5g.apps .googleusercontent.com' # GENERATE SERVICE ACCOUNT ID TOKEN credentials = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, scopes=SCOPES) with open(SERVICE_ACCOUNT_FILE) as f: data = json.load(f)

www.hycu.com

Page 6: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

6

email = data["client_email"] iamcredentials = discovery.build('iamcredentials', 'v1', credentials=credentials) print("Generating ID token for Service Account '%s'..." % email) name = 'projects/-/serviceAccounts/' + email generate_id_token_request = { 'includeEmail': True, 'audience': CLIENT_ID } request = iamcredentials.projects().serviceAccounts().generateIdToken(name=name, body=generate_id_token_request) response = request.execute() id_token = "Bearer %s" % response["token"] print("Token:\n%s" % id_token)

Applying bearer tokensYou must apply the bearer token to the following endpoints to authorize all API requests and take full advantage of the HYCU for GCP API:

 l Main HYCU for GCP endpoint

 l Endpoint specific to your service subscription

You can complete authorization interactively or programmatically.

Example   This example includes a procedure to interactively authorize API requests that you will make to the main HYCU for GCP endpoint on the endpoint's webpage.

Do the following:

 1. Make sure that the acquired bearer token is still valid.

 2. Copy the bearer token string that you acquired earlier. The string starts with the Bearer prefix.

 3. Open a web browser and go to the solution's central HYCU Data Protection as a Service for GCP API webpage.

 4. In the upper-right part of the webpage, click Authorize.

www.hycu.com

Page 7: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

7

 5. In the Available authorizations dialog box, paste the bearer token string that you acquired in step 2 of the procedure into the Value text box, and click Authorize.

Example   This example includes a procedure to retrieve a list of instances (already identified by HYCU for GCP) that belong to the default protection set once API requests to the main HYCU for GCP endpoint are already authorized.

Do the following:

 1. Make sure that the acquired bearer token is still valid.

 2. From the solution's central HYCU Data Protection as a Service for GCP API webpage, invoke the following API request:

GET auth/currentAuthority

 3. In the request response, search for the billing account ID of the desired HYCU for GCP subscription, and then determine the matching managerUrl property. Example line with this property:

"managerUrl": "https://my-endpoint.manager.gcp.hycu.com"

 4. In the web browser, go to the following HYCU Data Protection as a Service for GCP API webpage that corresponds to the endpoint of your service subscription:

https://my-endpoint.manager.gcp.hycu.com/swagger

 5. In the upper-right part of the webpage, click Authorize.

 6. In the Available authorizations dialog box, paste the bearer token string that you acquired in step 2 of the procedure (in the first example) into the Value text box, and click Authorize.

 7. From the webpage corresponding to the endpoint of your service subscription, invoke the following API request:

GET protectionSets/default-protection-set/instances

www.hycu.com

Page 8: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

8

Example program: assigning a backup policy to an instanceThe following Python program is an example of how you can assign a backup policy to an instance in your Google Cloud Platform project by using the HYCU for GCP API. It includes an entire flow from the bearer token acquisition to the policy assignment. For general prerequisites for using the program, see “Prerequisites for using the API” on page 4.

Example   To be able to run this program, make the following replacements in the source code: l Replace <PathToServiceAccountJSONFile> with pathname of the actual file that stores

the service account information, including its private key, in the JSON format. l Replace <ProjectID> with the ID of your Google Cloud Platform project. l Replace <ZoneName> with the name of the Google Cloud Platform zone where the

desired instance resides. l Replace <InstanceName> with the name of the instance that you want to assign the

backup policy to. l Replace <ProtectionSetName> with the name of the HYCU for GCP protection set which

your project is part of. l Replace <PolicyName> with the name of the backup policy that you want to assign.

import json from google.oauth2 import service_account from googleapiclient import discovery import http from http import client import ssl from json import JSONDecodeError REGISTRY_ENDPOINT = 'endpoints.hycu.com' SCOPES = ['https://www.googleapis.com/auth/cloud-platform'] CLIENT_ID = '225038073315-sbrhk8s4hgucmhk1hnd2h2t6ofp0ff5g.apps.googleusercontent.com' SERVICE_ACCOUNT_FILE = '<PathToServiceAccountJSONFile>' # Instance unique identifier: PROJECT_ID = '<ProjectID>' ZONE_NAME = '<ZoneName>'

www.hycu.com

Page 9: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

9

INSTANCE_NAME = '<InstanceName>' # Policy unique identifier: PROTECTION_SET_NAME = '<ProtectionSetName>' POLICY_NAME = '<PolicyName>' def request_id_token(client_id, scopes, request_service_account): # Generate credentials credentials = service_account.Credentials.from_service_account_file(request_service_account, scopes=scopes) iam_credentials = discovery.build('iamcredentials', 'v1', credentials=credentials) with open(request_service_account) as f: data_file = json.load(f) email = data_file["client_email"] print("Generating ID token for Service Account '%s'..." % email) name = 'projects/-/serviceAccounts/' + email generate_id_token_request = { 'includeEmail': True, 'audience': client_id } request = iam_credentials.projects().serviceAccounts().generateIdToken(name=name, body=generate_id_token_request) response_generate_id_token = request.execute() return "Bearer %s" % response_generate_id_token["token"] def get_manager_url(connection, header): url = "/api/v1/auth/currentAuthority" connection.request(method="GET", url=url, body={}, headers=header) r = connection.getresponse() output = json.loads(r.read()) return output['items'][0]['subscriptions'][0]['managerUrl'].split('//')[1] def policy_assign(protection_set_name, project, zone, instance_name, policy_name, connection, header): # Define the body body = { "instanceInfoList": [ { "name": instance_name,

www.hycu.com

Page 10: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

10

"zone": zone, "projectId": project } ] } json_body = json.dumps(body) url = "/api/v1/protectionSets/{}/policies/{}:assign".format(protection_set_name, policy_name) # Creating the request: 'POST /api/v1/protectionSets/<ProtectionSetName>/policies/<PolicyName>:assign' connection.request(method="POST", url=url, body=json_body, headers=header) return connection.getresponse() def print_response(response): print('Response status: %d' % response.status) temp = response.read() try: print_data = json.loads(temp) print(json.dumps(print_data, indent=4, sort_keys=True)) return print_data except JSONDecodeError: print(temp) # Establish connection to Registry registry_endpoint_connection = http.client.HTTPSConnection(REGISTRY_ENDPOINT) id_token = request_id_token(CLIENT_ID, SCOPES, SERVICE_ACCOUNT_FILE) print("Token:\n%s" % id_token) headers = { 'Content-type': 'application/json', 'Authorization': id_token } # Establish connection to Manager MANAGER_ENDPOINT = get_manager_url(registry_endpoint_connection, headers) print("Manager URL: " + MANAGER_ENDPOINT) manager_endpoint_connection = http.client.HTTPSConnection(MANAGER_ENDPOINT, context=ssl._create_unverified_context()) # Assign the policy r = policy_assign(GROUP_NAME, PROJECT_ID, ZONE_NAME, INSTANCE_NAME,

www.hycu.com

Page 11: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

11

POLICY_NAME, manager_endpoint_connection, headers) print_response(r)

www.hycu.com

Page 12: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

API QUICK START

12

HYCU Customer Support and informationUse the communication channels listed in this section if you need:

 l Help with the HYCU for GCP subscription process

 l Assistance while using HYCU for GCP

 l Additional information about HYCU for GCP

 l Information about other HYCU products and services

Customer SupportShould you require additional information or assistance while using the service, contact the vendor that arranged its subscription for you.

If you have subscribed to the service yourself, and are experiencing a problem, search for a solution on the HYCU Customer Support webpage. In the absence of an article addressing your problem, ask HYCU Customer Support for assistance: on the webpage, sign in with a valid user account, click Submit a request, and then fill in the request form. You should have received user account information by email after subscribing to the service.

Important: Before submitting a request to HYCU Customer Support, collect troubleshooting information. For a list of the relevant pieces of information, check troubleshooting sections in the service documentation.

Company resources on the webFor more information about our company and other products and services in our offering, visit the HYCU | Simplifying Multi-cloud Data Protection website. For additional product- or service-related information, watch videos on the HYCU, Inc. - YouTube channel. HYCU is

also present on social networks. Follow us on Twitter and LinkedIn .

General informationFor questions related to product or service business, purchase of HYCU products, or subscription to other HYCU services, send an email to [email protected].

FeedbackFor comments or suggestions about this service, including its documentation, send an email to [email protected]. We will be glad to hear from you!

www.hycu.com

Page 13: HYCU Data Protection as a Service for GCP API Quick Start · 2020-04-02 · APIQUICKSTART 4 Introduction to HYCU for GCP API HYCU Data Protection as a Service for GCP (HYCU for GCP)

 

www.hycu.com