Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rd 339 amplience update amplience go sdk and provider to allow hub update #34

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -54,7 +61,7 @@ jobs:
fetch-depth: 0

- name: Prepare release
uses: labd/changie-release-action@v0.3.1
uses: labd/changie-release-action@v0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
release-workflow: 'release.yaml'
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,13 +42,13 @@
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)
}

data.SetId(repository.ID)
data.Set("label", repository.Label)

Check failure on line 51 in amplience/data_source_content_repository.go

View workflow job for this annotation

GitHub Actions / test

Error return value of `data.Set` is not checked (errcheck)
data.Set("name", repository.Name)

Check failure on line 52 in amplience/data_source_content_repository.go

View workflow job for this annotation

GitHub Actions / test

Error return value of `data.Set` is not checked (errcheck)
return diags
}
2 changes: 1 addition & 1 deletion amplience/data_source_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

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)
}

data.SetId(hub.ID)
data.Set("hub_id", hub.ID)

Check failure on line 43 in amplience/data_source_hub.go

View workflow job for this annotation

GitHub Actions / test

Error return value of `data.Set` is not checked (errcheck)
return diags
}
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 @@
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 {

Check failure on line 92 in amplience/resource_content_type.go

View workflow job for this annotation

GitHub Actions / test

unnecessary leading newline (whitespace)

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 @@
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 @@

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 @@

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 @@
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 @@

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 All @@ -71,7 +71,7 @@
data.SetId("")
return diags

}

Check failure on line 74 in amplience/resource_content_type_assignment.go

View workflow job for this annotation

GitHub Actions / test

unnecessary trailing newline (whitespace)

func resourceContentTypeAssignmentSaveState(data *schema.ResourceData, repository_id string, content_type_id string) {
data.SetId(createID(repository_id, content_type_id))
Expand Down
Loading
Loading