diff --git a/secretmanager/snippets/secret_intro.ipynb b/secretmanager/snippets/secret_intro.ipynb new file mode 100644 index 00000000000..354e75ca9dc --- /dev/null +++ b/secretmanager/snippets/secret_intro.ipynb @@ -0,0 +1,108 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "28fb3454", + "metadata": {}, + "source": [ + "# Introduction to Secret Manager\n", + "\n", + "TODO(glasnt): write secret intro" + ] + }, + { + "cell_type": "markdown", + "id": "1fbaf44f", + "metadata": {}, + "source": [ + "## Before you begin\n", + "\n", + "1. [Enable the Secret Manager API](https://cloud.google.com/secret-manager/docs/configuring-secret-manager)\n", + "1. Set up authentication\n", + " * TODO(glasnt): details\n", + "\n", + "## Required roles\n", + "\n", + "TODO(glasnt): `roles/secretmanager.admin`\n", + "\n", + "## Install dependencies" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "024d207a", + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa2c0cb5", + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "%%capture\n", + "%pip install google-cloud-secret-manager" + ] + }, + { + "cell_type": "markdown", + "id": "ea877cf5", + "metadata": {}, + "source": [ + "## Create a secret" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21414ea1", + "metadata": {}, + "outputs": [], + "source": [ + "# [START secret_create_secret_notebook]\n", + "from google.cloud import secretmanager\n", + "\n", + "project_id = \"PROJECT_ID\"\n", + "secret_id = \"SECRET_ID\"\n", + "\n", + "client = secretmanager.SecretManagerServiceClient()\n", + "response = client.create_secret(\n", + " parent=f\"projects/{project_id}\",\n", + " secret_id=secret_id,\n", + " secret={\"replication\": {\"automatic\": {}}},\n", + ")\n", + "\n", + "print(f\"Created secret: {response.name}\")\n", + "# [END secret_create_secret_notebook]" + ] + }, + { + "cell_type": "markdown", + "id": "2ba37c38", + "metadata": {}, + "source": [ + "## Dev Notes\n", + "\n", + "* `# @param {type:\"string\"}` only works for Google Colabs. " + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/secretmanager/snippets/secret_intro.py b/secretmanager/snippets/secret_intro.py new file mode 100644 index 00000000000..807e1916462 --- /dev/null +++ b/secretmanager/snippets/secret_intro.py @@ -0,0 +1,57 @@ +# Copyright 2025 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. + +# Hello developer! This file uses special syntax to import parts of +# this file into the Google Cloud documentation +# +# You can safely ignore any line that starts with: +# * `# [START ` +# * `# [END ` +# + +# [START secret_create_secret_ipy_style] +from google.cloud import secretmanager +# [END secret_create_secret_ipy_style] + +""" +# Define these values to use this sample: +# [START secret_create_secret_ipy_style] + +project_id = "PROJECT_ID" +secret_id = "SECRET_ID" + +# [END secret_create_secret_ipy_style] +""" + +def create_secret(project_id, secret_id): + # [START secret_create_secret_ipy_style] + # [START secret_create_secret_ipy_style_indent] + client = secretmanager.SecretManagerServiceClient() + response = client.create_secret( + parent=f"projects/{project_id}", + secret_id=secret_id, + secret={"replication": {"automatic": {}}}, + ) + + print(f"Created secret: {response.name}") + # [END secret_create_secret_ipy_style_indent] + # [END secret_create_secret_ipy_style] + return response + +# [START secret_create_secret_ipy_style] +""" +Run this sample: +create_secret(project_id, secret_id) +""" +# [END secret_create_secret_ipy_style]