Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
# Unix-style newlines at the bottom of every file
end_of_line = lf
charset = utf-8

# indentation style and size
indent_style = space
indent_size = 2

# Make sure every file has a blank line at the end
insert_final_newline = true

# Remove any whitespace characters preceding newline characters
trim_trailing_whitespace = true

# Give operators breathing room, but not brackets
spaces_around_operators = true
spaces_around_brackets = false

# 4 space indentation
[*.{py,java}]
indent_size = 4

[*.json]
indent_size = 4

# 2 space indentation
[*.{js,html}]
indent_size = 2

[*.{tf}]
indent_size = 2

[*.rb]
indent_size = 2

[*.yml]
indent_size = 2

[*.yaml]
indent_size = 2

[*.{md}]
indent_size = unset
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is a comment. Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in the repo. @oneanupam will be requested for review when someone opens a pull request.

- @oneanupam
5 changes: 5 additions & 0 deletions .github/conventional-commit-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Config for GitHub App that ensures that commit messages and pull requests are based on conventionalcommits.org
# https://github.com/googleapis/repo-automation-bots/tree/main/packages/conventional-commit-lint

enabled: true
always_check_pr_title: true
15 changes: 15 additions & 0 deletions .github/pull-request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Description
Please include a short summary of the update made along with the context.

## Checklist
- [ ] Self-review of the code is performed.
- [ ] Code has been fully tested and completely functional.

## Type of Change
- [ ] break: Resolved a breaking change. This will increment the major version.
- [ ] feat: A new feature or enhancement added to the codebase. This will increment the minor version.
- [ ] fix: A bug fix or correction to resolve an issue. This will increment the patch version.
- [ ] chore: Other changes not directly affecting the code (e.g., documentation update). No version increment.

## Reference
https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository
40 changes: 40 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pull Request Checks

on:
pull_request:
branches:
- master
types:
- opened
- synchronize
- reopened

jobs:
pull-request-check:
runs-on: ubuntu-latest
steps:
# Checkout the repository code
- name: Code checkout
id: code_checkout
uses: actions/checkout@v4

# Check PR title prefix to ensure it follows the convention
- name: Check PR title prefix
run: |
echo "PR Title: '${{ github.event.pull_request.title }}'"

if [[ ! "${{ github.event.pull_request.title }}" =~ ^(ci|feat|fix|chore|docs|refactor): ]]; then
echo "❌ PR title must start with one of: ci:, feat:, fix:, chore:, docs:, refactor:"
exit 1
else
echo "✅ PR title is valid."
fi

# Scan the repo for any sensitive information like secrets etc
- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
with:
path: ./ # Code repository path
base: "" # Start scanning from here
head: ${{ github.head_ref || github.ref_name }} # Scan commits until here
extra_args: --only-verified
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: no-commit-to-branch
args: [--branch, main, --branch, master]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: detect-private-key
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"EditorConfig.EditorConfig"
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true
}
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contribution

This document provides guidelines for contributing to the project.

## Pull Request

Pull requests are the best way to propose changes to the codebase (we use ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)). We actively welcome your pull requests:

1. Fork the repository to your own Github account.
2. Clone the project to your machine.
3. Create a branch locally with a succinct but descriptive name.
4. Commit changes to the branch following any formatting and testing guidelines specific to this repo.
5. Push changes to your forked repository.
6. Open a Pull Request in our repository.

## Guidelines

### Commit Message Guidelines

Use the combination of "Commit Type" and "Commit Summary" with an optional "Commit description".

