Skip to content

Commit

Permalink
Rd 339 amplience update amplience go sdk and provider to allow hub up…
Browse files Browse the repository at this point in the history
…date (#34)

* Add resource hub update options

* 🔄 synced local '.github/' with remote 'projects/go-terraform-provider/.github'

* 🔄 synced local '.github/' with remote 'projects/go-terraform-provider/.github'

* 🔄 synced local '.changie.yaml' with remote 'projects/go-terraform-provider/.changie.yaml'

* 🔄 synced local '.github/' with remote 'projects/go-terraform-provider/.github'

* 🔄 synced local '.github/' with remote 'projects/go-terraform-provider/.github'

* feat: add resource hub update options

* feat: fixed goreleaser issues

* feat: updated versions

---------

Co-authored-by: labd-project-manager[bot] <141430439+labd-project-manager[bot]@users.noreply.github.com>
  • Loading branch information
demeyerthom and labd-project-manager[bot] authored Aug 2, 2024
1 parent 0e0d5bf commit 9453fa9
Show file tree
Hide file tree
Showing 26 changed files with 1,489 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240802-123857.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: Added full Hub resource logic
time: 2024-08-02T12:38:57.201504019+02:00
81 changes: 81 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '44 19 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
20 changes: 20 additions & 0 deletions .github/workflows/prepare-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Generate release pull request

on:
push:
branches: [ "main" ]

jobs:
generate-pr:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare release
uses: labd/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
release-workflow: release.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Run Tests

on: [push]
on: [ pull_request ]

jobs:

Expand All @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version-file: "go.mod"

- name: Install dependencies
run: go get ./...
Expand All @@ -40,6 +40,13 @@ jobs:
with:
verbose: true

- name: build binary
uses: goreleaser/goreleaser-action@v3
with:
args: build --snapshot --clean --single-target
env:
GOPATH: ${{ env.GOPATH }}

changie:
runs-on: ubuntu-latest
needs: test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version-file: "go.mod"

- name: Import GPG key
id: import_gpg
Expand Down
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
project_name: terraform-provider-amplience

builds:
Expand Down Expand Up @@ -47,4 +48,4 @@ release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
disable: true
2 changes: 1 addition & 1 deletion amplience/data_source_content_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func dataSourceContentRepositoryRead(ctx context.Context, data *schema.ResourceD
ci := getClient(meta)

repository_id := data.Get("id").(string)
repository, err := ci.client.ContentRepositoryGet(repository_id)
repository, err := ci.Client.ContentRepositoryGet(repository_id)
if err != nil {
return diag.FromErr(err)
}
Expand Down
2 changes: 1 addition & 1 deletion amplience/data_source_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dataSourceHubRead(ctx context.Context, data *schema.ResourceData, meta inte

hub_id := data.Get("id").(string)

hub, err := ci.client.HubGet(hub_id)
hub, err := ci.Client.HubGet(hub_id)
if err != nil {
return diag.FromErr(err)
}
Expand Down
13 changes: 4 additions & 9 deletions amplience/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package amplience
import (
"context"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -74,10 +73,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}

var diags diag.Diagnostics

// FIXME: pass context to amplience sdk client
spew.Dump(clientID)
spew.Dump(clientSecret)

client, err := content.NewClient(&content.ClientConfig{
ClientID: clientID,
ClientSecret: clientSecret,
Expand All @@ -88,10 +83,10 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
return nil, diag.FromErr(err)
}

client_info := &ClientInfo{
client: client,
hubID: d.Get("hub_id").(string),
clientInfo := &ClientInfo{
Client: client,
HubID: d.Get("hub_id").(string),
}

return client_info, diags
return clientInfo, diags
}
8 changes: 4 additions & 4 deletions amplience/resource_content_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func resourceContentRepositoryCreate(ctx context.Context, data *schema.ResourceD
Label: data.Get("label").(string),
}

repository, err := ci.client.ContentRepositoryCreate(ci.hubID, input)
repository, err := ci.Client.ContentRepositoryCreate(ci.HubID, input)

if err != nil {
return diag.FromErr(err)
Expand All @@ -67,7 +67,7 @@ func resourceContentRepositoryRead(ctx context.Context, data *schema.ResourceDat

repository_id := data.Id()

repository, err := ci.client.ContentRepositoryGet(repository_id)
repository, err := ci.Client.ContentRepositoryGet(repository_id)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -84,7 +84,7 @@ func resourceContentRepositoryUpdate(ctx context.Context, data *schema.ResourceD
repository_id := data.Id()

if data.HasChange("label") || data.HasChange("name") {
current, err := ci.client.ContentRepositoryGet(repository_id)
current, err := ci.Client.ContentRepositoryGet(repository_id)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -94,7 +94,7 @@ func resourceContentRepositoryUpdate(ctx context.Context, data *schema.ResourceD
Label: data.Get("label").(string),
}

repository, err := ci.client.ContentRepositoryUpdate(current, input)
repository, err := ci.Client.ContentRepositoryUpdate(current, input)
if err != nil {
return diag.FromErr(err)
}
Expand Down
18 changes: 9 additions & 9 deletions amplience/resource_content_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,28 @@ func resourceContentTypeCreate(ctx context.Context, data *schema.ResourceData, m
ci := getClient(meta)

input := resourceContentTypeCreateInput(data)
instance, err := ci.client.ContentTypeCreate(ci.hubID, input)
instance, err := ci.Client.ContentTypeCreate(ci.HubID, input)

if errResp, ok := err.(*content.ErrorResponse); ok {
if errResp.StatusCode >= 400 {

log.Println("Received 400 conflict response: content type already exists.")
log.Println("Proceeding to unarchive if necessary and update exiting content type.")

instance, err = ci.client.ContentTypeFindByUri(input.ContentTypeURI, ci.hubID)
instance, err = ci.Client.ContentTypeFindByUri(input.ContentTypeURI, ci.HubID)

if err != nil {
return diag.FromErr(err)
}

if instance.Status == string(content.StatusArchived) {
instance, err = ci.client.ContentTypeUnarchive(instance.ID)
instance, err = ci.Client.ContentTypeUnarchive(instance.ID)
}
if err != nil {
return diag.FromErr(err)
}

instance, err = ci.client.ContentTypeUpdate(instance, input)
instance, err = ci.Client.ContentTypeUpdate(instance, input)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -127,7 +127,7 @@ func resourceContentTypeRead(ctx context.Context, data *schema.ResourceData, met
ci := getClient(meta)

content_type_id := data.Id()
content_type, err := ci.client.ContentTypeGet(content_type_id)
content_type, err := ci.Client.ContentTypeGet(content_type_id)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -142,22 +142,22 @@ func resourceContentTypeUpdate(ctx context.Context, data *schema.ResourceData, m

id := data.Id()

instance, err := ci.client.ContentTypeGet(id)
instance, err := ci.Client.ContentTypeGet(id)
if err != nil {
return diag.FromErr(err)
}

if instance.Status == string(content.StatusArchived) {
log.Println("Content type was archived. Proceed to unarchive first before applying update.")

instance, err = ci.client.ContentTypeUnarchive(instance.ID)
instance, err = ci.Client.ContentTypeUnarchive(instance.ID)
if err != nil {
return diag.FromErr(err)
}
}

input := resourceContentTypeCreateInput(data)
content_type, err := ci.client.ContentTypeUpdate(instance, input)
content_type, err := ci.Client.ContentTypeUpdate(instance, input)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -173,7 +173,7 @@ func resourceContentTypeDelete(ctx context.Context, data *schema.ResourceData, m

id := data.Id()

_, err := ci.client.ContentTypeArchive(id)
_, err := ci.Client.ContentTypeArchive(id)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions amplience/resource_content_type_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func resourceContentTypeAssignmentCreate(ctx context.Context, data *schema.Resou
repository_id := data.Get("repository_id").(string)
content_type_id := data.Get("content_type_id").(string)

_, err := ci.client.ContentRepositoryAssignContentType(repository_id, content_type_id)
_, err := ci.Client.ContentRepositoryAssignContentType(repository_id, content_type_id)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -63,7 +63,7 @@ func resourceContentTypeAssignmentDelete(ctx context.Context, data *schema.Resou

repository_id, content_type_id := parseID(data.Id())

_, err := ci.client.ContentRepositoryRemoveContentType(repository_id, content_type_id)
_, err := ci.Client.ContentRepositoryRemoveContentType(repository_id, content_type_id)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Loading

0 comments on commit 9453fa9

Please sign in to comment.