mirror of
https://github.com/Kichiyaki/terraform-provider-woodpecker.git
synced 2024-06-26 14:27:41 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
fbc3b39840 | |||
|
b728dee457 | ||
|
a51316d0f6 | ||
014265dc57 | |||
1763f24888 | |||
67956ca230 | |||
|
d3ac9bd8ff | ||
|
4b6064c66d |
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
|
@ -30,14 +30,14 @@ jobs:
|
|||
- run: make generate && go mod tidy && git diff --exit-code go.mod docs/ examples/
|
||||
- uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.54
|
||||
- name: Gitea 1.20 & Woodpecker 1.0
|
||||
version: v1.55
|
||||
- name: Gitea 1.21 & Woodpecker 2.0
|
||||
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
env:
|
||||
GITEA_IMAGE: gitea/gitea:1.20
|
||||
WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v1.0
|
||||
- name: Forgejo 1.20 & Woodpecker 1.0
|
||||
GITEA_IMAGE: gitea/gitea:1.21
|
||||
WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.4.1
|
||||
- name: Forgejo 1.21 & Woodpecker 2.0
|
||||
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
env:
|
||||
GITEA_IMAGE: codeberg.org/forgejo/forgejo:1.20
|
||||
WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v1.0
|
||||
GITEA_IMAGE: codeberg.org/forgejo/forgejo:1.21
|
||||
WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.4.1
|
||||
|
|
394
.golangci.yml
394
.golangci.yml
|
@ -1,6 +1,8 @@
|
|||
run:
|
||||
tests: true
|
||||
timeout: 5m
|
||||
skip-dirs:
|
||||
- internal/woodpecker
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
|
@ -10,7 +12,6 @@ linters:
|
|||
- bodyclose
|
||||
- bidichk
|
||||
- exportloopref
|
||||
- depguard
|
||||
- errcheck
|
||||
- gocritic
|
||||
- gosec
|
||||
|
@ -30,8 +31,6 @@ linters:
|
|||
- nestif
|
||||
- thelper
|
||||
- nonamedreturns
|
||||
- gocyclo
|
||||
- gomnd
|
||||
- tenv
|
||||
- testpackage
|
||||
- noctx
|
||||
|
@ -51,27 +50,19 @@ linters:
|
|||
- predeclared
|
||||
- promlinter
|
||||
- wastedassign
|
||||
- testifylint
|
||||
- inamedparam
|
||||
- sloglint
|
||||
- revive
|
||||
|
||||
linters-settings:
|
||||
tagliatelle:
|
||||
case:
|
||||
rules:
|
||||
json: camel
|
||||
tfsdk: snake
|
||||
bun: snake
|
||||
lll:
|
||||
line-length: 150
|
||||
gocyclo:
|
||||
min-complexity: 10
|
||||
depguard:
|
||||
rules:
|
||||
main:
|
||||
files:
|
||||
- "$all"
|
||||
deny:
|
||||
- pkg: reflect
|
||||
desc: Please don't use reflect package
|
||||
- pkg: github.com/pkg/errors
|
||||
desc: Should be replaced by standard lib errors package
|
||||
line-length: 120
|
||||
govet:
|
||||
enable:
|
||||
- asmdecl
|
||||
|
@ -109,18 +100,375 @@ linters-settings:
|
|||
- unsafeptr
|
||||
- unusedresult
|
||||
- unusedwrite
|
||||
gomnd:
|
||||
ignored-functions:
|
||||
- strconv.FormatInt
|
||||
- strconv.ParseInt
|
||||
testifylint:
|
||||
enable-all: true
|
||||
sloglint:
|
||||
attr-only: true
|
||||
revive:
|
||||
rules:
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
|
||||
- name: add-constant
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments:
|
||||
- maxLitCount: "3"
|
||||
allowStrs: "\"\""
|
||||
ignoreFuncs: os.Exit,wg.Add,make
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit
|
||||
- name: argument-limit
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments: [4]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic
|
||||
- name: atomic
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#banned-characters
|
||||
- name: banned-characters
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments: []
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return
|
||||
- name: bare-return
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports
|
||||
- name: blank-imports
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
|
||||
- name: bool-literal-in-expr
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#call-to-gc
|
||||
- name: call-to-gc
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cognitive-complexity
|
||||
- name: cognitive-complexity
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments: [7]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#comment-spacings
|
||||
- name: comment-spacings
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-naming
|
||||
- name: confusing-naming
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-results
|
||||
- name: confusing-results
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr
|
||||
- name: constant-logical-expr
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
|
||||
- name: context-as-argument
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- allowTypesBefore: "*testing.T,testing.TB"
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type
|
||||
- name: context-keys-type
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cyclomatic
|
||||
- name: cyclomatic
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments: [10]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#datarace
|
||||
- name: datarace
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit
|
||||
- name: deep-exit
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer
|
||||
- name: defer
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- [call-chain, loop]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports
|
||||
- name: dot-imports
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports
|
||||
- name: duplicated-imports
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
|
||||
- name: early-return
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- preserveScope
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
|
||||
- name: empty-block
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
|
||||
- name: empty-lines
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#enforce-map-style
|
||||
- name: enforce-map-style
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- make
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming
|
||||
- name: error-naming
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return
|
||||
- name: error-return
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings
|
||||
- name: error-strings
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf
|
||||
- name: errorf
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported
|
||||
- name: exported
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments:
|
||||
- preserveScope
|
||||
- checkPrivateReceivers
|
||||
- sayRepetitiveInsteadOfStutters
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header
|
||||
- name: file-header
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments:
|
||||
- This is the text that must appear at the top of source files.
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter
|
||||
- name: flag-parameter
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-result-limit
|
||||
- name: function-result-limit
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments: [3]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-length
|
||||
- name: function-length
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments: [10, 0]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#get-return
|
||||
- name: get-return
|
||||
severity: warning
|
||||
disabled: true
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches
|
||||
- name: identical-branches
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
|
||||
- name: if-return
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement
|
||||
- name: increment-decrement
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow
|
||||
- name: indent-error-flow
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments:
|
||||
- preserveScope
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-alias-naming
|
||||
- name: import-alias-naming
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments:
|
||||
- ^[a-z][a-z0-9]{0,}$
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#imports-blacklist
|
||||
- name: imports-blacklist
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- reflect
|
||||
- github.com/pkg/errors
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
|
||||
- name: import-shadowing
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
|
||||
- name: line-length-limit
|
||||
severity: warning
|
||||
# lll is enabled
|
||||
disabled: true
|
||||
arguments: [80]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#max-public-structs
|
||||
- name: max-public-structs
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments: [3]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-parameter
|
||||
- name: modifies-parameter
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-value-receiver
|
||||
- name: modifies-value-receiver
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#nested-structs
|
||||
- name: nested-structs
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#optimize-operands-order
|
||||
- name: optimize-operands-order
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments
|
||||
- name: package-comments
|
||||
severity: warning
|
||||
disabled: true
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range
|
||||
- name: range
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure
|
||||
- name: range-val-in-closure
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address
|
||||
- name: range-val-address
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming
|
||||
- name: receiver-naming
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-import-alias
|
||||
- name: redundant-import-alias
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id
|
||||
- name: redefines-builtin-id
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-of-int
|
||||
- name: string-of-int
|
||||
severity: warning
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
|
||||
- name: string-format
|
||||
severity: warning
|
||||
disabled: true
|
||||
arguments:
|
||||
- - core.WriteError[1].Message
|
||||
- /^([^A-Z]|$)/
|
||||
- must not start with a capital letter
|
||||
- - fmt.Errorf[0]
|
||||
- /(^|[^\.!?])$/
|
||||
- must not end in punctuation
|
||||
- - panic
|
||||
- /^[^\n]*$/
|
||||
- must not contain line breaks
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
|
||||
- name: struct-tag
|
||||
arguments:
|
||||
- json,inline
|
||||
- bson,outline,gnu
|
||||
severity: warning
|
||||
# tagliatelle is enabled
|
||||
disabled: true
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else
|
||||
- name: superfluous-else
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- preserveScope
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal
|
||||
- name: time-equal
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-naming
|
||||
- name: time-naming
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
|
||||
- name: var-naming
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- [] # AllowList
|
||||
- [] # DenyList
|
||||
- - upperCaseConst: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration
|
||||
- name: var-declaration
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion
|
||||
- name: unconditional-recursion
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming
|
||||
- name: unexported-naming
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
|
||||
- name: unexported-return
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
|
||||
- name: unhandled-error
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments:
|
||||
- fmt.Printf
|
||||
- fmt.Println
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt
|
||||
- name: unnecessary-stmt
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unreachable-code
|
||||
- name: unreachable-code
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
|
||||
- name: unused-parameter
|
||||
severity: error
|
||||
disabled: false
|
||||
arguments:
|
||||
- allowRegex: ^_
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
|
||||
- name: unused-receiver
|
||||
severity: error
|
||||
disabled: true
|
||||
arguments:
|
||||
- allowRegex: ^_
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
|
||||
- name: useless-break
|
||||
severity: error
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value
|
||||
- name: waitgroup-by-value
|
||||
severity: warning
|
||||
disabled: false
|
||||
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
# Exclude some linters from running on tests files.
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- dupl
|
||||
- gocyclo
|
||||
- gosec
|
||||
- path: _test\.go
|
||||
text: deep-exit
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate "
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
repos:
|
||||
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
|
||||
rev: v9.5.0
|
||||
rev: v9.13.0
|
||||
hooks:
|
||||
- id: commitlint
|
||||
stages: [commit-msg]
|
||||
additional_dependencies: ['@commitlint/config-conventional']
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.54.2
|
||||
rev: v1.55.2
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
|
|
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ install-tfplugindocs:
|
|||
.PHONY: install-golangci-lint
|
||||
install-golangci-lint:
|
||||
@echo "Installing github.com/golangci/golangci-lint..."
|
||||
@(test -f $(GOLANGCI_LINT_PATH) && echo "github.com/golangci/golangci-lint is already installed. Skipping...") || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.54.2
|
||||
@(test -f $(GOLANGCI_LINT_PATH) && echo "github.com/golangci/golangci-lint is already installed. Skipping...") || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.55.2
|
||||
|
||||
.PHONY: install-tools
|
||||
install-tools: install-golangci-lint install-tfplugindocs
|
||||
|
|
|
@ -33,6 +33,5 @@ data "woodpecker_repository_secret" "test_secret" {
|
|||
|
||||
### Read-Only
|
||||
|
||||
- `email` (String) email used for authentication
|
||||
- `id` (Number) the id of the registry
|
||||
- `username` (String) username used for authentication
|
||||
|
|
|
@ -33,7 +33,6 @@ data "woodpecker_repository_secret" "test_secret" {
|
|||
|
||||
### Read-Only
|
||||
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual)
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)
|
||||
- `id` (Number) the secret's id
|
||||
- `images` (Set of String) list of Docker images for which this secret is available
|
||||
- `plugins_only` (Boolean) whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)
|
||||
|
|
|
@ -27,7 +27,6 @@ data "woodpecker_secret" "test_secret" {
|
|||
|
||||
### Read-Only
|
||||
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual)
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)
|
||||
- `id` (Number) the secret's id
|
||||
- `images` (Set of String) list of Docker images for which this secret is available
|
||||
- `plugins_only` (Boolean) whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)
|
||||
|
|
|
@ -4,12 +4,17 @@ page_title: "woodpecker Provider"
|
|||
subcategory: ""
|
||||
description: |-
|
||||
A Terraform provider used to interact with Woodpecker CI https://woodpecker-ci.org/ resources.
|
||||
v0.2.x and later versions of the provider work with Woodpecker 2.x+v0.1.x version of the provider works with Woodpecker 2.0.0>1.x>=1.0.0
|
||||
---
|
||||
|
||||
# woodpecker Provider
|
||||
|
||||
A Terraform provider used to interact with [Woodpecker CI](https://woodpecker-ci.org/) resources.
|
||||
|
||||
|
||||
- v0.2.x and later versions of the provider work with Woodpecker 2.x+
|
||||
- v0.1.x version of the provider works with Woodpecker 2.0.0>1.x>=1.0.0
|
||||
|
||||
## Example Usage
|
||||
|
||||
```terraform
|
||||
|
|
|
@ -37,10 +37,6 @@ resource "woodpecker_repository_secret" "test" {
|
|||
- `repository_id` (Number) the ID of the repository
|
||||
- `username` (String) username used for authentication
|
||||
|
||||
### Optional
|
||||
|
||||
- `email` (String) email used for authentication
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `id` (Number) the id of the registry
|
||||
|
|
|
@ -32,7 +32,7 @@ resource "woodpecker_repository_secret" "test" {
|
|||
|
||||
### Required
|
||||
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual)
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)
|
||||
- `name` (String) the name of the secret
|
||||
- `repository_id` (Number) the ID of the repository
|
||||
- `value` (String, Sensitive) the value of the secret
|
||||
|
@ -40,7 +40,6 @@ resource "woodpecker_repository_secret" "test" {
|
|||
### Optional
|
||||
|
||||
- `images` (Set of String) list of Docker images for which this secret is available, leave blank to allow all images
|
||||
- `plugins_only` (Boolean) whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)
|
||||
|
||||
### Read-Only
|
||||
|
||||
|
|
|
@ -26,14 +26,13 @@ resource "woodpecker_secret" "test" {
|
|||
|
||||
### Required
|
||||
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual)
|
||||
- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)
|
||||
- `name` (String) the name of the secret
|
||||
- `value` (String, Sensitive) the value of the secret
|
||||
|
||||
### Optional
|
||||
|
||||
- `images` (Set of String) list of Docker images for which this secret is available, leave blank to allow all images
|
||||
- `plugins_only` (Boolean) whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)
|
||||
|
||||
### Read-Only
|
||||
|
||||
|
|
37
go.mod
37
go.mod
|
@ -3,15 +3,15 @@ module github.com/Kichiyaki/terraform-provider-woodpecker
|
|||
go 1.21
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20230815151548-091528835fc2
|
||||
github.com/google/uuid v1.3.1
|
||||
code.gitea.io/sdk/gitea v0.16.0
|
||||
github.com/Masterminds/semver/v3 v3.2.1
|
||||
github.com/google/uuid v1.4.0
|
||||
github.com/hashicorp/terraform-plugin-framework v1.3.5
|
||||
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
|
||||
github.com/hashicorp/terraform-plugin-go v0.18.0
|
||||
github.com/hashicorp/terraform-plugin-testing v1.4.0
|
||||
github.com/hashicorp/terraform-plugin-testing v1.5.1
|
||||
github.com/ory/dockertest/v3 v3.10.0
|
||||
github.com/woodpecker-ci/woodpecker v1.0.2
|
||||
golang.org/x/oauth2 v0.12.0
|
||||
golang.org/x/oauth2 v0.14.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/agext/levenshtein v1.2.2 // indirect
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/cloudflare/circl v1.3.3 // indirect
|
||||
github.com/cloudflare/circl v1.3.7 // indirect
|
||||
github.com/containerd/continuity v0.3.0 // indirect
|
||||
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||
github.com/docker/cli v20.10.24+incompatible // indirect
|
||||
|
@ -31,9 +31,10 @@ require (
|
|||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/go-fed/httpsig v1.1.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
|
||||
|
@ -41,7 +42,7 @@ require (
|
|||
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
|
||||
github.com/hashicorp/go-hclog v1.5.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/hashicorp/go-plugin v1.5.1 // indirect
|
||||
github.com/hashicorp/go-plugin v1.5.2 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||
github.com/hashicorp/go-version v1.6.0 // indirect
|
||||
github.com/hashicorp/hc-install v0.5.2 // indirect
|
||||
|
@ -51,10 +52,11 @@ require (
|
|||
github.com/hashicorp/terraform-json v0.17.1 // indirect
|
||||
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
|
||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0 // indirect
|
||||
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
|
||||
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
|
||||
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
|
||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
|
||||
github.com/imdario/mergo v0.3.13 // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
|
@ -69,22 +71,25 @@ require (
|
|||
github.com/opencontainers/runc v1.1.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/stretchr/testify v1.8.3 // indirect
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
github.com/zclconf/go-cty v1.13.3 // indirect
|
||||
golang.org/x/crypto v0.13.0 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
|
||||
golang.org/x/mod v0.11.0 // indirect
|
||||
golang.org/x/net v0.15.0 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/net v0.18.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.7.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
|
||||
google.golang.org/grpc v1.57.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gotest.tools/v3 v3.4.0 // indirect
|
||||
)
|
||||
|
|
80
go.sum
80
go.sum
|
@ -1,8 +1,10 @@
|
|||
code.gitea.io/sdk/gitea v0.15.1-0.20230815151548-091528835fc2 h1:IFmjjaW1PUn4yUB9a3F59KjVcVMB8TDdocL5Cqy6Xrk=
|
||||
code.gitea.io/sdk/gitea v0.15.1-0.20230815151548-091528835fc2/go.mod h1:ndkDk99BnfiUCCYEUhpNzi0lpmApXlwRFqClBlOlEBg=
|
||||
code.gitea.io/sdk/gitea v0.16.0 h1:gAfssETO1Hv9QbE+/nhWu7EjoFQYKt6kPoyDytQgw00=
|
||||
code.gitea.io/sdk/gitea v0.16.0/go.mod h1:ndkDk99BnfiUCCYEUhpNzi0lpmApXlwRFqClBlOlEBg=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
|
||||
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
|
||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
|
||||
|
@ -24,8 +26,8 @@ github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInq
|
|||
github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E=
|
||||
github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA=
|
||||
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
|
||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
|
||||
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
|
||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
|
||||
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
|
||||
|
@ -77,12 +79,12 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
|
|||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
|
||||
|
@ -96,8 +98,8 @@ github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+
|
|||
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/hashicorp/go-plugin v1.5.1 h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k=
|
||||
github.com/hashicorp/go-plugin v1.5.1/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
|
||||
github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y=
|
||||
github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
|
||||
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
|
@ -116,21 +118,18 @@ github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQH
|
|||
github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o=
|
||||
github.com/hashicorp/terraform-plugin-framework v1.3.5 h1:FJ6s3CVWVAxlhiF/jhy6hzs4AnPHiflsp9KgzTGl1wo=
|
||||
github.com/hashicorp/terraform-plugin-framework v1.3.5/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o=
|
||||
github.com/hashicorp/terraform-plugin-framework v1.4.0 h1:WKbtCRtNrjsh10eA7NZvC/Qyr7zp77j+D21aDO5th9c=
|
||||
github.com/hashicorp/terraform-plugin-framework v1.4.0/go.mod h1:XC0hPcQbBvlbxwmjxuV/8sn8SbZRg4XwGMs22f+kqV0=
|
||||
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
|
||||
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
|
||||
github.com/hashicorp/terraform-plugin-go v0.18.0 h1:IwTkOS9cOW1ehLd/rG0y+u/TGLK9y6fGoBjXVUquzpE=
|
||||
github.com/hashicorp/terraform-plugin-go v0.18.0/go.mod h1:l7VK+2u5Kf2y+A+742GX0ouLut3gttudmvMgN0PA74Y=
|
||||
github.com/hashicorp/terraform-plugin-go v0.19.0/go.mod h1:EhRSkEPNoylLQntYsk5KrDHTZJh9HQoumZXbOGOXmec=
|
||||
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
|
||||
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
|
||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0 h1:gY4SG34ANc6ZSeWEKC9hDTChY0ZiN+Myon17fSA0Xgc=
|
||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0/go.mod h1:deXEw/iJXtJxNV9d1c/OVJrvL7Zh0a++v7rzokW6wVY=
|
||||
github.com/hashicorp/terraform-plugin-testing v1.4.0 h1:DVIXxw7VHZvnwWVik4HzhpC2yytaJ5FpiHxz5debKmE=
|
||||
github.com/hashicorp/terraform-plugin-testing v1.4.0/go.mod h1:b7Bha24iGrbZQjT+ZE8m9crck1YjdVOZ8mfGCQ19OxA=
|
||||
github.com/hashicorp/terraform-registry-address v0.2.2 h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno=
|
||||
github.com/hashicorp/terraform-registry-address v0.2.2/go.mod h1:LtwNbCihUoUZ3RYriyS2wF/lGPB6gF9ICLRtuDk7hSo=
|
||||
github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c=
|
||||
github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0=
|
||||
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
|
||||
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
|
||||
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
|
||||
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
|
||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
|
||||
|
@ -207,7 +206,6 @@ github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXi
|
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||
|
@ -219,12 +217,10 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17
|
|||
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/woodpecker-ci/woodpecker v1.0.2 h1:303z7GVGA4Eks1Uar3TvAun5tXJEVdWa/q7LPe2t2Ss=
|
||||
github.com/woodpecker-ci/woodpecker v1.0.2/go.mod h1:JQkI4/WUzM7qFhu7QfsWEWIIL5c3yad1EHtzq4011/Q=
|
||||
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
|
||||
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
|
||||
|
@ -243,8 +239,10 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
|||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U=
|
||||
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
|
||||
|
@ -257,16 +255,16 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
|||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=
|
||||
golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4=
|
||||
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
||||
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
|
||||
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
|
||||
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -276,6 +274,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -289,21 +288,22 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
|
||||
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -313,10 +313,10 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
|||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
|
||||
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
|
||||
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE=
|
||||
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
|
||||
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryDataSource struct {
|
||||
|
@ -20,11 +20,19 @@ func newRepositoryDataSource() datasource.DataSource {
|
|||
return &repositoryDataSource{}
|
||||
}
|
||||
|
||||
func (d *repositoryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *repositoryDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository"
|
||||
}
|
||||
|
||||
func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
func (d *repositoryDataSource) Schema(
|
||||
_ context.Context,
|
||||
_ datasource.SchemaRequest,
|
||||
resp *datasource.SchemaResponse,
|
||||
) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "Use this data source to retrieve information about a repository.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
|
@ -91,8 +99,9 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
|
|||
Description: "when true, every pipeline needs to be approved before being executed",
|
||||
},
|
||||
"allow_pull_requests": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.",
|
||||
Computed: true,
|
||||
Description: "Enables handling webhook's pull request event." +
|
||||
" If disabled, then pipeline won't run for pull requests.",
|
||||
},
|
||||
"config_file": schema.StringAttribute{
|
||||
Computed: true,
|
||||
|
@ -103,13 +112,18 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
|
|||
"netrc_only_trusted": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " +
|
||||
//nolint:lll
|
||||
"see [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers) for more info",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *repositoryDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *repositoryDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -119,7 +133,10 @@ func (d *repositoryDataSource) Configure(_ context.Context, req datasource.Confi
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryCronDataSource struct {
|
||||
|
@ -20,11 +20,19 @@ func newRepositoryCronDataSource() datasource.DataSource {
|
|||
return &repositoryCronDataSource{}
|
||||
}
|
||||
|
||||
func (d *repositoryCronDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *repositoryCronDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_cron"
|
||||
}
|
||||
|
||||
func (d *repositoryCronDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
func (d *repositoryCronDataSource) Schema(
|
||||
_ context.Context,
|
||||
_ datasource.SchemaRequest,
|
||||
resp *datasource.SchemaResponse,
|
||||
) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "Use this data source to retrieve information about a cron job in a specific repository.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
|
@ -60,7 +68,11 @@ func (d *repositoryCronDataSource) Schema(_ context.Context, _ datasource.Schema
|
|||
}
|
||||
}
|
||||
|
||||
func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *repositoryCronDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -70,7 +82,10 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -78,7 +93,11 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C
|
|||
d.client = client
|
||||
}
|
||||
|
||||
func (d *repositoryCronDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
func (d *repositoryCronDataSource) Read(
|
||||
ctx context.Context,
|
||||
req datasource.ReadRequest,
|
||||
resp *datasource.ReadResponse,
|
||||
) {
|
||||
var data repositoryCronModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryRegistryDataSource struct {
|
||||
|
@ -20,13 +20,22 @@ func newRepositoryRegistryDataSource() datasource.DataSource {
|
|||
return &repositoryRegistryDataSource{}
|
||||
}
|
||||
|
||||
func (d *repositoryRegistryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *repositoryRegistryDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_registry"
|
||||
}
|
||||
|
||||
func (d *repositoryRegistryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
func (d *repositoryRegistryDataSource) Schema(
|
||||
_ context.Context,
|
||||
_ datasource.SchemaRequest,
|
||||
resp *datasource.SchemaResponse,
|
||||
) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "Use this data source to retrieve information about a container registry in a specific repository.",
|
||||
MarkdownDescription: "Use this data source to retrieve information about a container registry" +
|
||||
" in a specific repository.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
|
@ -44,15 +53,15 @@ func (d *repositoryRegistryDataSource) Schema(_ context.Context, _ datasource.Sc
|
|||
Computed: true,
|
||||
Description: "username used for authentication",
|
||||
},
|
||||
"email": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "email used for authentication",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *repositoryRegistryDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -62,7 +71,10 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -70,7 +82,11 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour
|
|||
d.client = client
|
||||
}
|
||||
|
||||
func (d *repositoryRegistryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
func (d *repositoryRegistryDataSource) Read(
|
||||
ctx context.Context,
|
||||
req datasource.ReadRequest,
|
||||
resp *datasource.ReadResponse,
|
||||
) {
|
||||
var data repositoryRegistryDataSourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositorySecretDataSource struct {
|
||||
|
@ -21,11 +21,19 @@ func newRepositorySecretDataSource() datasource.DataSource {
|
|||
return &repositorySecretDataSource{}
|
||||
}
|
||||
|
||||
func (d *repositorySecretDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *repositorySecretDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_secret"
|
||||
}
|
||||
|
||||
func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
func (d *repositorySecretDataSource) Schema(
|
||||
_ context.Context,
|
||||
_ datasource.SchemaRequest,
|
||||
resp *datasource.SchemaResponse,
|
||||
) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "Use this data source to retrieve information about a secret in a specific repository.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
|
@ -44,11 +52,8 @@ func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.Sche
|
|||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)",
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
|
@ -59,7 +64,11 @@ func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.Sche
|
|||
}
|
||||
}
|
||||
|
||||
func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *repositorySecretDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -69,7 +78,10 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -77,7 +89,11 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource
|
|||
d.client = client
|
||||
}
|
||||
|
||||
func (d *repositorySecretDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
func (d *repositorySecretDataSource) Read(
|
||||
ctx context.Context,
|
||||
req datasource.ReadRequest,
|
||||
resp *datasource.ReadResponse,
|
||||
) {
|
||||
var data repositorySecretDataSourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
|
|
@ -41,7 +41,6 @@ data "woodpecker_repository_secret" "test_secret" {
|
|||
resource.TestCheckResourceAttrSet("data.woodpecker_repository_secret.test_secret", "repository_id"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository_secret.test_secret", "name", name),
|
||||
resource.TestCheckTypeSetElemAttr("data.woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -29,7 +29,11 @@ data "woodpecker_repository" "test_repo" {
|
|||
`, repo.FullName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "id"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.woodpecker_repository.test_repo",
|
||||
"forge_remote_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "name", repo.Name),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "owner", repo.Owner.UserName),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "full_name", repo.FullName),
|
||||
|
@ -39,7 +43,11 @@ data "woodpecker_repository" "test_repo" {
|
|||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "scm", "git"),
|
||||
resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "timeout"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "visibility", "public"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo.Private)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.woodpecker_repository.test_repo",
|
||||
"is_private",
|
||||
strconv.FormatBool(repo.Private),
|
||||
),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_trusted", "false"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_gated", "false"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "allow_pull_requests", "true"),
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type secretDataSource struct {
|
||||
|
@ -21,7 +21,11 @@ func newSecretDataSource() datasource.DataSource {
|
|||
return &secretDataSource{}
|
||||
}
|
||||
|
||||
func (d *secretDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *secretDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_secret"
|
||||
}
|
||||
|
||||
|
@ -40,11 +44,8 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
|
|||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)",
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
|
@ -55,7 +56,11 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
|
|||
}
|
||||
}
|
||||
|
||||
func (d *secretDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *secretDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -65,7 +70,10 @@ func (d *secretDataSource) Configure(_ context.Context, req datasource.Configure
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ data "woodpecker_secret" "test_secret" {
|
|||
resource.TestCheckResourceAttrSet("data.woodpecker_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_secret.test_secret", "name", name),
|
||||
resource.TestCheckTypeSetElemAttr("data.woodpecker_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("data.woodpecker_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type userDataSource struct {
|
||||
|
@ -20,7 +20,11 @@ func newUserDataSource() datasource.DataSource {
|
|||
return &userDataSource{}
|
||||
}
|
||||
|
||||
func (d *userDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *userDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_user"
|
||||
}
|
||||
|
||||
|
@ -33,8 +37,9 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r
|
|||
Description: "the user's id",
|
||||
},
|
||||
"login": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The user's login. Use an empty string \"\" to retrieve information about the currently authenticated user.",
|
||||
Required: true,
|
||||
Description: "The user's login. " +
|
||||
"Use an empty string \"\" to retrieve information about the currently authenticated user.",
|
||||
},
|
||||
"email": schema.StringAttribute{
|
||||
Computed: true,
|
||||
|
@ -56,7 +61,11 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r
|
|||
}
|
||||
}
|
||||
|
||||
func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *userDataSource) Configure(
|
||||
_ context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -66,7 +75,10 @@ func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRe
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
@ -48,7 +48,13 @@ func TestMain(m *testing.M) {
|
|||
|
||||
giteaClient = newGiteaClient(resourceGitea.httpURL, resourceGitea.user)
|
||||
|
||||
resourceWoodpecker := runWoodpecker(pool, network, resourceGitea.httpURL, resourceGitea.privateHTTPURL, resourceGitea.user)
|
||||
resourceWoodpecker := runWoodpecker(
|
||||
pool,
|
||||
network,
|
||||
resourceGitea.httpURL,
|
||||
resourceGitea.privateHTTPURL,
|
||||
resourceGitea.user,
|
||||
)
|
||||
deferFuncs = append(deferFuncs, func() {
|
||||
_ = resourceWoodpecker.Close()
|
||||
})
|
||||
|
@ -68,7 +74,6 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
|
||||
os.Exit(code)
|
||||
|
||||
}
|
||||
|
||||
func newDockertestPool() *dockertest.Pool {
|
||||
|
@ -103,7 +108,8 @@ type giteaResource struct {
|
|||
|
||||
func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource {
|
||||
repo, tag := getGiteaRepoTag()
|
||||
gitea, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
|
||||
giteaRsc, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
Repository: repo,
|
||||
Tag: tag,
|
||||
Networks: []*dockertest.Network{network},
|
||||
|
@ -120,13 +126,13 @@ func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource
|
|||
log.Fatalf("couldn't run gitea: %s", err)
|
||||
}
|
||||
|
||||
if err = gitea.Expire(giteaContainerExpInSec); err != nil {
|
||||
if err = giteaRsc.Expire(giteaContainerExpInSec); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
httpURL := &urlpkg.URL{
|
||||
Scheme: "http",
|
||||
Host: getHostPort(gitea, "3000/tcp"),
|
||||
Host: getHostPort(giteaRsc, "3000/tcp"),
|
||||
}
|
||||
|
||||
if err = pool.Retry(func() error {
|
||||
|
@ -158,13 +164,13 @@ func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource
|
|||
}
|
||||
|
||||
return giteaResource{
|
||||
docker: gitea,
|
||||
docker: giteaRsc,
|
||||
httpURL: httpURL,
|
||||
privateHTTPURL: &urlpkg.URL{
|
||||
Scheme: httpURL.Scheme,
|
||||
Host: gitea.GetIPInNetwork(network) + ":3000",
|
||||
Host: giteaRsc.GetIPInNetwork(network) + ":3000",
|
||||
},
|
||||
user: createGiteaUser(pool, gitea),
|
||||
user: createGiteaUser(pool, giteaRsc),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +180,8 @@ func (r giteaResource) Close() error {
|
|||
|
||||
const defaultGiteaImage = "gitea/gitea:1.20"
|
||||
|
||||
func getGiteaRepoTag() (string, string) {
|
||||
//nolint:nonamedreturns
|
||||
func getGiteaRepoTag() (repository string, tag string) {
|
||||
val := os.Getenv("GITEA_IMAGE")
|
||||
if val == "" {
|
||||
val = defaultGiteaImage
|
||||
|
@ -182,7 +189,7 @@ func getGiteaRepoTag() (string, string) {
|
|||
return docker.ParseRepositoryTag(val)
|
||||
}
|
||||
|
||||
func createGiteaUser(pool *dockertest.Pool, gitea *dockertest.Resource) *urlpkg.Userinfo {
|
||||
func createGiteaUser(pool *dockertest.Pool, giteaRsc *dockertest.Resource) *urlpkg.Userinfo {
|
||||
username := strings.ReplaceAll(uuid.NewString(), "-", "")
|
||||
password := uuid.NewString()
|
||||
|
||||
|
@ -190,7 +197,7 @@ func createGiteaUser(pool *dockertest.Pool, gitea *dockertest.Resource) *urlpkg.
|
|||
stdErrBuf := bytes.NewBuffer(nil)
|
||||
|
||||
exec, err := pool.Client.CreateExec(docker.CreateExecOptions{
|
||||
Container: gitea.Container.ID,
|
||||
Container: giteaRsc.Container.ID,
|
||||
User: "git",
|
||||
Cmd: []string{
|
||||
"gitea",
|
||||
|
@ -259,7 +266,7 @@ func runWoodpecker(
|
|||
}
|
||||
|
||||
repo, tag := getWoodpeckerRepoTag()
|
||||
woodpecker, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
woodpeckerRsc, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
Repository: repo,
|
||||
Tag: tag,
|
||||
Networks: []*dockertest.Network{network},
|
||||
|
@ -295,7 +302,7 @@ func runWoodpecker(
|
|||
log.Fatalf("couldn't run woodpecker: %s", err)
|
||||
}
|
||||
|
||||
if err = woodpecker.Expire(woodpeckerContainerExpInSec); err != nil {
|
||||
if err = woodpeckerRsc.Expire(woodpeckerContainerExpInSec); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -328,7 +335,7 @@ func runWoodpecker(
|
|||
}
|
||||
|
||||
return woodpeckerResource{
|
||||
docker: woodpecker,
|
||||
docker: woodpeckerRsc,
|
||||
httpURL: httpURL,
|
||||
token: newWoodpeckerTokenProvider(oauthApp, giteaUser, giteaPublicURL, httpURL).token(),
|
||||
}
|
||||
|
@ -338,9 +345,10 @@ func (r woodpeckerResource) Close() error {
|
|||
return r.docker.Close()
|
||||
}
|
||||
|
||||
const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v1.0.2"
|
||||
const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v2.4.1"
|
||||
|
||||
func getWoodpeckerRepoTag() (string, string) {
|
||||
//nolint:nonamedreturns
|
||||
func getWoodpeckerRepoTag() (repo string, tag string) {
|
||||
val := os.Getenv("WOODPECKER_IMAGE")
|
||||
if val == "" {
|
||||
val = defaultWoodpeckerImage
|
||||
|
@ -453,7 +461,12 @@ func (p woodpeckerTokenProvider) get(ctx context.Context, url string) *http.Resp
|
|||
return p.do(p.newRequestWithContext(ctx, http.MethodGet, url, nil))
|
||||
}
|
||||
|
||||
func (p woodpeckerTokenProvider) newRequestWithContext(ctx context.Context, method string, url string, body io.Reader) *http.Request {
|
||||
func (p woodpeckerTokenProvider) newRequestWithContext(
|
||||
ctx context.Context,
|
||||
method string,
|
||||
url string,
|
||||
body io.Reader,
|
||||
) *http.Request {
|
||||
req, err := http.NewRequestWithContext(ctx, method, url, body)
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't construct request for url %s: %s", url, err)
|
||||
|
|
|
@ -3,9 +3,9 @@ package internal
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type userModel struct {
|
||||
|
@ -38,7 +38,7 @@ func (m *userModel) toWoodpeckerModel(_ context.Context) (*woodpecker.User, diag
|
|||
}, nil
|
||||
}
|
||||
|
||||
type secretResourceModel struct {
|
||||
type secretResourceModelV0 struct {
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Value types.String `tfsdk:"value"`
|
||||
|
@ -47,7 +47,15 @@ type secretResourceModel struct {
|
|||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
func (m *secretResourceModel) setValues(ctx context.Context, secret *woodpecker.Secret) diag.Diagnostics {
|
||||
type secretResourceModelV1 struct {
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Value types.String `tfsdk:"value"`
|
||||
Images types.Set `tfsdk:"images"`
|
||||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
func (m *secretResourceModelV1) setValues(ctx context.Context, secret *woodpecker.Secret) diag.Diagnostics {
|
||||
var diagsRes diag.Diagnostics
|
||||
var diags diag.Diagnostics
|
||||
|
||||
|
@ -55,21 +63,19 @@ func (m *secretResourceModel) setValues(ctx context.Context, secret *woodpecker.
|
|||
m.Name = types.StringValue(secret.Name)
|
||||
m.Images, diags = types.SetValueFrom(ctx, types.StringType, secret.Images)
|
||||
diagsRes.Append(diags...)
|
||||
m.PluginsOnly = types.BoolValue(secret.PluginsOnly)
|
||||
m.Events, diags = types.SetValueFrom(ctx, types.StringType, secret.Events)
|
||||
diagsRes.Append(diags...)
|
||||
|
||||
return diagsRes
|
||||
}
|
||||
|
||||
func (m *secretResourceModel) toWoodpeckerModel(ctx context.Context) (*woodpecker.Secret, diag.Diagnostics) {
|
||||
func (m *secretResourceModelV1) toWoodpeckerModel(ctx context.Context) (*woodpecker.Secret, diag.Diagnostics) {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
secret := &woodpecker.Secret{
|
||||
ID: m.ID.ValueInt64(),
|
||||
Name: m.Name.ValueString(),
|
||||
Value: m.Value.ValueString(),
|
||||
PluginsOnly: m.PluginsOnly.ValueBool(),
|
||||
ID: m.ID.ValueInt64(),
|
||||
Name: m.Name.ValueString(),
|
||||
Value: m.Value.ValueString(),
|
||||
}
|
||||
diags.Append(m.Images.ElementsAs(ctx, &secret.Images, false)...)
|
||||
diags.Append(m.Events.ElementsAs(ctx, &secret.Events, false)...)
|
||||
|
@ -78,11 +84,10 @@ func (m *secretResourceModel) toWoodpeckerModel(ctx context.Context) (*woodpecke
|
|||
}
|
||||
|
||||
type secretDataSourceModel struct {
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Images types.Set `tfsdk:"images"`
|
||||
PluginsOnly types.Bool `tfsdk:"plugins_only"`
|
||||
Events types.Set `tfsdk:"events"`
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Images types.Set `tfsdk:"images"`
|
||||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
func (m *secretDataSourceModel) setValues(ctx context.Context, secret *woodpecker.Secret) diag.Diagnostics {
|
||||
|
@ -93,7 +98,6 @@ func (m *secretDataSourceModel) setValues(ctx context.Context, secret *woodpecke
|
|||
m.Name = types.StringValue(secret.Name)
|
||||
m.Images, diags = types.SetValueFrom(ctx, types.StringType, secret.Images)
|
||||
diagsRes.Append(diags...)
|
||||
m.PluginsOnly = types.BoolValue(secret.PluginsOnly)
|
||||
m.Events, diags = types.SetValueFrom(ctx, types.StringType, secret.Events)
|
||||
diagsRes.Append(diags...)
|
||||
|
||||
|
@ -128,7 +132,7 @@ func (m *repositoryModel) setValues(_ context.Context, repo *woodpecker.Repo) di
|
|||
m.Name = types.StringValue(repo.Name)
|
||||
m.FullName = types.StringValue(repo.FullName)
|
||||
m.AvatarURL = types.StringValue(repo.Avatar)
|
||||
m.URL = types.StringValue(repo.Link)
|
||||
m.URL = types.StringValue(repo.ForgeURL)
|
||||
m.CloneURL = types.StringValue(repo.Clone)
|
||||
m.DefaultBranch = types.StringValue(repo.DefaultBranch)
|
||||
m.SCMKind = types.StringValue(repo.SCMKind)
|
||||
|
@ -154,7 +158,7 @@ func (m *repositoryModel) toWoodpeckerPatch(_ context.Context) (*woodpecker.Repo
|
|||
}, nil
|
||||
}
|
||||
|
||||
type repositorySecretResourceModel struct {
|
||||
type repositorySecretResourceModelV0 struct {
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
RepositoryID types.Int64 `tfsdk:"repository_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
|
@ -164,7 +168,16 @@ type repositorySecretResourceModel struct {
|
|||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
func (m *repositorySecretResourceModel) setValues(ctx context.Context, secret *woodpecker.Secret) diag.Diagnostics {
|
||||
type repositorySecretResourceModelV1 struct {
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
RepositoryID types.Int64 `tfsdk:"repository_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Value types.String `tfsdk:"value"`
|
||||
Images types.Set `tfsdk:"images"`
|
||||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
func (m *repositorySecretResourceModelV1) setValues(ctx context.Context, secret *woodpecker.Secret) diag.Diagnostics {
|
||||
var diagsRes diag.Diagnostics
|
||||
var diags diag.Diagnostics
|
||||
|
||||
|
@ -172,21 +185,21 @@ func (m *repositorySecretResourceModel) setValues(ctx context.Context, secret *w
|
|||
m.Name = types.StringValue(secret.Name)
|
||||
m.Images, diags = types.SetValueFrom(ctx, types.StringType, secret.Images)
|
||||
diagsRes.Append(diags...)
|
||||
m.PluginsOnly = types.BoolValue(secret.PluginsOnly)
|
||||
m.Events, diags = types.SetValueFrom(ctx, types.StringType, secret.Events)
|
||||
diagsRes.Append(diags...)
|
||||
|
||||
return diagsRes
|
||||
}
|
||||
|
||||
func (m *repositorySecretResourceModel) toWoodpeckerModel(ctx context.Context) (*woodpecker.Secret, diag.Diagnostics) {
|
||||
func (m *repositorySecretResourceModelV1) toWoodpeckerModel(
|
||||
ctx context.Context,
|
||||
) (*woodpecker.Secret, diag.Diagnostics) {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
secret := &woodpecker.Secret{
|
||||
ID: m.ID.ValueInt64(),
|
||||
Name: m.Name.ValueString(),
|
||||
Value: m.Value.ValueString(),
|
||||
PluginsOnly: m.PluginsOnly.ValueBool(),
|
||||
ID: m.ID.ValueInt64(),
|
||||
Name: m.Name.ValueString(),
|
||||
Value: m.Value.ValueString(),
|
||||
}
|
||||
diags.Append(m.Images.ElementsAs(ctx, &secret.Images, false)...)
|
||||
diags.Append(m.Events.ElementsAs(ctx, &secret.Events, false)...)
|
||||
|
@ -199,7 +212,6 @@ type repositorySecretDataSourceModel struct {
|
|||
RepositoryID types.Int64 `tfsdk:"repository_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Images types.Set `tfsdk:"images"`
|
||||
PluginsOnly types.Bool `tfsdk:"plugins_only"`
|
||||
Events types.Set `tfsdk:"events"`
|
||||
}
|
||||
|
||||
|
@ -211,7 +223,6 @@ func (m *repositorySecretDataSourceModel) setValues(ctx context.Context, secret
|
|||
m.Name = types.StringValue(secret.Name)
|
||||
m.Images, diags = types.SetValueFrom(ctx, types.StringType, secret.Images)
|
||||
diagsRes.Append(diags...)
|
||||
m.PluginsOnly = types.BoolValue(secret.PluginsOnly)
|
||||
m.Events, diags = types.SetValueFrom(ctx, types.StringType, secret.Events)
|
||||
diagsRes.Append(diags...)
|
||||
|
||||
|
@ -257,24 +268,23 @@ type repositoryRegistryResourceModel struct {
|
|||
Address types.String `tfsdk:"address"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
Password types.String `tfsdk:"password"`
|
||||
Email types.String `tfsdk:"email"`
|
||||
}
|
||||
|
||||
func (m *repositoryRegistryResourceModel) setValues(_ context.Context, registry *woodpecker.Registry) diag.Diagnostics {
|
||||
m.ID = types.Int64Value(registry.ID)
|
||||
m.Address = types.StringValue(registry.Address)
|
||||
m.Username = types.StringValue(registry.Username)
|
||||
m.Email = types.StringValue(registry.Email)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *repositoryRegistryResourceModel) toWoodpeckerModel(_ context.Context) (*woodpecker.Registry, diag.Diagnostics) {
|
||||
func (m *repositoryRegistryResourceModel) toWoodpeckerModel(
|
||||
_ context.Context,
|
||||
) (*woodpecker.Registry, diag.Diagnostics) {
|
||||
return &woodpecker.Registry{
|
||||
ID: m.ID.ValueInt64(),
|
||||
Address: m.Address.ValueString(),
|
||||
Username: m.Username.ValueString(),
|
||||
Password: m.Password.ValueString(),
|
||||
Email: m.Email.ValueString(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -283,13 +293,14 @@ type repositoryRegistryDataSourceModel struct {
|
|||
RepositoryID types.Int64 `tfsdk:"repository_id"`
|
||||
Address types.String `tfsdk:"address"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
Email types.String `tfsdk:"email"`
|
||||
}
|
||||
|
||||
func (m *repositoryRegistryDataSourceModel) setValues(_ context.Context, registry *woodpecker.Registry) diag.Diagnostics {
|
||||
func (m *repositoryRegistryDataSourceModel) setValues(
|
||||
_ context.Context,
|
||||
registry *woodpecker.Registry,
|
||||
) diag.Diagnostics {
|
||||
m.ID = types.Int64Value(registry.ID)
|
||||
m.Address = types.StringValue(registry.Address)
|
||||
m.Username = types.StringValue(registry.Username)
|
||||
m.Email = types.StringValue(registry.Email)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/provider"
|
||||
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
@ -36,7 +39,10 @@ func (p *woodpeckerProvider) Metadata(_ context.Context, _ provider.MetadataRequ
|
|||
|
||||
func (p *woodpeckerProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "A Terraform provider used to interact with [Woodpecker CI](https://woodpecker-ci.org/) resources.",
|
||||
MarkdownDescription: "A Terraform provider used to interact with" +
|
||||
" [Woodpecker CI](https://woodpecker-ci.org/) resources." +
|
||||
"\n\n\n- v0.2.x and later versions of the provider work with Woodpecker 2.x+" +
|
||||
"\n- v0.1.x version of the provider works with Woodpecker 2.0.0>1.x>=1.0.0",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"server": schema.StringAttribute{
|
||||
Optional: true,
|
||||
|
@ -76,13 +82,20 @@ func (p *woodpeckerProvider) Resources(_ context.Context) []func() resource.Reso
|
|||
}
|
||||
}
|
||||
|
||||
func (p *woodpeckerProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
|
||||
func (p *woodpeckerProvider) Configure(
|
||||
ctx context.Context,
|
||||
req provider.ConfigureRequest,
|
||||
resp *provider.ConfigureResponse,
|
||||
) {
|
||||
cfg := newProviderConfig(ctx, req, resp)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
client := newClient(ctx, cfg, resp)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.DataSourceData = client
|
||||
resp.ResourceData = client
|
||||
|
@ -151,5 +164,49 @@ func newClient(
|
|||
return nil
|
||||
}
|
||||
|
||||
c, err := semver.NewConstraint(">= 2.0.0")
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(
|
||||
"Couldn't parse woodpecker version constraint",
|
||||
fmt.Sprintf(
|
||||
"%s. Please report this issue to the provider developers.",
|
||||
err,
|
||||
),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
ver, err := client.Version()
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Couldn't get woodpecker version", err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
// split is required because in some cases the version looks like this: 2.0.0-f05c1631d2
|
||||
parsedVer, err := semver.NewVersion(strings.Split(ver.Version, "-")[0])
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(
|
||||
"Couldn't parse woodpecker version",
|
||||
fmt.Sprintf(
|
||||
"%s. Please report this issue to the provider developers.",
|
||||
err,
|
||||
),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !c.Check(parsedVer) {
|
||||
resp.Diagnostics.AddError(
|
||||
"Woodpecker version doesn't satisfy the constraint",
|
||||
fmt.Sprintf(
|
||||
"Current woodpecker version: %s, expected: %s."+
|
||||
" Consider using an older version of the provider or update woodpecker.",
|
||||
ver.Version,
|
||||
c.String(),
|
||||
),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"slices"
|
||||
"strconv"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryResource struct {
|
||||
|
@ -31,7 +31,11 @@ func newRepositoryResource() resource.Resource {
|
|||
return &repositoryResource{}
|
||||
}
|
||||
|
||||
func (r *repositoryResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
func (r *repositoryResource) Metadata(
|
||||
_ context.Context,
|
||||
req resource.MetadataRequest,
|
||||
resp *resource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository"
|
||||
}
|
||||
|
||||
|
@ -157,9 +161,10 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
|
|||
},
|
||||
},
|
||||
"allow_pull_requests": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Enables handling webhook's pull request event." +
|
||||
" If disabled, then pipeline won't run for pull requests.",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
|
@ -190,8 +195,10 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
|
|||
"netrc_only_trusted": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " +
|
||||
"see [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers) for more info",
|
||||
MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, see" +
|
||||
//nolint:lll
|
||||
" [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers)" +
|
||||
" for more info",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
|
@ -200,7 +207,11 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
|
|||
}
|
||||
}
|
||||
|
||||
func (r *repositoryResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
func (r *repositoryResource) Configure(
|
||||
_ context.Context,
|
||||
req resource.ConfigureRequest,
|
||||
resp *resource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -210,7 +221,10 @@ func (r *repositoryResource) Configure(_ context.Context, req resource.Configure
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -228,7 +242,7 @@ func (r *repositoryResource) Create(ctx context.Context, req resource.CreateRequ
|
|||
|
||||
repoFullName := data.FullName.ValueString()
|
||||
|
||||
repos, err := r.client.RepoListOpts(true, true)
|
||||
repos, err := r.client.RepoListOpts(true)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Couldn't list repositories", err.Error())
|
||||
return
|
||||
|
@ -342,6 +356,10 @@ func (r *repositoryResource) Delete(ctx context.Context, req resource.DeleteRequ
|
|||
// from provider logic.
|
||||
}
|
||||
|
||||
func (r *repositoryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *repositoryResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("full_name"), req.ID)...)
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryCronResource struct {
|
||||
|
@ -27,7 +27,11 @@ func newRepositoryCronResource() resource.Resource {
|
|||
return &repositoryCronResource{}
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
func (r *repositoryCronResource) Metadata(
|
||||
_ context.Context,
|
||||
req resource.MetadataRequest,
|
||||
resp *resource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_cron"
|
||||
}
|
||||
|
||||
|
@ -86,7 +90,11 @@ func (r *repositoryCronResource) Schema(_ context.Context, _ resource.SchemaRequ
|
|||
}
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
func (r *repositoryCronResource) Configure(
|
||||
_ context.Context,
|
||||
req resource.ConfigureRequest,
|
||||
resp *resource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -96,7 +104,10 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -104,7 +115,11 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi
|
|||
r.client = client
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
func (r *repositoryCronResource) Create(
|
||||
ctx context.Context,
|
||||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) {
|
||||
var data repositoryCronModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
@ -153,7 +168,11 @@ func (r *repositoryCronResource) Read(ctx context.Context, req resource.ReadRequ
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
func (r *repositoryCronResource) Update(
|
||||
ctx context.Context,
|
||||
req resource.UpdateRequest,
|
||||
resp *resource.UpdateResponse,
|
||||
) {
|
||||
var data repositoryCronModel
|
||||
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
|
@ -181,7 +200,11 @@ func (r *repositoryCronResource) Update(ctx context.Context, req resource.Update
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
func (r *repositoryCronResource) Delete(
|
||||
ctx context.Context,
|
||||
req resource.DeleteRequest,
|
||||
resp *resource.DeleteResponse,
|
||||
) {
|
||||
var data repositoryCronModel
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
|
@ -197,7 +220,11 @@ func (r *repositoryCronResource) Delete(ctx context.Context, req resource.Delete
|
|||
resp.State.RemoveResource(ctx)
|
||||
}
|
||||
|
||||
func (r *repositoryCronResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *repositoryCronResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
idParts := strings.Split(req.ID, importStateIDSeparator)
|
||||
|
||||
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestRepositoryCronResource(t *testing.T) {
|
||||
|
@ -42,7 +42,11 @@ resource "woodpecker_repository_cron" "test_cron" {
|
|||
`, repo.ID, name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_cron.test_cron",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""),
|
||||
|
@ -61,7 +65,11 @@ resource "woodpecker_repository_cron" "test_cron" {
|
|||
`, repo.ID, name, branch.Name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_cron.test_cron",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@every 5m"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name),
|
||||
|
@ -79,7 +87,11 @@ resource "woodpecker_repository_cron" "test_cron" {
|
|||
//`, repo.ID, name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_cron.test_cron",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name),
|
||||
|
@ -108,7 +120,11 @@ resource "woodpecker_repository_cron" "test_cron" {
|
|||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(newRepo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_cron.test_cron",
|
||||
"repository_id",
|
||||
strconv.FormatInt(newRepo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""),
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositoryRegistryResource struct {
|
||||
|
@ -27,11 +27,19 @@ func newRepositoryRegistryResource() resource.Resource {
|
|||
return &repositoryRegistryResource{}
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
func (r *repositoryRegistryResource) Metadata(
|
||||
_ context.Context,
|
||||
req resource.MetadataRequest,
|
||||
resp *resource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_registry"
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
func (r *repositoryRegistryResource) Schema(
|
||||
_ context.Context,
|
||||
_ resource.SchemaRequest,
|
||||
resp *resource.SchemaResponse,
|
||||
) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "This resource allows you to add/remove container registries for specific repositories." +
|
||||
" When applied, a new registry will be created." +
|
||||
|
@ -68,19 +76,15 @@ func (r *repositoryRegistryResource) Schema(_ context.Context, _ resource.Schema
|
|||
Description: "password used for authentication",
|
||||
Sensitive: true,
|
||||
},
|
||||
"email": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "email used for authentication",
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
func (r *repositoryRegistryResource) Configure(
|
||||
_ context.Context,
|
||||
req resource.ConfigureRequest,
|
||||
resp *resource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -90,7 +94,10 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -98,7 +105,11 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C
|
|||
r.client = client
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
func (r *repositoryRegistryResource) Create(
|
||||
ctx context.Context,
|
||||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) {
|
||||
var data repositoryRegistryResourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
@ -154,7 +165,11 @@ func (r *repositoryRegistryResource) Read(ctx context.Context, req resource.Read
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
func (r *repositoryRegistryResource) Update(
|
||||
ctx context.Context,
|
||||
req resource.UpdateRequest,
|
||||
resp *resource.UpdateResponse,
|
||||
) {
|
||||
var data repositoryRegistryResourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
|
@ -182,7 +197,11 @@ func (r *repositoryRegistryResource) Update(ctx context.Context, req resource.Up
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
func (r *repositoryRegistryResource) Delete(
|
||||
ctx context.Context,
|
||||
req resource.DeleteRequest,
|
||||
resp *resource.DeleteResponse,
|
||||
) {
|
||||
var data repositoryRegistryResourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
|
@ -198,7 +217,11 @@ func (r *repositoryRegistryResource) Delete(ctx context.Context, req resource.De
|
|||
resp.State.RemoveResource(ctx)
|
||||
}
|
||||
|
||||
func (r *repositoryRegistryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *repositoryRegistryResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
idParts := strings.Split(req.ID, importStateIDSeparator)
|
||||
|
||||
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestRepositoryRegistryResource(t *testing.T) {
|
||||
|
@ -43,7 +43,11 @@ resource "woodpecker_repository_registry" "test_registry" {
|
|||
`, repo.ID, address),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
|
||||
|
@ -56,16 +60,18 @@ resource "woodpecker_repository_registry" "test_registry" {
|
|||
address = "%s"
|
||||
username = "test2"
|
||||
password = "test2"
|
||||
email = "test@localhost"
|
||||
}
|
||||
`, repo.ID, address),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test2"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test2"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "email", "test@localhost"),
|
||||
),
|
||||
},
|
||||
{ // update registry
|
||||
|
@ -79,11 +85,14 @@ resource "woodpecker_repository_registry" "test_registry" {
|
|||
//`, repo.ID, address),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "email", "test@localhost"),
|
||||
),
|
||||
},
|
||||
{ // import
|
||||
|
@ -104,12 +113,19 @@ resource "woodpecker_repository_registry" "test_registry" {
|
|||
`, repo.ID, newAddress),
|
||||
ConfigPlanChecks: resource.ConfigPlanChecks{
|
||||
PreApply: []plancheck.PlanCheck{
|
||||
plancheck.ExpectResourceAction("woodpecker_repository_registry.test_registry", plancheck.ResourceActionReplace),
|
||||
plancheck.ExpectResourceAction(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
plancheck.ResourceActionReplace,
|
||||
),
|
||||
},
|
||||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", newAddress),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
|
||||
|
@ -131,7 +147,11 @@ resource "woodpecker_repository_registry" "test_registry" {
|
|||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(newRepo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_registry.test_registry",
|
||||
"repository_id",
|
||||
strconv.FormatInt(newRepo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", newAddress),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
@ -18,7 +19,6 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type repositorySecretResource struct {
|
||||
|
@ -28,18 +28,24 @@ type repositorySecretResource struct {
|
|||
var _ resource.Resource = (*repositorySecretResource)(nil)
|
||||
var _ resource.ResourceWithConfigure = (*repositorySecretResource)(nil)
|
||||
var _ resource.ResourceWithImportState = (*repositorySecretResource)(nil)
|
||||
var _ resource.ResourceWithUpgradeState = (*repositorySecretResource)(nil)
|
||||
|
||||
func newRepositorySecretResource() resource.Resource {
|
||||
return &repositorySecretResource{}
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
func (r *repositorySecretResource) Metadata(
|
||||
_ context.Context,
|
||||
req resource.MetadataRequest,
|
||||
resp *resource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_repository_secret"
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "This resource allows you to add/remove secrets that are only available to specific repositories." +
|
||||
MarkdownDescription: "This resource allows you to add/remove secrets that" +
|
||||
" are only available to specific repositories." +
|
||||
" When applied, a new secret will be created." +
|
||||
" When destroyed, that secret will be removed." +
|
||||
" For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).",
|
||||
|
@ -76,24 +82,26 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe
|
|||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Required: true,
|
||||
Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)",
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
Validators: []validator.Set{
|
||||
setvalidator.ValueStringsAre(
|
||||
stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"),
|
||||
stringvalidator.OneOfCaseInsensitive(
|
||||
"push",
|
||||
"tag",
|
||||
"pull_request",
|
||||
"pull_request_closed",
|
||||
"deployment",
|
||||
"cron",
|
||||
"manual",
|
||||
"release",
|
||||
),
|
||||
),
|
||||
},
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Optional: true,
|
||||
|
@ -104,10 +112,15 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe
|
|||
},
|
||||
},
|
||||
},
|
||||
Version: 1,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
func (r *repositorySecretResource) Configure(
|
||||
_ context.Context,
|
||||
req resource.ConfigureRequest,
|
||||
resp *resource.ConfigureResponse,
|
||||
) {
|
||||
// Prevent panic if the provider has not been configured.
|
||||
if req.ProviderData == nil {
|
||||
return
|
||||
|
@ -117,7 +130,10 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -125,8 +141,12 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con
|
|||
r.client = client
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var data repositorySecretResourceModel
|
||||
func (r *repositorySecretResource) Create(
|
||||
ctx context.Context,
|
||||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) {
|
||||
var data repositorySecretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -154,7 +174,7 @@ func (r *repositorySecretResource) Create(ctx context.Context, req resource.Crea
|
|||
}
|
||||
|
||||
func (r *repositorySecretResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var data repositorySecretResourceModel
|
||||
var data repositorySecretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -174,8 +194,12 @@ func (r *repositorySecretResource) Read(ctx context.Context, req resource.ReadRe
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var data repositorySecretResourceModel
|
||||
func (r *repositorySecretResource) Update(
|
||||
ctx context.Context,
|
||||
req resource.UpdateRequest,
|
||||
resp *resource.UpdateResponse,
|
||||
) {
|
||||
var data repositorySecretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -202,8 +226,12 @@ func (r *repositorySecretResource) Update(ctx context.Context, req resource.Upda
|
|||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
var data repositorySecretResourceModel
|
||||
func (r *repositorySecretResource) Delete(
|
||||
ctx context.Context,
|
||||
req resource.DeleteRequest,
|
||||
resp *resource.DeleteResponse,
|
||||
) {
|
||||
var data repositorySecretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -218,7 +246,11 @@ func (r *repositorySecretResource) Delete(ctx context.Context, req resource.Dele
|
|||
resp.State.RemoveResource(ctx)
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *repositorySecretResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
idParts := strings.Split(req.ID, importStateIDSeparator)
|
||||
|
||||
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
|
@ -238,3 +270,103 @@ func (r *repositorySecretResource) ImportState(ctx context.Context, req resource
|
|||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("repository_id"), repoID)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), idParts[1])...)
|
||||
}
|
||||
|
||||
func (r *repositorySecretResource) UpgradeState(_ context.Context) map[int64]resource.StateUpgrader {
|
||||
return map[int64]resource.StateUpgrader{
|
||||
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
|
||||
0: {
|
||||
// remove plugins_only attribute
|
||||
PriorSchema: &schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "the secret's id",
|
||||
PlanModifiers: []planmodifier.Int64{
|
||||
int64planmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"repository_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "the ID of the repository",
|
||||
PlanModifiers: []planmodifier.Int64{
|
||||
int64planmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "the name of the secret",
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"value": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "the value of the secret",
|
||||
Sensitive: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Required: true,
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
Validators: []validator.Set{
|
||||
setvalidator.ValueStringsAre(
|
||||
stringvalidator.OneOfCaseInsensitive(
|
||||
"push",
|
||||
"tag",
|
||||
"pull_request",
|
||||
"pull_request_closed",
|
||||
"deployment",
|
||||
"cron",
|
||||
"manual",
|
||||
"release",
|
||||
),
|
||||
),
|
||||
},
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for" +
|
||||
" [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "list of Docker images for which this secret is available, leave blank to allow all images",
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
|
||||
var priorStateData repositorySecretResourceModelV0
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &priorStateData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, repositorySecretResourceModelV1{
|
||||
ID: priorStateData.ID,
|
||||
RepositoryID: priorStateData.RepositoryID,
|
||||
Name: priorStateData.Name,
|
||||
Value: priorStateData.Value,
|
||||
Images: priorStateData.Images,
|
||||
Events: priorStateData.Events,
|
||||
})...)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestRepositorySecretResource(t *testing.T) {
|
||||
|
@ -46,11 +46,14 @@ resource "woodpecker_repository_secret" "test_secret" {
|
|||
`, repo.ID, name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_secret.test_secret",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
{ // update secret
|
||||
|
@ -59,19 +62,23 @@ resource "woodpecker_repository_secret" "test_secret" {
|
|||
repository_id = %d
|
||||
name = "%s"
|
||||
value = "test123123"
|
||||
events = ["push", "deployment"]
|
||||
plugins_only = true
|
||||
events = ["push", "deployment", "release", "pull_request_closed"]
|
||||
images = ["testimage"]
|
||||
}
|
||||
`, repo.ID, name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_secret.test_secret",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "deployment"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "plugins_only", "true"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "release"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "pull_request_closed"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "images.*", "testimage"),
|
||||
),
|
||||
},
|
||||
|
@ -86,13 +93,16 @@ resource "woodpecker_repository_secret" "test_secret" {
|
|||
//`, repo.ID, name),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_secret.test_secret",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "deployment"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "cron"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "plugins_only", "true"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "images.*", "testimage"),
|
||||
),
|
||||
},
|
||||
|
@ -119,11 +129,14 @@ resource "woodpecker_repository_secret" "test_secret" {
|
|||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_secret.test_secret",
|
||||
"repository_id",
|
||||
strconv.FormatInt(repo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", newName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
{ // replace secret (new repo id)
|
||||
|
@ -142,11 +155,14 @@ resource "woodpecker_repository_secret" "test_secret" {
|
|||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(newRepo.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository_secret.test_secret",
|
||||
"repository_id",
|
||||
strconv.FormatInt(newRepo.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", newName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestRepositoryResource(t *testing.T) {
|
||||
|
@ -38,7 +38,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
`, repo1.FullName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"forge_remote_id",
|
||||
strconv.FormatInt(repo1.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName),
|
||||
|
@ -48,7 +52,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"is_private",
|
||||
strconv.FormatBool(repo1.Private),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "true"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
|
||||
|
@ -69,7 +77,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
`, repo1.FullName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"forge_remote_id",
|
||||
strconv.FormatInt(repo1.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName),
|
||||
|
@ -79,7 +91,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "30"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"is_private",
|
||||
strconv.FormatBool(repo1.Private),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
|
||||
|
@ -96,7 +112,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
//`, repo1.FullName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"forge_remote_id",
|
||||
strconv.FormatInt(repo1.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName),
|
||||
|
@ -106,7 +126,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "15"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"is_private",
|
||||
strconv.FormatBool(repo1.Private),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
|
||||
|
@ -133,7 +157,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
},
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo2.ID, 10)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"forge_remote_id",
|
||||
strconv.FormatInt(repo2.ID, 10),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo2.Name),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo2.Owner.UserName),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo2.FullName),
|
||||
|
@ -143,7 +171,11 @@ resource "woodpecker_repository" "test_repo" {
|
|||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
|
||||
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo2.Private)),
|
||||
resource.TestCheckResourceAttr(
|
||||
"woodpecker_repository.test_repo",
|
||||
"is_private",
|
||||
strconv.FormatBool(repo2.Private),
|
||||
),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"),
|
||||
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
|
||||
|
@ -198,7 +230,7 @@ resource "woodpecker_repository" "test_repo" {
|
|||
|
||||
func checkRepositoryResourceDestroy(names ...string) func(state *terraform.State) error {
|
||||
return func(state *terraform.State) error {
|
||||
repos, err := woodpeckerClient.RepoListOpts(true, true)
|
||||
repos, err := woodpeckerClient.RepoListOpts(true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't list repos: %w", err)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type secretResource struct {
|
||||
|
@ -26,6 +26,7 @@ type secretResource struct {
|
|||
var _ resource.Resource = (*secretResource)(nil)
|
||||
var _ resource.ResourceWithConfigure = (*secretResource)(nil)
|
||||
var _ resource.ResourceWithImportState = (*secretResource)(nil)
|
||||
var _ resource.ResourceWithUpgradeState = (*secretResource)(nil)
|
||||
|
||||
func newSecretResource() resource.Resource {
|
||||
return &secretResource{}
|
||||
|
@ -37,7 +38,8 @@ func (r *secretResource) Metadata(_ context.Context, req resource.MetadataReques
|
|||
|
||||
func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "This resource allows you to add/remove global secrets. When applied, a new secret will be created." +
|
||||
MarkdownDescription: "This resource allows you to add/remove global secrets." +
|
||||
" When applied, a new secret will be created." +
|
||||
" When destroyed, that secret will be removed." +
|
||||
" For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
|
@ -66,24 +68,26 @@ func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
|||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Required: true,
|
||||
Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)",
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
Validators: []validator.Set{
|
||||
setvalidator.ValueStringsAre(
|
||||
stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"),
|
||||
stringvalidator.OneOfCaseInsensitive(
|
||||
"push",
|
||||
"tag",
|
||||
"pull_request",
|
||||
"pull_request_closed",
|
||||
"deployment",
|
||||
"cron",
|
||||
"manual",
|
||||
"release",
|
||||
),
|
||||
),
|
||||
},
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Optional: true,
|
||||
|
@ -94,6 +98,7 @@ func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
|||
},
|
||||
},
|
||||
},
|
||||
Version: 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +112,10 @@ func (r *secretResource) Configure(_ context.Context, req resource.ConfigureRequ
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -116,7 +124,7 @@ func (r *secretResource) Configure(_ context.Context, req resource.ConfigureRequ
|
|||
}
|
||||
|
||||
func (r *secretResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
var data secretResourceModel
|
||||
var data secretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -144,7 +152,7 @@ func (r *secretResource) Create(ctx context.Context, req resource.CreateRequest,
|
|||
}
|
||||
|
||||
func (r *secretResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
var data secretResourceModel
|
||||
var data secretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -165,7 +173,7 @@ func (r *secretResource) Read(ctx context.Context, req resource.ReadRequest, res
|
|||
}
|
||||
|
||||
func (r *secretResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
var data secretResourceModel
|
||||
var data secretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -193,7 +201,7 @@ func (r *secretResource) Update(ctx context.Context, req resource.UpdateRequest,
|
|||
}
|
||||
|
||||
func (r *secretResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
var data secretResourceModel
|
||||
var data secretResourceModelV1
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
@ -208,6 +216,102 @@ func (r *secretResource) Delete(ctx context.Context, req resource.DeleteRequest,
|
|||
resp.State.RemoveResource(ctx)
|
||||
}
|
||||
|
||||
func (r *secretResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *secretResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), req.ID)...)
|
||||
}
|
||||
|
||||
func (r *secretResource) UpgradeState(_ context.Context) map[int64]resource.StateUpgrader {
|
||||
return map[int64]resource.StateUpgrader{
|
||||
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
|
||||
0: {
|
||||
// remove plugins_only attribute
|
||||
PriorSchema: &schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "the secret's id",
|
||||
PlanModifiers: []planmodifier.Int64{
|
||||
int64planmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "the name of the secret",
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"value": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "the value of the secret",
|
||||
Sensitive: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"events": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Required: true,
|
||||
Description: "events for which the secret is available " +
|
||||
"(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)",
|
||||
Validators: []validator.Set{
|
||||
setvalidator.ValueStringsAre(
|
||||
stringvalidator.OneOfCaseInsensitive(
|
||||
"push",
|
||||
"tag",
|
||||
"pull_request",
|
||||
"pull_request_closed",
|
||||
"deployment",
|
||||
"cron",
|
||||
"manual",
|
||||
"release",
|
||||
),
|
||||
),
|
||||
},
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"plugins_only": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MarkdownDescription: "whether secret is only available for" +
|
||||
" [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
|
||||
PlanModifiers: []planmodifier.Bool{
|
||||
boolplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"images": schema.SetAttribute{
|
||||
ElementType: types.StringType,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "list of Docker images for which this secret is available, leave blank to allow all images",
|
||||
PlanModifiers: []planmodifier.Set{
|
||||
setplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
|
||||
var priorStateData secretResourceModelV0
|
||||
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &priorStateData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, secretResourceModelV1{
|
||||
ID: priorStateData.ID,
|
||||
Name: priorStateData.Name,
|
||||
Value: priorStateData.Value,
|
||||
Images: priorStateData.Images,
|
||||
Events: priorStateData.Events,
|
||||
})...)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestSecretResource(t *testing.T) {
|
||||
|
@ -41,7 +41,6 @@ resource "woodpecker_secret" "test_secret" {
|
|||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "name", name),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "value", "test123"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
{ // update secret
|
||||
|
@ -50,7 +49,6 @@ resource "woodpecker_secret" "test_secret" {
|
|||
name = "%s"
|
||||
value = "test123123"
|
||||
events = ["push", "deployment"]
|
||||
plugins_only = true
|
||||
images = ["testimage"]
|
||||
}
|
||||
`, name),
|
||||
|
@ -60,7 +58,6 @@ resource "woodpecker_secret" "test_secret" {
|
|||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "value", "test123123"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "deployment"),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "plugins_only", "true"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "images.*", "testimage"),
|
||||
),
|
||||
},
|
||||
|
@ -79,7 +76,6 @@ resource "woodpecker_secret" "test_secret" {
|
|||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "deployment"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "cron"),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "plugins_only", "true"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "images.*", "testimage"),
|
||||
),
|
||||
},
|
||||
|
@ -108,7 +104,6 @@ resource "woodpecker_secret" "test_secret" {
|
|||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "name", newName),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "value", "test123New"),
|
||||
resource.TestCheckTypeSetElemAttr("woodpecker_secret.test_secret", "events.*", "push"),
|
||||
resource.TestCheckResourceAttr("woodpecker_secret.test_secret", "plugins_only", "false"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
|
@ -11,7 +12,6 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
type userResource struct {
|
||||
|
@ -32,10 +32,10 @@ func (r *userResource) Metadata(_ context.Context, req resource.MetadataRequest,
|
|||
|
||||
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: `Provides a user resource.
|
||||
|
||||
|
||||
This resource allows you to add/remove users. When applied, a new user will be created. When destroyed, that user will be removed.`,
|
||||
MarkdownDescription: "Provides a user resource." +
|
||||
"\n\n\nThis resource allows you to add/remove users." +
|
||||
" When applied, a new user will be created." +
|
||||
" When destroyed, that user will be removed.",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
|
@ -96,7 +96,10 @@ func (r *userResource) Configure(_ context.Context, req resource.ConfigureReques
|
|||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
fmt.Sprintf(
|
||||
"Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.",
|
||||
req.ProviderData,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -199,6 +202,10 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
|
|||
// from provider logic.
|
||||
}
|
||||
|
||||
func (r *userResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
func (r *userResource) ImportState(
|
||||
ctx context.Context,
|
||||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("login"), req.ID)...)
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func TestUserResource(t *testing.T) {
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/Kichiyaki/terraform-provider-woodpecker/internal/woodpecker"
|
||||
"github.com/google/uuid"
|
||||
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
||||
)
|
||||
|
||||
func createRepo(tb testing.TB) *gitea.Repository {
|
||||
|
|
667
internal/woodpecker/client.go
Normal file
667
internal/woodpecker/client.go
Normal file
|
@ -0,0 +1,667 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package woodpecker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
pathSelf = "%s/api/user"
|
||||
pathRepos = "%s/api/user/repos"
|
||||
pathRepoPost = "%s/api/repos?forge_remote_id=%d"
|
||||
pathRepo = "%s/api/repos/%d"
|
||||
pathRepoLookup = "%s/api/repos/lookup/%s"
|
||||
pathRepoMove = "%s/api/repos/%d/move?to=%s"
|
||||
pathChown = "%s/api/repos/%d/chown"
|
||||
pathRepair = "%s/api/repos/%d/repair"
|
||||
pathPipelines = "%s/api/repos/%d/pipelines"
|
||||
pathPipeline = "%s/api/repos/%d/pipelines/%v"
|
||||
pathLogs = "%s/api/repos/%d/logs/%d/%d"
|
||||
pathApprove = "%s/api/repos/%d/pipelines/%d/approve"
|
||||
pathDecline = "%s/api/repos/%d/pipelines/%d/decline"
|
||||
pathStop = "%s/api/repos/%d/pipelines/%d/cancel"
|
||||
pathLogPurge = "%s/api/repos/%d/logs/%d"
|
||||
pathRepoSecrets = "%s/api/repos/%d/secrets"
|
||||
pathRepoSecret = "%s/api/repos/%d/secrets/%s"
|
||||
pathRepoRegistries = "%s/api/repos/%d/registry"
|
||||
pathRepoRegistry = "%s/api/repos/%d/registry/%s"
|
||||
pathRepoCrons = "%s/api/repos/%d/cron"
|
||||
pathRepoCron = "%s/api/repos/%d/cron/%d"
|
||||
pathOrg = "%s/api/orgs/%d"
|
||||
pathOrgLookup = "%s/api/orgs/lookup/%s"
|
||||
pathOrgSecrets = "%s/api/orgs/%d/secrets"
|
||||
pathOrgSecret = "%s/api/orgs/%d/secrets/%s"
|
||||
pathGlobalSecrets = "%s/api/secrets"
|
||||
pathGlobalSecret = "%s/api/secrets/%s"
|
||||
pathUsers = "%s/api/users"
|
||||
pathUser = "%s/api/users/%s"
|
||||
pathPipelineQueue = "%s/api/pipelines"
|
||||
pathQueue = "%s/api/queue"
|
||||
pathLogLevel = "%s/api/log-level"
|
||||
pathAgents = "%s/api/agents"
|
||||
pathAgent = "%s/api/agents/%d"
|
||||
pathAgentTasks = "%s/api/agents/%d/tasks"
|
||||
pathVersion = "%s/version"
|
||||
// TODO: implement endpoints
|
||||
// pathFeed = "%s/api/user/feed"
|
||||
)
|
||||
|
||||
type client struct {
|
||||
client *http.Client
|
||||
addr string
|
||||
}
|
||||
|
||||
// New returns a client at the specified url.
|
||||
func New(uri string) Client {
|
||||
return &client{http.DefaultClient, strings.TrimSuffix(uri, "/")}
|
||||
}
|
||||
|
||||
// NewClient returns a client at the specified url.
|
||||
func NewClient(uri string, cli *http.Client) Client {
|
||||
return &client{cli, strings.TrimSuffix(uri, "/")}
|
||||
}
|
||||
|
||||
// SetClient sets the http.Client.
|
||||
func (c *client) SetClient(client *http.Client) {
|
||||
c.client = client
|
||||
}
|
||||
|
||||
// SetAddress sets the server address.
|
||||
func (c *client) SetAddress(addr string) {
|
||||
c.addr = addr
|
||||
}
|
||||
|
||||
// Self returns the currently authenticated user.
|
||||
func (c *client) Self() (*User, error) {
|
||||
out := new(User)
|
||||
uri := fmt.Sprintf(pathSelf, c.addr)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// User returns a user by login.
|
||||
func (c *client) User(login string) (*User, error) {
|
||||
out := new(User)
|
||||
uri := fmt.Sprintf(pathUser, c.addr, login)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// UserList returns a list of all registered users.
|
||||
func (c *client) UserList() ([]*User, error) {
|
||||
var out []*User
|
||||
uri := fmt.Sprintf(pathUsers, c.addr)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// UserPost creates a new user account.
|
||||
func (c *client) UserPost(in *User) (*User, error) {
|
||||
out := new(User)
|
||||
uri := fmt.Sprintf(pathUsers, c.addr)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// UserPatch updates a user account.
|
||||
func (c *client) UserPatch(in *User) (*User, error) {
|
||||
out := new(User)
|
||||
uri := fmt.Sprintf(pathUser, c.addr, in.Login)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// UserDel deletes a user account.
|
||||
func (c *client) UserDel(login string) error {
|
||||
uri := fmt.Sprintf(pathUser, c.addr, login)
|
||||
err := c.delete(uri)
|
||||
return err
|
||||
}
|
||||
|
||||
// Repo returns a repository by id.
|
||||
func (c *client) Repo(repoID int64) (*Repo, error) {
|
||||
out := new(Repo)
|
||||
uri := fmt.Sprintf(pathRepo, c.addr, repoID)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoLookup returns a repository by name.
|
||||
func (c *client) RepoLookup(fullName string) (*Repo, error) {
|
||||
out := new(Repo)
|
||||
uri := fmt.Sprintf(pathRepoLookup, c.addr, fullName)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoList returns a list of all repositories to which
|
||||
// the user has explicit access in the host system.
|
||||
func (c *client) RepoList() ([]*Repo, error) {
|
||||
var out []*Repo
|
||||
uri := fmt.Sprintf(pathRepos, c.addr)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoListOpts returns a list of all repositories to which
|
||||
// the user has explicit access in the host system.
|
||||
func (c *client) RepoListOpts(all bool) ([]*Repo, error) {
|
||||
var out []*Repo
|
||||
uri := fmt.Sprintf(pathRepos+"?all=%v", c.addr, all)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoPost activates a repository.
|
||||
func (c *client) RepoPost(forgeRemoteID int64) (*Repo, error) {
|
||||
out := new(Repo)
|
||||
uri := fmt.Sprintf(pathRepoPost, c.addr, forgeRemoteID)
|
||||
err := c.post(uri, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoChown updates a repository owner.
|
||||
func (c *client) RepoChown(repoID int64) (*Repo, error) {
|
||||
out := new(Repo)
|
||||
uri := fmt.Sprintf(pathChown, c.addr, repoID)
|
||||
err := c.post(uri, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoRepair repairs the repository hooks.
|
||||
func (c *client) RepoRepair(repoID int64) error {
|
||||
uri := fmt.Sprintf(pathRepair, c.addr, repoID)
|
||||
return c.post(uri, nil, nil)
|
||||
}
|
||||
|
||||
// RepoPatch updates a repository.
|
||||
func (c *client) RepoPatch(repoID int64, in *RepoPatch) (*Repo, error) {
|
||||
out := new(Repo)
|
||||
uri := fmt.Sprintf(pathRepo, c.addr, repoID)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RepoDel deletes a repository.
|
||||
func (c *client) RepoDel(repoID int64) error {
|
||||
uri := fmt.Sprintf(pathRepo, c.addr, repoID)
|
||||
err := c.delete(uri)
|
||||
return err
|
||||
}
|
||||
|
||||
// RepoMove moves a repository
|
||||
func (c *client) RepoMove(repoID int64, newFullName string) error {
|
||||
uri := fmt.Sprintf(pathRepoMove, c.addr, repoID, newFullName)
|
||||
return c.post(uri, nil, nil)
|
||||
}
|
||||
|
||||
// Pipeline returns a repository pipeline by pipeline-id.
|
||||
func (c *client) Pipeline(repoID, pipeline int64) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Pipeline returns the latest repository pipeline by branch.
|
||||
func (c *client) PipelineLast(repoID int64, branch string) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
uri := fmt.Sprintf(pathPipeline, c.addr, repoID, "latest")
|
||||
if len(branch) != 0 {
|
||||
uri += "?branch=" + branch
|
||||
}
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineList returns a list of recent pipelines for the
|
||||
// the specified repository.
|
||||
func (c *client) PipelineList(repoID int64) ([]*Pipeline, error) {
|
||||
var out []*Pipeline
|
||||
uri := fmt.Sprintf(pathPipelines, c.addr, repoID)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *client) PipelineCreate(repoID int64, options *PipelineOptions) (*Pipeline, error) {
|
||||
var out *Pipeline
|
||||
uri := fmt.Sprintf(pathPipelines, c.addr, repoID)
|
||||
err := c.post(uri, options, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineQueue returns a list of enqueued pipelines.
|
||||
func (c *client) PipelineQueue() ([]*Feed, error) {
|
||||
var out []*Feed
|
||||
uri := fmt.Sprintf(pathPipelineQueue, c.addr)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineStart re-starts a stopped pipeline.
|
||||
func (c *client) PipelineStart(repoID, pipeline int64, params map[string]string) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
val := mapValues(params)
|
||||
uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline)
|
||||
err := c.post(uri+"?"+val.Encode(), nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineStop cancels the running step.
|
||||
func (c *client) PipelineStop(repoID, pipeline int64) error {
|
||||
uri := fmt.Sprintf(pathStop, c.addr, repoID, pipeline)
|
||||
err := c.post(uri, nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// PipelineApprove approves a blocked pipeline.
|
||||
func (c *client) PipelineApprove(repoID, pipeline int64) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
uri := fmt.Sprintf(pathApprove, c.addr, repoID, pipeline)
|
||||
err := c.post(uri, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineDecline declines a blocked pipeline.
|
||||
func (c *client) PipelineDecline(repoID, pipeline int64) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
uri := fmt.Sprintf(pathDecline, c.addr, repoID, pipeline)
|
||||
err := c.post(uri, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// PipelineKill force kills the running pipeline.
|
||||
func (c *client) PipelineKill(repoID, pipeline int64) error {
|
||||
uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline)
|
||||
err := c.delete(uri)
|
||||
return err
|
||||
}
|
||||
|
||||
// PipelineLogs returns the pipeline logs for the specified step.
|
||||
func (c *client) StepLogEntries(repoID, num, step int64) ([]*LogEntry, error) {
|
||||
uri := fmt.Sprintf(pathLogs, c.addr, repoID, num, step)
|
||||
var out []*LogEntry
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Deploy triggers a deployment for an existing pipeline using the
|
||||
// specified target environment.
|
||||
func (c *client) Deploy(repoID, pipeline int64, env string, params map[string]string) (*Pipeline, error) {
|
||||
out := new(Pipeline)
|
||||
val := mapValues(params)
|
||||
val.Set("event", EventDeploy)
|
||||
val.Set("deploy_to", env)
|
||||
uri := fmt.Sprintf(pathPipeline, c.addr, repoID, pipeline)
|
||||
err := c.post(uri+"?"+val.Encode(), nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// LogsPurge purges the pipeline logs for the specified pipeline.
|
||||
func (c *client) LogsPurge(repoID, pipeline int64) error {
|
||||
uri := fmt.Sprintf(pathLogPurge, c.addr, repoID, pipeline)
|
||||
err := c.delete(uri)
|
||||
return err
|
||||
}
|
||||
|
||||
// Registry returns a registry by hostname.
|
||||
func (c *client) Registry(repoID int64, hostname string) (*Registry, error) {
|
||||
out := new(Registry)
|
||||
uri := fmt.Sprintf(pathRepoRegistry, c.addr, repoID, hostname)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RegistryList returns a list of all repository registries.
|
||||
func (c *client) RegistryList(repoID int64) ([]*Registry, error) {
|
||||
var out []*Registry
|
||||
uri := fmt.Sprintf(pathRepoRegistries, c.addr, repoID)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RegistryCreate creates a registry.
|
||||
func (c *client) RegistryCreate(repoID int64, in *Registry) (*Registry, error) {
|
||||
out := new(Registry)
|
||||
uri := fmt.Sprintf(pathRepoRegistries, c.addr, repoID)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RegistryUpdate updates a registry.
|
||||
func (c *client) RegistryUpdate(repoID int64, in *Registry) (*Registry, error) {
|
||||
out := new(Registry)
|
||||
uri := fmt.Sprintf(pathRepoRegistry, c.addr, repoID, in.Address)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// RegistryDelete deletes a registry.
|
||||
func (c *client) RegistryDelete(repoID int64, hostname string) error {
|
||||
uri := fmt.Sprintf(pathRepoRegistry, c.addr, repoID, hostname)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// Secret returns a secret by name.
|
||||
func (c *client) Secret(repoID int64, secret string) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathRepoSecret, c.addr, repoID, secret)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// SecretList returns a list of all repository secrets.
|
||||
func (c *client) SecretList(repoID int64) ([]*Secret, error) {
|
||||
var out []*Secret
|
||||
uri := fmt.Sprintf(pathRepoSecrets, c.addr, repoID)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// SecretCreate creates a secret.
|
||||
func (c *client) SecretCreate(repoID int64, in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathRepoSecrets, c.addr, repoID)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// SecretUpdate updates a secret.
|
||||
func (c *client) SecretUpdate(repoID int64, in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathRepoSecret, c.addr, repoID, in.Name)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// SecretDelete deletes a secret.
|
||||
func (c *client) SecretDelete(repoID int64, secret string) error {
|
||||
uri := fmt.Sprintf(pathRepoSecret, c.addr, repoID, secret)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// Org returns an organization by id.
|
||||
func (c *client) Org(orgID int64) (*Org, error) {
|
||||
out := new(Org)
|
||||
uri := fmt.Sprintf(pathOrg, c.addr, orgID)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgLookup returns a organsization by its name.
|
||||
func (c *client) OrgLookup(name string) (*Org, error) {
|
||||
out := new(Org)
|
||||
uri := fmt.Sprintf(pathOrgLookup, c.addr, name)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgSecret returns an organization secret by name.
|
||||
func (c *client) OrgSecret(orgID int64, secret string) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathOrgSecret, c.addr, orgID, secret)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgSecretList returns a list of all organization secrets.
|
||||
func (c *client) OrgSecretList(orgID int64) ([]*Secret, error) {
|
||||
var out []*Secret
|
||||
uri := fmt.Sprintf(pathOrgSecrets, c.addr, orgID)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgSecretCreate creates an organization secret.
|
||||
func (c *client) OrgSecretCreate(orgID int64, in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathOrgSecrets, c.addr, orgID)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgSecretUpdate updates an organization secret.
|
||||
func (c *client) OrgSecretUpdate(orgID int64, in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathOrgSecret, c.addr, orgID, in.Name)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// OrgSecretDelete deletes an organization secret.
|
||||
func (c *client) OrgSecretDelete(orgID int64, secret string) error {
|
||||
uri := fmt.Sprintf(pathOrgSecret, c.addr, orgID, secret)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// GlobalOrgSecret returns an global secret by name.
|
||||
func (c *client) GlobalSecret(secret string) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathGlobalSecret, c.addr, secret)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// GlobalSecretList returns a list of all global secrets.
|
||||
func (c *client) GlobalSecretList() ([]*Secret, error) {
|
||||
var out []*Secret
|
||||
uri := fmt.Sprintf(pathGlobalSecrets, c.addr)
|
||||
err := c.get(uri, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// GlobalSecretCreate creates a global secret.
|
||||
func (c *client) GlobalSecretCreate(in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathGlobalSecrets, c.addr)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// GlobalSecretUpdate updates a global secret.
|
||||
func (c *client) GlobalSecretUpdate(in *Secret) (*Secret, error) {
|
||||
out := new(Secret)
|
||||
uri := fmt.Sprintf(pathGlobalSecret, c.addr, in.Name)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// GlobalSecretDelete deletes a global secret.
|
||||
func (c *client) GlobalSecretDelete(secret string) error {
|
||||
uri := fmt.Sprintf(pathGlobalSecret, c.addr, secret)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
// QueueInfo returns queue info
|
||||
func (c *client) QueueInfo() (*Info, error) {
|
||||
out := new(Info)
|
||||
uri := fmt.Sprintf(pathQueue+"/info", c.addr)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// LogLevel returns the current logging level
|
||||
func (c *client) LogLevel() (*LogLevel, error) {
|
||||
out := new(LogLevel)
|
||||
uri := fmt.Sprintf(pathLogLevel, c.addr)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// SetLogLevel sets the logging level of the server
|
||||
func (c *client) SetLogLevel(in *LogLevel) (*LogLevel, error) {
|
||||
out := new(LogLevel)
|
||||
uri := fmt.Sprintf(pathLogLevel, c.addr)
|
||||
err := c.post(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *client) CronList(repoID int64) ([]*Cron, error) {
|
||||
out := make([]*Cron, 0, 5)
|
||||
uri := fmt.Sprintf(pathRepoCrons, c.addr, repoID)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
func (c *client) CronCreate(repoID int64, in *Cron) (*Cron, error) {
|
||||
out := new(Cron)
|
||||
uri := fmt.Sprintf(pathRepoCrons, c.addr, repoID)
|
||||
return out, c.post(uri, in, out)
|
||||
}
|
||||
|
||||
func (c *client) CronUpdate(repoID int64, in *Cron) (*Cron, error) {
|
||||
out := new(Cron)
|
||||
uri := fmt.Sprintf(pathRepoCron, c.addr, repoID, in.ID)
|
||||
err := c.patch(uri, in, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *client) CronDelete(repoID, cronID int64) error {
|
||||
uri := fmt.Sprintf(pathRepoCron, c.addr, repoID, cronID)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
func (c *client) CronGet(repoID, cronID int64) (*Cron, error) {
|
||||
out := new(Cron)
|
||||
uri := fmt.Sprintf(pathRepoCron, c.addr, repoID, cronID)
|
||||
return out, c.get(uri, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentList() ([]*Agent, error) {
|
||||
out := make([]*Agent, 0, 5)
|
||||
uri := fmt.Sprintf(pathAgents, c.addr)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
func (c *client) Agent(agentID int64) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, agentID)
|
||||
return out, c.get(uri, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentCreate(in *Agent) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgents, c.addr)
|
||||
return out, c.post(uri, in, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentUpdate(in *Agent) (*Agent, error) {
|
||||
out := new(Agent)
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, in.ID)
|
||||
return out, c.patch(uri, in, out)
|
||||
}
|
||||
|
||||
func (c *client) AgentDelete(agentID int64) error {
|
||||
uri := fmt.Sprintf(pathAgent, c.addr, agentID)
|
||||
return c.delete(uri)
|
||||
}
|
||||
|
||||
func (c *client) AgentTasksList(agentID int64) ([]*Task, error) {
|
||||
out := make([]*Task, 0, 5)
|
||||
uri := fmt.Sprintf(pathAgentTasks, c.addr, agentID)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
func (c *client) Version() (*Version, error) {
|
||||
out := new(Version)
|
||||
uri := fmt.Sprintf(pathVersion, c.addr)
|
||||
return out, c.get(uri, &out)
|
||||
}
|
||||
|
||||
//
|
||||
// http request helper functions
|
||||
//
|
||||
|
||||
// helper function for making an http GET request.
|
||||
func (c *client) get(rawurl string, out any) error {
|
||||
return c.do(rawurl, http.MethodGet, nil, out)
|
||||
}
|
||||
|
||||
// helper function for making an http POST request.
|
||||
func (c *client) post(rawurl string, in, out any) error {
|
||||
return c.do(rawurl, http.MethodPost, in, out)
|
||||
}
|
||||
|
||||
// helper function for making an http PATCH request.
|
||||
func (c *client) patch(rawurl string, in, out any) error {
|
||||
return c.do(rawurl, http.MethodPatch, in, out)
|
||||
}
|
||||
|
||||
// helper function for making an http DELETE request.
|
||||
func (c *client) delete(rawurl string) error {
|
||||
return c.do(rawurl, http.MethodDelete, nil, nil)
|
||||
}
|
||||
|
||||
// helper function to make an http request
|
||||
func (c *client) do(rawurl, method string, in, out any) error {
|
||||
body, err := c.open(rawurl, method, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer body.Close()
|
||||
if out != nil {
|
||||
return json.NewDecoder(body).Decode(out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper function to open an http request
|
||||
func (c *client) open(rawurl, method string, in any) (io.ReadCloser, error) {
|
||||
uri, err := url.Parse(rawurl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequest(method, uri.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in != nil {
|
||||
decoded, derr := json.Marshal(in)
|
||||
if derr != nil {
|
||||
return nil, derr
|
||||
}
|
||||
buf := bytes.NewBuffer(decoded)
|
||||
req.Body = io.NopCloser(buf)
|
||||
req.ContentLength = int64(len(decoded))
|
||||
req.Header.Set("Content-Length", strconv.Itoa(len(decoded)))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
}
|
||||
resp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode > http.StatusPartialContent {
|
||||
defer resp.Body.Close()
|
||||
out, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("client error %d: %s", resp.StatusCode, string(out))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
// mapValues converts a map to url.Values
|
||||
func mapValues(params map[string]string) url.Values {
|
||||
values := url.Values{}
|
||||
for key, val := range params {
|
||||
values.Add(key, val)
|
||||
}
|
||||
return values
|
||||
}
|
57
internal/woodpecker/const.go
Normal file
57
internal/woodpecker/const.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package woodpecker
|
||||
|
||||
// Event values.
|
||||
const (
|
||||
EventPush = "push"
|
||||
EventPull = "pull_request"
|
||||
EventTag = "tag"
|
||||
EventDeploy = "deployment"
|
||||
)
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusBlocked = "blocked"
|
||||
StatusSkipped = "skipped"
|
||||
StatusPending = "pending"
|
||||
StatusRunning = "running"
|
||||
StatusSuccess = "success"
|
||||
StatusFailure = "failure"
|
||||
StatusKilled = "killed"
|
||||
StatusError = "error"
|
||||
)
|
||||
|
||||
// LogEntryType identifies the type of line in the logs.
|
||||
type LogEntryType int
|
||||
|
||||
const (
|
||||
LogEntryStdout LogEntryType = iota
|
||||
LogEntryStderr
|
||||
LogEntryExitCode
|
||||
LogEntryMetadata
|
||||
LogEntryProgress
|
||||
)
|
||||
|
||||
// StepType identifies the type of step
|
||||
type StepType string
|
||||
|
||||
const (
|
||||
StepTypeClone StepType = "clone"
|
||||
StepTypeService StepType = "service"
|
||||
StepTypePlugin StepType = "plugin"
|
||||
StepTypeCommands StepType = "commands"
|
||||
StepTypeCache StepType = "cache"
|
||||
)
|
231
internal/woodpecker/interface.go
Normal file
231
internal/woodpecker/interface.go
Normal file
|
@ -0,0 +1,231 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package woodpecker
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Client is used to communicate with a Woodpecker server.
|
||||
type Client interface {
|
||||
// SetClient sets the http.Client.
|
||||
SetClient(*http.Client)
|
||||
|
||||
// SetAddress sets the server address.
|
||||
SetAddress(string)
|
||||
|
||||
// Self returns the currently authenticated user.
|
||||
Self() (*User, error)
|
||||
|
||||
// User returns a user by login.
|
||||
User(string) (*User, error)
|
||||
|
||||
// UserList returns a list of all registered users.
|
||||
UserList() ([]*User, error)
|
||||
|
||||
// UserPost creates a new user account.
|
||||
UserPost(*User) (*User, error)
|
||||
|
||||
// UserPatch updates a user account.
|
||||
UserPatch(*User) (*User, error)
|
||||
|
||||
// UserDel deletes a user account.
|
||||
UserDel(string) error
|
||||
|
||||
// Repo returns a repository by name.
|
||||
Repo(repoID int64) (*Repo, error)
|
||||
|
||||
// RepoLookup returns a repository id by the owner and name.
|
||||
RepoLookup(repoFullName string) (*Repo, error)
|
||||
|
||||
// RepoList returns a list of all repositories to which the user has explicit
|
||||
// access in the host system.
|
||||
RepoList() ([]*Repo, error)
|
||||
|
||||
// RepoListOpts returns a list of all repositories to which the user has
|
||||
// explicit access in the host system.
|
||||
RepoListOpts(bool) ([]*Repo, error)
|
||||
|
||||
// RepoPost activates a repository.
|
||||
RepoPost(forgeRemoteID int64) (*Repo, error)
|
||||
|
||||
// RepoPatch updates a repository.
|
||||
RepoPatch(repoID int64, repo *RepoPatch) (*Repo, error)
|
||||
|
||||
// RepoMove moves the repository
|
||||
RepoMove(repoID int64, dst string) error
|
||||
|
||||
// RepoChown updates a repository owner.
|
||||
RepoChown(repoID int64) (*Repo, error)
|
||||
|
||||
// RepoRepair repairs the repository hooks.
|
||||
RepoRepair(repoID int64) error
|
||||
|
||||
// RepoDel deletes a repository.
|
||||
RepoDel(repoID int64) error
|
||||
|
||||
// Pipeline returns a repository pipeline by number.
|
||||
Pipeline(repoID, pipeline int64) (*Pipeline, error)
|
||||
|
||||
// PipelineLast returns the latest repository pipeline by branch. An empty branch
|
||||
// will result in the default branch.
|
||||
PipelineLast(repoID int64, branch string) (*Pipeline, error)
|
||||
|
||||
// PipelineList returns a list of recent pipelines for the
|
||||
// the specified repository.
|
||||
PipelineList(repoID int64) ([]*Pipeline, error)
|
||||
|
||||
// PipelineQueue returns a list of enqueued pipelines.
|
||||
PipelineQueue() ([]*Feed, error)
|
||||
|
||||
// PipelineCreate returns creates a pipeline on specified branch.
|
||||
PipelineCreate(repoID int64, opts *PipelineOptions) (*Pipeline, error)
|
||||
|
||||
// PipelineStart re-starts a stopped pipeline.
|
||||
PipelineStart(repoID, num int64, params map[string]string) (*Pipeline, error)
|
||||
|
||||
// PipelineStop stops the given pipeline.
|
||||
PipelineStop(repoID, pipeline int64) error
|
||||
|
||||
// PipelineApprove approves a blocked pipeline.
|
||||
PipelineApprove(repoID, pipeline int64) (*Pipeline, error)
|
||||
|
||||
// PipelineDecline declines a blocked pipeline.
|
||||
PipelineDecline(repoID, pipeline int64) (*Pipeline, error)
|
||||
|
||||
// PipelineKill force kills the running pipeline.
|
||||
PipelineKill(repoID, pipeline int64) error
|
||||
|
||||
// StepLogEntries returns the LogEntries for the given pipeline step
|
||||
StepLogEntries(repoID, pipeline, stepID int64) ([]*LogEntry, error)
|
||||
|
||||
// Deploy triggers a deployment for an existing pipeline using the specified
|
||||
// target environment.
|
||||
Deploy(repoID, pipeline int64, env string, params map[string]string) (*Pipeline, error)
|
||||
|
||||
// LogsPurge purges the pipeline logs for the specified pipeline.
|
||||
LogsPurge(repoID, pipeline int64) error
|
||||
|
||||
// Registry returns a registry by hostname.
|
||||
Registry(repoID int64, hostname string) (*Registry, error)
|
||||
|
||||
// RegistryList returns a list of all repository registries.
|
||||
RegistryList(repoID int64) ([]*Registry, error)
|
||||
|
||||
// RegistryCreate creates a registry.
|
||||
RegistryCreate(repoID int64, registry *Registry) (*Registry, error)
|
||||
|
||||
// RegistryUpdate updates a registry.
|
||||
RegistryUpdate(repoID int64, registry *Registry) (*Registry, error)
|
||||
|
||||
// RegistryDelete deletes a registry.
|
||||
RegistryDelete(repoID int64, hostname string) error
|
||||
|
||||
// Secret returns a secret by name.
|
||||
Secret(repoID int64, secret string) (*Secret, error)
|
||||
|
||||
// SecretList returns a list of all repository secrets.
|
||||
SecretList(repoID int64) ([]*Secret, error)
|
||||
|
||||
// SecretCreate creates a secret.
|
||||
SecretCreate(repoID int64, secret *Secret) (*Secret, error)
|
||||
|
||||
// SecretUpdate updates a secret.
|
||||
SecretUpdate(repoID int64, secret *Secret) (*Secret, error)
|
||||
|
||||
// SecretDelete deletes a secret.
|
||||
SecretDelete(repoID int64, secret string) error
|
||||
|
||||
// Org returns an organization by name.
|
||||
Org(orgID int64) (*Org, error)
|
||||
|
||||
// OrgLookup returns an organization id by name.
|
||||
OrgLookup(orgName string) (*Org, error)
|
||||
|
||||
// OrgSecret returns an organization secret by name.
|
||||
OrgSecret(orgID int64, secret string) (*Secret, error)
|
||||
|
||||
// OrgSecretList returns a list of all organization secrets.
|
||||
OrgSecretList(orgID int64) ([]*Secret, error)
|
||||
|
||||
// OrgSecretCreate creates an organization secret.
|
||||
OrgSecretCreate(orgID int64, secret *Secret) (*Secret, error)
|
||||
|
||||
// OrgSecretUpdate updates an organization secret.
|
||||
OrgSecretUpdate(orgID int64, secret *Secret) (*Secret, error)
|
||||
|
||||
// OrgSecretDelete deletes an organization secret.
|
||||
OrgSecretDelete(orgID int64, secret string) error
|
||||
|
||||
// GlobalSecret returns an global secret by name.
|
||||
GlobalSecret(secret string) (*Secret, error)
|
||||
|
||||
// GlobalSecretList returns a list of all global secrets.
|
||||
GlobalSecretList() ([]*Secret, error)
|
||||
|
||||
// GlobalSecretCreate creates a global secret.
|
||||
GlobalSecretCreate(secret *Secret) (*Secret, error)
|
||||
|
||||
// GlobalSecretUpdate updates a global secret.
|
||||
GlobalSecretUpdate(secret *Secret) (*Secret, error)
|
||||
|
||||
// GlobalSecretDelete deletes a global secret.
|
||||
GlobalSecretDelete(secret string) error
|
||||
|
||||
// QueueInfo returns the queue state.
|
||||
QueueInfo() (*Info, error)
|
||||
|
||||
// LogLevel returns the current logging level
|
||||
LogLevel() (*LogLevel, error)
|
||||
|
||||
// SetLogLevel sets the server's logging level
|
||||
SetLogLevel(logLevel *LogLevel) (*LogLevel, error)
|
||||
|
||||
// CronList list all cron jobs of a repo
|
||||
CronList(repoID int64) ([]*Cron, error)
|
||||
|
||||
// CronGet get a specific cron job of a repo by id
|
||||
CronGet(repoID, cronID int64) (*Cron, error)
|
||||
|
||||
// CronDelete delete a specific cron job of a repo by id
|
||||
CronDelete(repoID, cronID int64) error
|
||||
|
||||
// CronCreate create a new cron job in a repo
|
||||
CronCreate(repoID int64, cron *Cron) (*Cron, error)
|
||||
|
||||
// CronUpdate update an existing cron job of a repo
|
||||
CronUpdate(repoID int64, cron *Cron) (*Cron, error)
|
||||
|
||||
// AgentList returns a list of all registered agents
|
||||
AgentList() ([]*Agent, error)
|
||||
|
||||
// Agent returns an agent by id
|
||||
Agent(int64) (*Agent, error)
|
||||
|
||||
// AgentCreate creates a new agent
|
||||
AgentCreate(*Agent) (*Agent, error)
|
||||
|
||||
// AgentUpdate updates an existing agent
|
||||
AgentUpdate(*Agent) (*Agent, error)
|
||||
|
||||
// AgentDelete deletes an agent
|
||||
AgentDelete(int64) error
|
||||
|
||||
// AgentTasksList returns a list of all tasks executed by an agent
|
||||
AgentTasksList(int64) ([]*Task, error)
|
||||
|
||||
// Version returns the instance version.
|
||||
Version() (*Version, error)
|
||||
}
|
259
internal/woodpecker/types.go
Normal file
259
internal/woodpecker/types.go
Normal file
|
@ -0,0 +1,259 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package woodpecker
|
||||
|
||||
type (
|
||||
// User represents a user account.
|
||||
User struct {
|
||||
ID int64 `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
Avatar string `json:"avatar_url"`
|
||||
Active bool `json:"active"`
|
||||
Admin bool `json:"admin"`
|
||||
}
|
||||
|
||||
// Repo represents a repository.
|
||||
Repo struct {
|
||||
ID int64 `json:"id,omitempty"`
|
||||
ForgeRemoteID string `json:"forge_remote_id"`
|
||||
Owner string `json:"owner"`
|
||||
Name string `json:"name"`
|
||||
FullName string `json:"full_name"`
|
||||
Avatar string `json:"avatar_url,omitempty"`
|
||||
ForgeURL string `json:"forge_url,omitempty"`
|
||||
Clone string `json:"clone_url,omitempty"`
|
||||
DefaultBranch string `json:"default_branch,omitempty"`
|
||||
SCMKind string `json:"scm,omitempty"`
|
||||
Timeout int64 `json:"timeout,omitempty"`
|
||||
Visibility string `json:"visibility"`
|
||||
IsSCMPrivate bool `json:"private"`
|
||||
IsTrusted bool `json:"trusted"`
|
||||
IsGated bool `json:"gated"`
|
||||
IsActive bool `json:"active"`
|
||||
AllowPullRequests bool `json:"allow_pr"`
|
||||
Config string `json:"config_file"`
|
||||
CancelPreviousPipelineEvents []string `json:"cancel_previous_pipeline_events"`
|
||||
NetrcOnlyTrusted bool `json:"netrc_only_trusted"`
|
||||
}
|
||||
|
||||
// RepoPatch defines a repository patch request.
|
||||
RepoPatch struct {
|
||||
Config *string `json:"config_file,omitempty"`
|
||||
IsTrusted *bool `json:"trusted,omitempty"`
|
||||
IsGated *bool `json:"gated,omitempty"`
|
||||
Timeout *int64 `json:"timeout,omitempty"`
|
||||
Visibility *string `json:"visibility"`
|
||||
AllowPull *bool `json:"allow_pr,omitempty"`
|
||||
PipelineCounter *int `json:"pipeline_counter,omitempty"`
|
||||
}
|
||||
|
||||
PipelineError struct {
|
||||
Type string `json:"type"`
|
||||
Message string `json:"message"`
|
||||
IsWarning bool `json:"is_warning"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
// Pipeline defines a pipeline object.
|
||||
Pipeline struct {
|
||||
ID int64 `json:"id"`
|
||||
Number int64 `json:"number"`
|
||||
Parent int64 `json:"parent"`
|
||||
Event string `json:"event"`
|
||||
Status string `json:"status"`
|
||||
Errors PipelineError `json:"errors"`
|
||||
Enqueued int64 `json:"enqueued_at"`
|
||||
Created int64 `json:"created_at"`
|
||||
Updated int64 `json:"updated_at"`
|
||||
Started int64 `json:"started_at"`
|
||||
Finished int64 `json:"finished_at"`
|
||||
Deploy string `json:"deploy_to"`
|
||||
Commit string `json:"commit"`
|
||||
Branch string `json:"branch"`
|
||||
Ref string `json:"ref"`
|
||||
Refspec string `json:"refspec"`
|
||||
CloneURL string `json:"clone_url"`
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Sender string `json:"sender"`
|
||||
Author string `json:"author"`
|
||||
Avatar string `json:"author_avatar"`
|
||||
Email string `json:"author_email"`
|
||||
ForgeURL string `json:"forge_url"`
|
||||
Reviewer string `json:"reviewed_by"`
|
||||
Reviewed int64 `json:"reviewed_at"`
|
||||
Workflows []*Workflow `json:"workflows,omitempty"`
|
||||
}
|
||||
|
||||
// Workflow represents a workflow in the pipeline.
|
||||
Workflow struct {
|
||||
ID int64 `json:"id"`
|
||||
PID int `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Started int64 `json:"start_time,omitempty"`
|
||||
Stopped int64 `json:"end_time,omitempty"`
|
||||
AgentID int64 `json:"agent_id,omitempty"`
|
||||
Platform string `json:"platform,omitempty"`
|
||||
Environ map[string]string `json:"environ,omitempty"`
|
||||
Children []*Step `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
// Step represents a process in the pipeline.
|
||||
Step struct {
|
||||
ID int64 `json:"id"`
|
||||
PID int `json:"pid"`
|
||||
PPID int `json:"ppid"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Error string `json:"error,omitempty"`
|
||||
ExitCode int `json:"exit_code"`
|
||||
Started int64 `json:"start_time,omitempty"`
|
||||
Stopped int64 `json:"end_time,omitempty"`
|
||||
Type StepType `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// Registry represents a docker registry with credentials.
|
||||
Registry struct {
|
||||
ID int64 `json:"id"`
|
||||
Address string `json:"address"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
// Deprecated
|
||||
Email string `json:"email"` // TODO remove in 3.x
|
||||
// Deprecated
|
||||
Token string `json:"token"` // TODO remove in 3.x
|
||||
}
|
||||
|
||||
// Secret represents a secret variable, such as a password or token.
|
||||
Secret struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Images []string `json:"images"`
|
||||
Events []string `json:"events"`
|
||||
}
|
||||
|
||||
// Feed represents an item in the user's feed or timeline.
|
||||
Feed struct {
|
||||
RepoID int64 `json:"repo_id"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
Number int64 `json:"number,omitempty"`
|
||||
Event string `json:"event,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Created int64 `json:"created_at,omitempty"`
|
||||
Started int64 `json:"started_at,omitempty"`
|
||||
Finished int64 `json:"finished_at,omitempty"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
Branch string `json:"branch,omitempty"`
|
||||
Ref string `json:"ref,omitempty"`
|
||||
Refspec string `json:"refspec,omitempty"`
|
||||
Remote string `json:"remote,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Author string `json:"author,omitempty"`
|
||||
Avatar string `json:"author_avatar,omitempty"`
|
||||
Email string `json:"author_email,omitempty"`
|
||||
}
|
||||
|
||||
// Version provides system version details.
|
||||
Version struct {
|
||||
Source string `json:"source,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
}
|
||||
|
||||
// Info provides queue stats.
|
||||
Info struct {
|
||||
Stats struct {
|
||||
Workers int `json:"worker_count"`
|
||||
Pending int `json:"pending_count"`
|
||||
WaitingOnDeps int `json:"waiting_on_deps_count"`
|
||||
Running int `json:"running_count"`
|
||||
Complete int `json:"completed_count"`
|
||||
} `json:"stats"`
|
||||
Paused bool `json:"paused,omitempty"`
|
||||
}
|
||||
|
||||
// LogLevel is for checking/setting logging level
|
||||
LogLevel struct {
|
||||
Level string `json:"log-level"`
|
||||
}
|
||||
|
||||
// LogEntry is a single log entry
|
||||
LogEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
StepID int64 `json:"step_id"`
|
||||
Time int64 `json:"time"`
|
||||
Line int `json:"line"`
|
||||
Data []byte `json:"data"`
|
||||
Type LogEntryType `json:"type"`
|
||||
}
|
||||
|
||||
// Cron is the JSON data of a cron job
|
||||
Cron struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RepoID int64 `json:"repo_id"`
|
||||
CreatorID int64 `json:"creator_id"`
|
||||
NextExec int64 `json:"next_exec"`
|
||||
Schedule string `json:"schedule"`
|
||||
Created int64 `json:"created_at"`
|
||||
Branch string `json:"branch"`
|
||||
}
|
||||
|
||||
// PipelineOptions is the JSON data for creating a new pipeline
|
||||
PipelineOptions struct {
|
||||
Branch string `json:"branch"`
|
||||
Variables map[string]string `json:"variables"`
|
||||
}
|
||||
|
||||
// Agent is the JSON data for an agent
|
||||
Agent struct {
|
||||
ID int64 `json:"id"`
|
||||
Created int64 `json:"created"`
|
||||
Updated int64 `json:"updated"`
|
||||
Name string `json:"name"`
|
||||
OwnerID int64 `json:"owner_id"`
|
||||
Token string `json:"token"`
|
||||
LastContact int64 `json:"last_contact"`
|
||||
Platform string `json:"platform"`
|
||||
Backend string `json:"backend"`
|
||||
Capacity int32 `json:"capacity"`
|
||||
Version string `json:"version"`
|
||||
NoSchedule bool `json:"no_schedule"`
|
||||
}
|
||||
|
||||
// Task is the JSON data for a task
|
||||
Task struct {
|
||||
ID string `json:"id"`
|
||||
Data []byte `json:"data"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Dependencies []string `json:"dependencies"`
|
||||
RunOn []string `json:"run_on"`
|
||||
DepStatus map[string]string `json:"dep_status"`
|
||||
AgentID int64 `json:"agent_id"`
|
||||
}
|
||||
|
||||
// Org is the JSON data for an organization
|
||||
Org struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsUser bool `json:"is_user"`
|
||||
}
|
||||
)
|
5
internal/woodpecker/woodpecker.go
Normal file
5
internal/woodpecker/woodpecker.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package woodpecker
|
||||
|
||||
// This package has been copied from https://github.com/woodpecker-ci/woodpecker/tree/v2.0.0/woodpecker-go/woodpecker.
|
||||
// At the moment of writing this comment, this package can't be imported because the module name hasn't been updated - https://github.com/woodpecker-ci/woodpecker/blob/v2.0.0/go.mod#L1.
|
||||
// https://go.dev/blog/v2-go-modules#publishing-v2-and-beyond
|
Loading…
Reference in New Issue
Block a user