The Google Cloud client libraries for Swift automatically configure the endpoint for each service. Some applications might need to override the default endpoint, either because their network has specific requirements or because they need to use regional versions of a service. This document shows you how to override the default endpoint.
Before you begin
This document uses the Secret Manager API. To enable this API, follow
the Secret Manager quickstart. Verify that your
principal has permissions to list secrets, such as the Secret Manager Viewer
Identity and Access Management (IAM) role (roles/secretmanager.viewer).
For complete setup instructions for the Swift client libraries, see Quickstart: Get started with Swift.
Configure a regional endpoint
In this example, you configure the client library to use Secret Manager regional endpoints. You can use the same override to configure the endpoint with one of the private access options, or for locational endpoints in the services that support them.
To configure a regional endpoint, follow these steps:
Add the imports required to use the client library:
Write a function that receives the project ID and region as parameters:
Initialize a client and override the endpoint to use a regional endpoint:
Use the client to retrieve the list of secrets in a region and iterate over the results:
After configuring the endpoint, running your application returns secrets stored in the specified region. You can also enable debug logging to verify that requests target the overridden host.
Complete code
The following example shows the complete code for this document:
What's next
- Learn how to enable debug logging to troubleshoot requests and responses.
- Learn how to configure package traits for large client libraries.
- Browse the Google Cloud client libraries for Swift reference documentation.