Skip to content

Commit 40df08b

Browse files
feat(tailscale): Tailscale Source plugin (#5546)
Implements #5507 #### Summary <!-- Explain what problem this PR addresses --> <!-- Use the following steps to ensure your PR is ready to be reviewed - [ ] Read the [contribution guidelines](../blob/main/CONTRIBUTING.md) 🧑‍🎓 - [ ] Test locally on your own infrastructure - [ ] Run `go fmt` to format your code 🖊 - [ ] Lint your changes via `golangci-lint run` 🚨 (install golangci-lint [here](https://golangci-lint.run/usage/install/#local-installation)) - [ ] Update or add tests 🧪 - [ ] Ensure the status checks below are successful ✅ ---> Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
1 parent 147becb commit 40df08b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2220
-0
lines changed

.github/styles/Vocab/Base/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ ELBs
156156
CMK
157157
CMKs
158158
serverless
159+
tailnet
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Source Plugin Tailscale Workflow
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "plugins/source/tailscale/**"
7+
- ".github/workflows/source_tailscale.yml"
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- "plugins/source/tailscale/**"
13+
- ".github/workflows/source_tailscale.yml"
14+
15+
jobs:
16+
plugins-source-tailscale:
17+
timeout-minutes: 30
18+
name: "plugins/source/tailscale"
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: ./plugins/source/tailscale
23+
steps:
24+
- uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 2
27+
- name: Set up Go 1.x
28+
uses: actions/setup-go@v3
29+
with:
30+
go-version-file: plugins/source/tailscale/go.mod
31+
cache: true
32+
cache-dependency-path: plugins/source/tailscale/go.sum
33+
- name: golangci-lint
34+
uses: golangci/golangci-lint-action@v3
35+
with:
36+
version: v1.50.1
37+
working-directory: plugins/source/tailscale
38+
args: "--config ../../.golangci.yml"
39+
- name: Get dependencies
40+
run: go get -t -d ./...
41+
- name: Build
42+
run: go build .
43+
- name: Test
44+
run: make test
45+
- name: gen
46+
if: github.event_name == 'pull_request'
47+
run: make gen
48+
- name: Cleanup after build
49+
run: rm ./tailscale
50+
- name: Fail if generation updated files
51+
if: github.event_name == 'pull_request'
52+
run: test "$(git status -s | wc -l)" -eq 0
53+
validate-release:
54+
timeout-minutes: 30
55+
runs-on: ubuntu-latest
56+
env:
57+
CGO_ENABLED: 0
58+
steps:
59+
- name: Checkout
60+
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
61+
uses: actions/checkout@v3
62+
- uses: actions/cache@v3
63+
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
64+
with:
65+
path: |
66+
~/.cache/go-build
67+
~/go/pkg/mod
68+
key: ${{ runner.os }}-go-1.19.3-release-cache-${{ hashFiles('plugins/source/tailscale/go.sum') }}
69+
restore-keys: |
70+
${{ runner.os }}-go-1.19.3-release-cache-plugins-source-tailscale
71+
- name: Set up Go
72+
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
73+
uses: actions/setup-go@v3
74+
with:
75+
go-version-file: plugins/source/tailscale/go.mod
76+
- name: Install GoReleaser
77+
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
78+
uses: goreleaser/goreleaser-action@v3
79+
with:
80+
distribution: goreleaser-pro
81+
version: latest
82+
install-only: true
83+
- name: Run GoReleaser Dry-Run
84+
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
85+
run: goreleaser release --snapshot --rm-dist --skip-validate --skip-publish --skip-sign -f ./plugins/source/tailscale/.goreleaser.yaml
86+
env:
87+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

.github/workflows/wait_for_required_workflows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
"plugins/source/heroku",
5454
"plugins/source/k8s",
5555
"plugins/source/okta",
56+
"plugins/source/tailscale",
5657
"plugins/source/terraform",
5758
"plugins/source/test",
5859
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tailscale
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variables:
2+
component: source/tailscale
3+
binary: tailscale
4+
5+
project_name: plugins/source/tailscale
6+
7+
monorepo:
8+
tag_prefix: plugins-source-tailscale-
9+
dir: plugins/source/tailscale
10+
11+
includes:
12+
- from_file:
13+
# Relative to the directory Go Releaser is run from (which is the root of the repository)
14+
path: ./plugins/.goreleaser.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/dnephin/pre-commit-golang
3+
rev: v0.5.0
4+
hooks:
5+
# - id: go-mod-tidy
6+
- id: golangci-lint

plugins/source/tailscale/CHANGELOG.md

Whitespace-only changes.

plugins/source/tailscale/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Unit tests
2+
.PHONY: test
3+
test:
4+
go test -timeout 3m ./...
5+
6+
.PHONY: lint
7+
lint:
8+
@golangci-lint run --config ../../.golangci.yml
9+
10+
.PHONY: gen-code
11+
gen-code:
12+
grep -rl '// Code generated by codegen; DO NOT EDIT.' resources/services/* | xargs rm
13+
go run codegen/main.go
14+
15+
.PHONY: gen-docs
16+
gen-docs:
17+
rm -rf ./docs/tables/*
18+
go run main.go doc ./docs/tables
19+
sed 's_(\(.*\))_(https://github.com/cloudquery/cloudquery/blob/main/plugins/source/tailscale/docs/tables/\1)_' docs/tables/README.md > ../../../website/pages/docs/plugins/sources/tailscale/tables.md
20+
21+
# All gen targets
22+
.PHONY: gen
23+
gen: gen-code gen-docs

plugins/source/tailscale/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tailscale Plugin
2+
3+
The CloudQuery Tailscale plugin pulls configuration out of Tailscale and loads it into any supported CloudQuery destination (e.g. PostgreSQL).
4+
5+
## Links
6+
7+
- [User Guide](https://docs.cloudquery.io/docs/plugins/sources/tailscale/overview)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/cloudquery/plugin-sdk/schema"
8+
"github.com/cloudquery/plugin-sdk/specs"
9+
"github.com/rs/zerolog"
10+
"github.com/tailscale/tailscale-client-go/tailscale"
11+
)
12+
13+
type Client struct {
14+
*tailscale.Client
15+
tailnet string
16+
logger zerolog.Logger
17+
}
18+
19+
var _ schema.ClientMeta = (*Client)(nil)
20+
21+
func (c *Client) ID() string {
22+
return c.tailnet
23+
}
24+
25+
func (c *Client) Logger() *zerolog.Logger {
26+
return &c.logger
27+
}
28+
29+
func Configure(_ context.Context, logger zerolog.Logger, spec specs.Source) (schema.ClientMeta, error) {
30+
tsSpec := new(Spec)
31+
err := spec.UnmarshalSpec(tsSpec)
32+
if err != nil {
33+
return nil, fmt.Errorf("failed to unmarshal spec: %w", err)
34+
}
35+
36+
client, err := tsSpec.getClient()
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to create Tailscale client: %w", err)
39+
}
40+
return &Client{
41+
Client: client,
42+
tailnet: tsSpec.Tailnet,
43+
logger: logger,
44+
}, nil
45+
}

0 commit comments

Comments
 (0)