Skip to content

Commit

Permalink
Merge pull request #1 from tyclipso/theming-api
Browse files Browse the repository at this point in the history
Add data_sources and resource for theme api of wikijs
  • Loading branch information
MarauderXtreme authored Oct 21, 2024
2 parents 90d5c31 + 4d50fef commit 0fe09f4
Show file tree
Hide file tree
Showing 31 changed files with 1,139 additions and 34 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Terraform Provider Wiki.js

Please use the [Documentation](https://registry.terraform.io/providers/startnext/wikijs/latest/docs) in the [Terraform registry](https://registry.terraform.io/providers/startnext/wikijs/latest)
Please use the [Documentation](https://registry.terraform.io/providers/tyclispo/wikijs/latest/docs) in the [Terraform registry](https://registry.terraform.io/providers/tyclipso/wikijs/latest)

This provider is developed internally at [Startnext GmbH](https://www.startnext.com). The repository on GitHub is only a mirror of our internal development repository.
This provider is a fork from the internal provider of [Startnext GmbH](https://www.startnext.com).
It implements more of the API components of Wiki.js.

## Requirements

Expand All @@ -12,8 +13,8 @@ This provider is developed internally at [Startnext GmbH](https://www.startnext.
## Building The Provider

1. Clone the repository
1. Enter the repository directory
1. Build the provider using the Go `install` command:
2. Enter the repository directory
3. Build the provider using the Go `install` command:

```shell
go install
Expand All @@ -22,16 +23,18 @@ go install
## Using the provider locally

To distribute the provider locally, download the repository and run the following commands. Change `BINARY_ARCH` if you are not on apple silicon.
```
export PROVIDER_VERSION=1.0.0
export BINARY_ARCH=darwin_arm64
CGO_ENABLED=0 go build -o ~/.terraform.d/plugins/terraform.local/local/wikijs/${PROVIDER_VERSION}/${BINARY_ARCH}/terraform-provider-wikijs_v${PROVIDER_VERSION} -ldflags="-X 'main.Version=${PROVIDER_VERSION}'" main.go

```shell
export PROVIDER_VERSION=1.0.0
export BINARY_ARCH=linux_amd64
CGO_ENABLED=0 go build -o "~/.terraform.d/plugins/terraform.local/local/wikijs/${PROVIDER_VERSION}/${BINARY_ARCH}/terraform-provider-wikijs_v${PROVIDER_VERSION}" -ldflags="-X 'main.Version=${PROVIDER_VERSION}'" main.go
```

Make sure to use the correct binary architecture

Add the following to your ~/.terraformrc
```

```terraform
provider_installation {
filesystem_mirror {
path = "/Users/%Me/.terraform.d/plugins"
Expand Down
56 changes: 56 additions & 0 deletions docs/data-sources/theme_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "wikijs_theme_config Data Source - terraform-provider-wikijs"
subcategory: ""
description: |-
The wikijs_theme_config Data Source implements the WikiJS API query theming{config{…}}.
It can be used to read the current state and only change one of the required or any of the optional, without touching the required.
The Schema descriptions are directly lifted from the descriptions of the input fields in WikiJS.
---

# wikijs_theme_config (Data Source)

The `wikijs_theme_config` Data Source implements the WikiJS API query `theming{config{…}}`.
It can be used to read the current state and only change one of the required or any of the optional, without touching the required.
The Schema descriptions are directly lifted from the descriptions of the input fields in WikiJS.

## Example Usage

```terraform
# This data_source can be useful if you want to change only one of the
# required theme configs but don't want to change the rest
# Notice that this data source does not take any arguments
data "wikijs_theme_config" "config" {}
resource "wikijs_theme_config" "config" {
theme = data.wikijs_theme_config.config.theme
iconset = data.wikijs_theme_config.data.iconset
# Only switch dark mode globally on
dark_mode = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `dark_mode` (Boolean) Dark Mode.
Not recommended for accessibility.
May not be supported by all themes.
- `iconset` (String) Set of icons to use for the sidebar navigation.
- `inject_body` (String) HTML code to be injected just before the closing body tag.
- `inject_css` (String) CSS code to inject after system default CSS.
Consider using custom themes if you have a large amount of css code.
Injecting too much CSS code will result in poor page load performance!
CSS will automatically be minified.

**CAUTION**: When adding styles for page content, you must scope them to the `.contents` class.
Omitting this could break the layout of the editor!
- `inject_head` (String) HTML code to be injected just before the closing head tag. Usually for script tags.
- `theme` (String) Themes affect how content pages are displayed.
Other site sections (such as the editor or admin area) are not affected.
- `toc_position` (String) Select whether the table of contents is shown on the left, right or not at all.


53 changes: 53 additions & 0 deletions docs/data-sources/themes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "wikijs_themes Data Source - terraform-provider-wikijs"
subcategory: ""
description: |-
The wikijs_themes Data Source implements the WikiJS API query theming{themes{…}}.
In wikijs v2 https://github.com/requarks/wiki/blob/main/server/graph/resolvers/theming.js#L16-L19 this contains only the default theme.
---

# wikijs_themes (Data Source)

The `wikijs_themes` Data Source implements the WikiJS API query `theming{themes{…}}`.
In wikijs [v2][api-themes] this contains only the default theme.

[api-themes]: https://github.com/requarks/wiki/blob/main/server/graph/resolvers/theming.js#L16-L19

## Example Usage

```terraform
# This data source currently only returns a list with one item
# The themes query is hardcoded to only respond with the default
# theme in v2
data "wikijs_themes" "themes_list" {
themes = []
}
# You could use it to reset the theme but it seems easier to just
# write "default"
resource "wikijs_theme_config" "theme_config" {
theme = data.wikijs_themes.themes_list[0].key
iconset = "mdi"
dark_mode = false
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `themes` (Attributes List) List of registered themes. (see [below for nested schema](#nestedatt--themes))

<a id="nestedatt--themes"></a>
### Nested Schema for `themes`

Read-Only:

- `author` (String)
- `key` (String)
- `title` (String)


84 changes: 84 additions & 0 deletions docs/resources/theme_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "wikijs_theme_config Resource - terraform-provider-wikijs"
subcategory: ""
description: |-
The wikijs_theme_config Resource implements the WikiJS API mutatation theming{setConfig{…}}.
It can be used to manipulate the theme setting on instances with custom themes.
The Schema descriptions are mostly lifted from the descriptions of the input fields in WikiJS.
---

# wikijs_theme_config (Resource)

The `wikijs_theme_config` Resource implements the WikiJS API mutatation `theming{setConfig{…}}`.
It can be used to manipulate the theme setting on instances with custom themes.
The Schema descriptions are mostly lifted from the descriptions of the input fields in WikiJS.

## Example Usage

```terraform
# The following example shows how to configure the wikijs theme
# Since v2 of Wiki.js does not allow for dynamic addition of
# custom themes you need to provide your own string there
resource "wikijs_theme_config" "config" {
theme = "custom_name"
iconset = "mdi"
dark_mode = true
}
# If you want to change the iconset currently the provider only supports
# the builtin names:
# Material Design Icons: "mdi"
# Font Awesome: "fa"
# Font Awesome 4: "fa4"
resource "wikijs_theme_config" "config" {
theme = "default"
iconset = "mdi"
dark_mode = false
}
# The provider has a builtin default theme_config that is set with the
# WikiJS setup. This config will be used for any Delete and a resource
# representation looks like this
resource "wikijs_theme_config" "config" {
theme = "default"
iconset = "mdi"
dark_mode = false
toc_position = "left"
inject_css = ""
inject_head = ""
inject_body = ""
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `dark_mode` (Boolean) Dark Mode.
Not recommended for accessibility.
May not be supported by all themes.
- `iconset` (String) Set of icons to use for the sidebar navigation.
Accepted values: `mdi`, `fa`, `fa4`
- `theme` (String) Themes affect how content pages are displayed.
Other site sections (such as the editor or admin area) are not affected.

### Optional

- `inject_body` (String) HTML code to be injected just before the closing body tag.
- `inject_css` (String) CSS code to inject after system default CSS.
Consider using custom themes if you have a large amount of css code.
Injecting too much CSS code will result in poor page load performance!
CSS will automatically be minified.

**CAUTION**: When adding styles for page content, you must scope them to the `.contents` class.
Omitting this could break the layout of the editor!
- `inject_head` (String) HTML code to be injected just before the closing head tag. Usually for script tags.
- `toc_position` (String) Select whether the table of contents is shown on the left, right or not at all.
Accepted values: `left`, `right`, `off`


12 changes: 12 additions & 0 deletions examples/data-sources/wikijs_theme_config/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This data_source can be useful if you want to change only one of the
# required theme configs but don't want to change the rest

# Notice that this data source does not take any arguments
data "wikijs_theme_config" "config" {}

resource "wikijs_theme_config" "config" {
theme = data.wikijs_theme_config.config.theme
iconset = data.wikijs_theme_config.data.iconset
# Only switch dark mode globally on
dark_mode = true
}
15 changes: 15 additions & 0 deletions examples/data-sources/wikijs_themes/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This data source currently only returns a list with one item
# The themes query is hardcoded to only respond with the default
# theme in v2

data "wikijs_themes" "themes_list" {
themes = []
}

# You could use it to reset the theme but it seems easier to just
# write "default"
resource "wikijs_theme_config" "theme_config" {
theme = data.wikijs_themes.themes_list[0].key
iconset = "mdi"
dark_mode = false
}
35 changes: 35 additions & 0 deletions examples/resources/wikijs_theme_config/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# The following example shows how to configure the wikijs theme
# Since v2 of Wiki.js does not allow for dynamic addition of
# custom themes you need to provide your own string there

resource "wikijs_theme_config" "config" {
theme = "custom_name"
iconset = "mdi"
dark_mode = true
}

# If you want to change the iconset currently the provider only supports
# the builtin names:
# Material Design Icons: "mdi"
# Font Awesome: "fa"
# Font Awesome 4: "fa4"

resource "wikijs_theme_config" "config" {
theme = "default"
iconset = "mdi"
dark_mode = false
}

# The provider has a builtin default theme_config that is set with the
# WikiJS setup. This config will be used for any Delete and a resource
# representation looks like this

resource "wikijs_theme_config" "config" {
theme = "default"
iconset = "mdi"
dark_mode = false
toc_position = "left"
inject_css = ""
inject_head = ""
inject_body = ""
}
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module gitlab.startnext.org/sre/terraform/terraform-provider-wikijs
module github.com/tyclipso/terraform-provider-wikijs

go 1.20
go 1.23

require (
github.com/Khan/genqlient v0.6.0
Expand All @@ -14,6 +14,9 @@ require (
github.com/alexflint/go-scalar v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.8.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Expand Down Expand Up @@ -61,10 +64,6 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/grpc v1.56.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,14 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
Expand All @@ -232,8 +238,12 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
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=
Expand All @@ -252,18 +262,28 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
Expand Down
Loading

0 comments on commit 0fe09f4

Please sign in to comment.