Skip to content

Commit

Permalink
Merge branch 'master' into feature/15_implement_service_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelpoot committed Oct 17, 2023
2 parents c409eea + 3544e27 commit e9b1577
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3

- name: Set up Go 1.18
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21

- name: Vet
run: go vet ./...
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3

- name: Set up Go 1.18
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.21

- name: Vet
run: go vet ./...
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.3.1] - 2023-05-09
### Changed
- Issue # : Build with 1.21
- Issue #27 : Missing contract headers

## [1.3.0] - 2023-05-09
### Changed
- Issue # : Require and changes for keyhub contract version 62 to fix problem with provision groups
### Added
- Issue #24 : Allow creation of GroupOnSystem without provGroups

Expand Down
2 changes: 1 addition & 1 deletion clientapplications.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *ClientApplicationService) Create(client *model.ClientApplication) (resu
errorReport := new(model.ErrorReport)
clients.Items = append(clients.Items, *client)

_, err = s.sling.New().Post("").BodyJSON(clients).Receive(results, errorReport)
_, err = s.sling.New().Post("").BodyProvider(khJsonBodyProvider{payload: clients}).Receive(results, errorReport)
if errorReport.Code > 0 {
err = errorReport.Wrap("Could not create ClientApplication.")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/topicuskeyhub/go-keyhub

go 1.18
go 1.21

require (
github.com/coreos/go-oidc v2.2.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *GroupService) Create(group *model.Group) (result *model.Group, err erro
errorReport := new(model.ErrorReport)
groups.Items = append(groups.Items, *group)

_, err = s.sling.New().Post("").BodyJSON(groups).Receive(results, errorReport)
_, err = s.sling.New().Post("").BodyProvider(khJsonBodyProvider{payload: groups}).Receive(results, errorReport)
if errorReport.Code > 0 {
err = errorReport.Wrap("Could not create Group.")
}
Expand All @@ -62,7 +62,7 @@ func (s *GroupService) CreateMembership(group *model.Group, list *model.GroupAcc

errorReport := new(model.ErrorReport)

_, err = s.sling.New().Post(idString+"/account").BodyJSON(list).Receive(results, errorReport)
_, err = s.sling.New().Post(idString+"/account").BodyProvider(khJsonBodyProvider{payload: list}).Receive(results, errorReport)

if errorReport.Code > 0 {
err = errorReport.Wrap("Could not create memberschip.")
Expand Down
24 changes: 23 additions & 1 deletion keyhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package keyhub

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"time"
Expand All @@ -31,7 +34,7 @@ import (

const (
/* KeyHub contract version supported by this client, set to 0 for latest */
supportedContractVersion = 57
supportedContractVersion = 62

/* KeyHub json mediatype */
mediatype = "application/vnd.topicus.keyhub+json"
Expand All @@ -48,6 +51,25 @@ type Client struct {
ServiceAccounts *ServiceAccountService
}

// khJsonBodyProvider encodes a JSON tagged struct value as a Body for requests.
// See https://golang.org/pkg/encoding/json/#MarshalIndent for details.
type khJsonBodyProvider struct {
payload interface{}
}

func (p khJsonBodyProvider) ContentType() string {
return ""
}

func (p khJsonBodyProvider) Body() (io.Reader, error) {
buf := &bytes.Buffer{}
err := json.NewEncoder(buf).Encode(p.payload)
if err != nil {
return nil, err
}
return buf, nil
}

func NewClientDefault(issuer string, clientID string, clientSecret string) (*Client, error) {
http.DefaultClient.Transport = http.DefaultTransport

Expand Down
36 changes: 4 additions & 32 deletions model/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ package model

import (
"encoding/json"
"fmt"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -255,21 +253,14 @@ func (p GroupAdditionalQueryParams) EncodeValues(key string, v *url.Values) erro
return additionalQueryParamsUrlEncoder(p, key, v)
}

const (
PRGRP_SECURITY_LEVEL_LOW ProvisioningGroupSecurityLevel = "LOW"
PRGRP_SECURITY_LEVEL_MEDIUM ProvisioningGroupSecurityLevel = "MEDIUM"
PRGRP_SECURITY_LEVEL_HIGH ProvisioningGroupSecurityLevel = "HIGH"
)

// Section: Group
func NewProvisioningGroup() *ProvisioningGroup {

pg := ProvisioningGroup{
Linkable: Linkable{
DType: "group.ProvisioningGroup",
},
SecurityLevel: PRGRP_SECURITY_LEVEL_HIGH,
StaticProvisioning: false,
ActivationRequired: true,
}
return &pg
}
Expand All @@ -278,26 +269,7 @@ func NewProvisioningGroup() *ProvisioningGroup {
type ProvisioningGroup struct {
Linkable

GroupOnSystem *GroupOnSystem `json:"groupOnSystem,omitempty"`
Group *Group `json:"group"`
SecurityLevel ProvisioningGroupSecurityLevel `json:"securityLevel"`
StaticProvisioning bool `json:"staticProvisioning"`
GroupOnSystem *GroupOnSystem `json:"groupOnSystem,omitempty"`
Group *Group `json:"group"`
ActivationRequired bool `json:"activationRequired"`
}

func (p *ProvisioningGroup) SetSecurityLevelString(level string) error {

switch strings.ToUpper(level) {
case string(PRGRP_SECURITY_LEVEL_HIGH):
p.SecurityLevel = PRGRP_SECURITY_LEVEL_HIGH
case string(PRGRP_SECURITY_LEVEL_MEDIUM):
p.SecurityLevel = PRGRP_SECURITY_LEVEL_MEDIUM
case string(PRGRP_SECURITY_LEVEL_LOW):
p.SecurityLevel = PRGRP_SECURITY_LEVEL_LOW
default:
return fmt.Errorf("value %s is not a valid level", level)
}
return nil

}

type ProvisioningGroupSecurityLevel string
2 changes: 1 addition & 1 deletion systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *SystemService) CreateGroupOnSystem(groupOnSystem *model.GroupOnSystem)

list.Items = append(list.Items, *groupOnSystem)

_, err = s.sling.New().Post(groupId+"/group").BodyJSON(list).Receive(results, errorReport)
_, err = s.sling.New().Post(groupId+"/group").BodyProvider(khJsonBodyProvider{payload: list}).Receive(results, errorReport)
if errorReport.Code > 0 {
err = errorReport.Wrap("Could not create GroupOnSystem.")
}
Expand Down
4 changes: 2 additions & 2 deletions vaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *VaultService) Create(group *model.Group, vaultRecord *model.VaultRecord
Additional: &model.VaultRecordAdditionalQueryParams{Secret: true},
}

_, err = s.sling.New().Path(selfUrl.Path+"/vault/").Post("record").QueryStruct(params).BodyJSON(vaultRecords).Receive(results, errorReport)
_, err = s.sling.New().Path(selfUrl.Path+"/vault/").Post("record").QueryStruct(params).BodyProvider(khJsonBodyProvider{payload: vaultRecords}).Receive(results, errorReport)
if errorReport.Code > 0 {
err = errorReport.Wrap("Could not create VaultRecord in Group %q.", group.UUID)
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func (s *VaultService) Update(group *model.Group, vaultRecord *model.VaultRecord
vaultRecord.AdditionalObjects.Audit = nil
}

_, err = s.sling.New().Path(selfUrl.Path).Put("").BodyJSON(vaultRecord).QueryStruct(query).Receive(al, errorReport)
_, err = s.sling.New().Path(selfUrl.Path).Put("").BodyProvider(khJsonBodyProvider{payload: vaultRecord}).QueryStruct(query).Receive(al, errorReport)
if errorReport.Code > 0 {
err = errorReport.Wrap("Could not update VaultRecord %q of Group %q.", vaultRecord.UUID, group.UUID)
return
Expand Down

0 comments on commit e9b1577

Please sign in to comment.