- Commit Type: Use the proper commit type for the changes as per [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) types.
- Commit Summary: Always use the imperative present tense (Write your commit messages as if you're giving a command or describing what the commit does, not what you did). Don’t capitalize the first letter of the commit message. Don’t use a period at the end of your text.

```
Ex: Suppose, You updated a file. So, the commit message could be -
docs: update readme file
feat: add application dockerfile
```

### PR Guidelines

Format: [Commit Type] Short Summary

```
Ex: Suppose, You added some functionality. So, the title could be -
[feat] added function to read input from user
```

### Coding Guidelines

- Try to put comments in your code, where required.
- Try to follow DRY (Don't Repeat Yourself) principle.
- Follow the style guide to write terraform code recommended by terraform.

## Report Bugs

We use GitHub issues to track bugs. Report a bug by opening a new issue.

## Linting and Formatting

All of the bash scripts in the repository must be linted or formatted using `shellcheck` to maintain a standard of quality.

- On the web, Paste a shell script on https://www.shellcheck.net for instant feedback. ShellCheck.net is always synchronized to the latest git commit, and is the easiest way to give ShellCheck a go.
- From your terminal, Run shellcheck yourscript in your terminal for instant output,

## License

By contributing, you agree that your contributions will be licensed under its [MIT License](LICENSE).
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# python-gcp-samples

This repository contains python samples intended to use in day to day operational activities on google cloud platform.
Usecases for which the python scripts are written can be found [here](./usecases.md).

## Prerequisites

Below prerequisites must be fulfilled for the successful execution of code.

### Software Requirement

Resources in this repository are meant for use with Python 3.x (check the version using `python3 --version`) and pip3 (check the version using `pip3 --version`). If you don't have the compatible version, download it from official python repository.

- [python3](https://www.python.org/downloads/) >= 3.9.2
- [python3](https://www.python.org/downloads/) >= 3.13.2
- [pip3](https://pypi.org/project/pip/) >= 20.3.4

### Bootstrap Virtual Environment

[venv](https://docs.python.org/3/library/venv.html) is a tool that creates isolated Python environments. These isolated environments can have separate versions of Python packages, which allows you to isolate one project's dependencies from the dependencies of other projects.

**Linux**

```
cd your-project
python3 -m venv env
Expand All @@ -28,35 +33,41 @@ Resources in this repository are meant for use with Python 3.x (check the versio
**Note:** Follow the [google article](https://cloud.google.com/python/docs/setup) to setup your Python development environment.

## Quick Start

If you want to quickly run and test Python samples without installing python, the recommended approach is to use Cloud Shell.

Cloud Shell is a Compute Engine virtual machine. The service credentials associated with this virtual machine are automatic, so there is no need to set up or download a service account key.

Cloud shell terminal is preloaded with softwares and utilities such as Python, gcloud command-line tool, kubectl, and more. letting you get started with less setup.

- **Step-01:** Activate Cloud Shell at the top of the Google Cloud Console.
- **Step-02:** Clone this repository: `git clone https://github.com/anupam-sy/python-gcp-samples.git`
- **Step-03:** Setup the python virtual environment using [Bootstrap Virtual Environment](#bootstrap-virtual-environment).

### Authentication and Authorization

This client library used in the python script supports authentication via Google Application Default Credentials, or by providing a JSON key file for a Service Account. Google Application Default Credentials (ADC) is the recommended way to authorize and authenticate clients.

## Accessing Cloud APIs

You can access Cloud APIs using client libraries available for many popular programming languages While you can use Google Cloud APIs directly by making raw requests to the server, client libraries provide simplifications that significantly reduce the amount of code you need to write.

1. Cloud Client Libraries are the recommended option for accessing Cloud APIs programmatically, where available. Cloud Client Libraries use the latest client library model.
[NEW - Recommended Way] https://github.com/googleapis/google-cloud-python
1. Cloud Client Libraries are the recommended option for accessing Cloud APIs programmatically, where available. Cloud Client Libraries use the latest client library model.
[NEW - Recommended Way] https://github.com/googleapis/google-cloud-python

2. A few Google Cloud APIs don't have Cloud Client Libraries available in all languages. If you want to use one of these APIs and there is no Cloud Client Library for your preferred language, you can still use the previous style of client library, called Google API Client Libraries.
[OLD - Not Recommended] https://github.com/googleapis/google-api-python-client
2. A few Google Cloud APIs don't have Cloud Client Libraries available in all languages. If you want to use one of these APIs and there is no Cloud Client Library for your preferred language, you can still use the previous style of client library, called Google API Client Libraries.
[OLD - Not Recommended] https://github.com/googleapis/google-api-python-client

**Note:** It is recommended to use Cloud Client Libraries for Python, where possible, for new code development due to the following reasons:

With Cloud Client Libraries for Python:

- There is a separate client library for each API, so you can choose which client libraries to download. Whereas, google-api-python-client is a single client library for all APIs. As a result, the total package size for google-api-python-client exceeds 50MB.
- There are stricter controls for breaking changes to the underlying APIs as each client library is focused on a specific API.
- There are more features in these Cloud Client Libraries as each library is focused on a specific API, and in some cases, the libraries are owned by team who specialized in that API.

## References

- https://cloud.google.com/python/docs/setup
- https://cloud.google.com/apis/docs/overview
- https://cloud.google.com/apis/docs/client-libraries-explained
Expand All @@ -70,7 +81,9 @@ With Cloud Client Libraries for Python:
- https://github.com/GoogleCloudPlatform/python-docs-samples

## License

This repository is under MIT License.

## Providing feedback
Open an issue in this GitHub repository.

Open an issue in this GitHub repository.
File renamed without changes.
File renamed without changes.