Skip to content

Commit

Permalink
Refectoring from the Povider Interface. (#4)
Browse files Browse the repository at this point in the history
Define the first "Stable" Version from the base provider configuration, use the original ids for the terraform state, and add import methode for some methodes.
  • Loading branch information
nolte authored May 24, 2020
1 parent 559eec5 commit 35f09a7
Show file tree
Hide file tree
Showing 37 changed files with 937 additions and 467 deletions.
17 changes: 9 additions & 8 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ USER root
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/swagger /usr/local/bin/swagger
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/terraform /usr/local/bin/terraform
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/terraform-doc /usr/local/bin/terraform-doc
COPY --from=docker.pkg.github.com/nolte/vscode-devcontainers/devops:latest /usr/local/bin/shellcheck /usr/local/bin/shellcheck

RUN curl -sSL -k https://github.com/bats-core/bats-core/archive/v${BATS_VERSION}.tar.gz -o /tmp/bats.tgz \
&& tar -zxf /tmp/bats.tgz -C /tmp \
&& /bin/bash /tmp/bats-core-${BATS_VERSION}/install.sh /usr/local
&& tar -zxf /tmp/bats.tgz -C /tmp \
&& /bin/bash /tmp/bats-core-${BATS_VERSION}/install.sh /usr/local

RUN curl -sSL -k https://github.com/bflad/tfproviderdocs/releases/download/v0.6.0/tfproviderdocs_0.6.0_linux_amd64.tar.gz -o /tmp/tfproviderdocs.tgz \
&& tar -zxf /tmp/tfproviderdocs.tgz -C /tmp \
&& mv /tmp/tfproviderdocs /usr/local/bin/
&& tar -zxf /tmp/tfproviderdocs.tgz -C /tmp \
&& mv /tmp/tfproviderdocs /usr/local/bin/


RUN apk add --update-cache \
nodejs npm \
&& rm -rf /var/cache/apk/*
nodejs npm \
&& rm -rf /var/cache/apk/*

RUN mkdir -p /go/src && chown -R ${USER_UID}:${USER_GID} /go/src \
&& mkdir -p /go/pkg && chown -R ${USER_UID}:${USER_GID} /go/pkg
&& mkdir -p /go/pkg && chown -R ${USER_UID}:${USER_GID} /go/pkg

USER ${USERNAME}

Expand All @@ -40,4 +41,4 @@ RUN npm config set prefix "/home/${USERNAME}/.npm-packages"
RUN npm install swagger-merger --user -g

RUN helm repo add harbor https://helm.goharbor.io
RUN npm install swagger-merger -g
RUN npm install swagger-merger -g
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"ms-kubernetes-tools.vscode-kubernetes-tools",
"jetmartin.bats",
"EditorConfig.EditorConfig",
"lonefy.vscode-js-css-html-formatter",
],
"settings": {
// General settings
Expand All @@ -67,4 +68,4 @@
"editor.detectIndentation": false
}
}
}
}
9 changes: 8 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[docs/**.md]
# allow line break https://3os.org/markdownCheatSheet/lineBreaks/#line_break_with_2_spaces
trim_trailing_whitespace = false

[makefile]
indent_style = tabs

[{*.yml,*.yaml, *.tf}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
linters:
enable-all: true
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ fmtcheck:
vet:
go vet ./...

check-scripts:
shellcheck scripts/*.sh
shellcheck scripts/test/bats/build/*.bats

e2e_prepare:
scripts/tst-00-prepare-kind.sh
scripts/tst-01-prepare-harbor.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is original based on the Work from [BESTSELLER/terraform-harbor-provider](h

**Planed Branking Changes:**

- [ ] Rename provier attributes, like url etc.
- [x] [Rename provider](https://github.com/nolte/terraform-provider-harbor/issues/3) attributes, like url etc.
- [x] Planed Git Rebase for remove the Ugly CI/CD Test Commit
- [x] Finazilize the frist version of common ci workflow
- [x] Finazilize the frist version of release workflow
Expand Down
23 changes: 4 additions & 19 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,20 @@ import (
apiclient "github.com/nolte/terraform-provider-harbor/gen/harborctl/client"
)

type Client struct {
url string
username string
password string
insecure bool
Client *apiclient.Harbor
}

// NewClient creates common settings
func NewClient(url string, username string, password string, insecure bool, basepath string) *Client {
func NewClient(host string, username string, password string, insecure bool, basepath string, schema string) *apiclient.Harbor {
basicAuth := httptransport.BasicAuth(username, password)
// create the transport
//proxyTLSClientConfig := &tls.Config{InsecureSkipVerify: true}

if insecure {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
transport := httptransport.New(url, basepath, apiclient.DefaultSchemes)
apiSchemes := []string{schema}
transport := httptransport.New(host, basepath, apiSchemes)

// add default auth
transport.DefaultAuthentication = basicAuth

// create the API client, with the transport
client := apiclient.New(transport, strfmt.Default)
return &Client{
url: url,
username: username,
password: password,
insecure: insecure,
Client: client,
}
return client
}
6 changes: 6 additions & 0 deletions docs/css/table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.wy-nav-content {
background: white;
max-width: 100%;
height: 100vh;
margin: 0;
}
30 changes: 30 additions & 0 deletions docs/data_sources/harbor_label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Data Source: harbor_label

## Example Usage

```hcl
data "harbor_label" "label_1" {
name = "main"
scope = "g"
}
data "harbor_label" "label_2" {
id = 4
}
```

## Argument Reference

- `id` - (Optional, int) ID of the label.
- `name` - (Optional, string) Name of the label.
- `scope` - (Optional, string) Scope of the label.

## Attributes Reference

- `id` - (int) Unique ID of the label.
- `name` - (string) Name of the label.
- `description` - (Optional) The description of the label account will be displayed in harbor.
- `color` - (Optional) The color the label.
- `scope` - (Optional) The scope the label, `p` for project and `g` for global.
- `project_id` - (Optional) The ID of project that the label belongs to.
43 changes: 8 additions & 35 deletions docs/data_sources/harbor_project.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
---
subcategory: "project"
page_title: "Harbor: harbor_project"
description: |-
Get information on a Harbor Project
---

# Data Source: harbor_project

Use this data source to get the ARN of a certificate in AWS Certificate
Manager (ACM), you can reference
it by domain without having to hard code the ARNs as input.

## Example Usage

```hcl
# Find a certificate that is issued
data "aws_acm_certificate" "example" {
domain = "tf.example.com"
statuses = ["ISSUED"]
data "harbor_project" "project_1" {
name = "main"
}
# Find a certificate issued by (not imported into) ACM
data "aws_acm_certificate" "example" {
domain = "tf.example.com"
types = ["AMAZON_ISSUED"]
most_recent = true
data "harbor_project" "project_2" {
id = 4
}
# Find a RSA 4096 bit certificate
data "aws_acm_certificate" "example" {
domain = "tf.example.com"
key_types = ["RSA_4096"]
}
```

## Argument Reference

* `domain` - (Required) The domain of the certificate to look up. If no certificate is found with this name, an error will be returned.
* `key_types` - (Optional) A list of key algorithms to filter certificates. By default, ACM does not return all certificate types when searching. Valid values are `RSA_1024`, `RSA_2048`, `RSA_4096`, `EC_prime256v1`, `EC_secp384r1`, and `EC_secp521r1`.
* `statuses` - (Optional) A list of statuses on which to filter the returned list. Valid values are `PENDING_VALIDATION`, `ISSUED`,
`INACTIVE`, `EXPIRED`, `VALIDATION_TIMED_OUT`, `REVOKED` and `FAILED`. If no value is specified, only certificates in the `ISSUED` state
are returned.
* `types` - (Optional) A list of types on which to filter the returned list. Valid values are `AMAZON_ISSUED` and `IMPORTED`.
* `most_recent` - (Optional) If set to true, it sorts the certificates matched by previous criteria by the NotBefore field, returning only the most recent one. If set to false, it returns an error if more than one certificate is found. Defaults to false.
- `id` - (Optional, int) ID of the project.
- `name` - (Optional, string) Name of the project.

## Attributes Reference

* `arn` - Set to the ARN of the found certificate, suitable for referencing in other resources that support ACM certificates.
* `tags` - A mapping of tags for the resource.

- `id` - (int) Unique ID of the project.
- `name` - (string) Name of the project.
24 changes: 24 additions & 0 deletions docs/data_sources/harbor_registry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Data Source: harbor_registry

## Example Usage

```hcl
data "harbor_registry" "registry_1" {
name = "main"
}
data "harbor_registry" "registry_2" {
id = 4
}
```

## Argument Reference

- `id` - (Optional, string) ID of the registry.
- `name` - (Optional, string) Name of the registry.

## Attributes Reference

- `id` - (int) Unique ID of the registry.
- `name` - (string) Name of the registry.
19 changes: 15 additions & 4 deletions docs/guides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ Please use the ```develop``` branch for new features and fixes.
### Releasing

The [Github Release](https://github.com/nolte/terraform-provider-harbor/releases) Assets will be automatical attatch from the build job see ```.github/workflows/go.yml```.
![Go](https://github.com/nolte/terraform-provider-harbor/workflows/Go/badge.svg?branch=master)

For a Easy Relase process we use the GitHub Commandline Interface [cli.github.com](https://cli.github.com/manual/).

![Go](https://github.com/nolte/terraform-provider-harbor/workflows/Go/badge.svg?branch=master)
For a Easy Relase process we use the GitHub Commandline Interface [cli.github.com](https://cli.github.com/manual/).
Each Release will be start from the ```develop``` branch.

```sh
Expand All @@ -58,6 +56,19 @@ mkdocs serve
```
and open [127.0.0.1:8000](http://127.0.0.1:8000/)

## Development Shortcuts

**build and test in one command**

```sh
make compile \
&& make install \
&& bats scripts/test/bats/build
```

```
terraform import -var harbor_endpoint=${HARBOR_ENDPOINT} -var harbor_base_path='/api' harbor_project.main 24
```

## Links

Expand Down
7 changes: 0 additions & 7 deletions docs/index.css

This file was deleted.

35 changes: 22 additions & 13 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@ app/service documentation.
## Example Usage

```hcl
provider "harbor" {
url = "demo.goharbor.io"
basepath = "/api/v2.0"
# example for harbor v2 api usage
provider "harborv2" {
host = "demo.goharbor.io"
schema = "https"
insecure = true
basepath = "/api/v2"
username = "admin"
password = "Harbor12345"
}
# example for harbor v1 api usage
provider "harborv1" {
host = var.harbor_endpoint
schema = "https"
insecure = true
basepath = var.harbor_base_path
username = "admin"
password = "Harbor12345"
}
Expand All @@ -29,21 +42,17 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf
(e.g. `alias` and `version`), the following arguments are supported in the Harbor
`provider` block:

* `url` - (Required) ddd

* `basepath` - (Optional)

* `basepath` - (Optional)
* `host` - (Required) Hostname from the [Harbor](https://goharbor.io) Service. like _demo.goharbor.io_

* `basepath` - (Optional)
* `username` - (Required) Username for authorize at the harbor.

* `basepath` - (Optional)
* `password` - (Required) Password from given user.

* `basepath` - (Optional)
* `schema` - (Optional) Set Used http Schema, possible values are: ```https,http```. Default: ```https```

* `basepath` - (Optional)
* `insecure` - (Optional) Verify Https Certificates. Default: ```false```

* `basepath` - (Optional)
* `basepath` - (Optional) The Harbor Api basepath, for example use ```/api``` for default HarborV1 and ```/api/v2``` for Harbor V2 Deployments. Default: ```/api```


## Install the Custom Provider
Expand Down
6 changes: 0 additions & 6 deletions docs/js/extra.js

This file was deleted.

5 changes: 5 additions & 0 deletions docs/js/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll("table").forEach(function(table) {
table.classList.add("docutils");
});
});
Loading

0 comments on commit 35f09a7

Please sign in to comment.