Skip to content

Commit

Permalink
Merge pull request #9 from ConductorOne/marcos/fix/unmarshal-token
Browse files Browse the repository at this point in the history
fix: Unmarshal response
  • Loading branch information
mgaeta authored Sep 30, 2024
2 parents 758f0f3 + bef70e9 commit a58a9bb
Show file tree
Hide file tree
Showing 60 changed files with 2,833 additions and 1,182 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=3m
Expand All @@ -28,9 +28,9 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
run: (set -o pipefail && go test -v -covermode=count -json ./... | tee test.json)
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=3m
Expand All @@ -31,9 +31,9 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
run: (set -o pipefail && go test -v -covermode=count -json ./... | tee test.json)
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ linters:
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # check for two durations multiplied together
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # Forbids identifiers
- gochecknoinits # Checks that no init functions are present in Go code
- goconst # Finds repeated strings that could be replaced by a constant
Expand Down
27 changes: 12 additions & 15 deletions cmd/baton-jamf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import (
"fmt"
"os"

"github.com/conductorone/baton-jamf/pkg/config"
"github.com/conductorone/baton-jamf/pkg/connector"
"github.com/conductorone/baton-sdk/pkg/config"
configSdk "github.com/conductorone/baton-sdk/pkg/config"
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
"github.com/conductorone/baton-sdk/pkg/field"
"github.com/conductorone/baton-sdk/pkg/types"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/spf13/viper"
"go.uber.org/zap"
)

var version = "dev"
var (
connectorName = "baton-jamf"
version = "dev"
)

func main() {
ctx := context.Background()

_, cmd, err := config.DefineConfiguration(
_, cmd, err := configSdk.DefineConfiguration(
ctx,
"baton-jamf",
connectorName,
getConnector,
Configuration,
config.Configuration,
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand All @@ -42,17 +45,11 @@ func main() {

func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)

err := field.Validate(Configuration, v)
if err != nil {
return nil, err
}

cb, err := connector.New(
ctx,
v.GetString(UsernameField.FieldName),
v.GetString(PasswordField.FieldName),
v.GetString(InstanceUrlField.FieldName),
v.GetString(config.UsernameField.FieldName),
v.GetString(config.PasswordField.FieldName),
v.GetString(config.InstanceUrlField.FieldName),
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.21
toolchain go1.22.6

require (
github.com/conductorone/baton-sdk v0.2.18
github.com/conductorone/baton-sdk v0.2.31
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/spf13/viper v1.18.2
go.uber.org/zap v1.27.0
)

Expand Down Expand Up @@ -67,7 +68,6 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/conductorone/baton-sdk v0.2.18 h1:nnEtw0qKl1s6zbDbQxlq6beA6Az+gwYGSycMG9X7fgg=
github.com/conductorone/baton-sdk v0.2.18/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
github.com/conductorone/baton-sdk v0.2.31 h1:yBFZP0F+1Qu0BoRWUXAB91qMst2SQZ676bDabEGIWZE=
github.com/conductorone/baton-sdk v0.2.31/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion cmd/baton-jamf/config.go → pkg/config/schema.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package config

import (
"github.com/conductorone/baton-sdk/pkg/field"
Expand Down
3 changes: 1 addition & 2 deletions pkg/connector/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/conductorone/baton-jamf/pkg/jamf"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/helpers"
"github.com/conductorone/baton-sdk/pkg/pagination"
rs "github.com/conductorone/baton-sdk/pkg/types/resource"
)
Expand All @@ -23,7 +22,7 @@ func (o *userResourceType) ResourceType(_ context.Context) *v2.ResourceType {

// Create a new connector resource for a Jamf user.
func userResource(user *jamf.User, parentResourceID *v2.ResourceId) (*v2.Resource, error) {
firstName, lastName := helpers.SplitFullName(user.FullName)
firstName, lastName := rs.SplitFullName(user.FullName)
profile := map[string]interface{}{
"first_name": firstName,
"last_name": lastName,
Expand Down
3 changes: 1 addition & 2 deletions pkg/connector/userAccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/conductorone/baton-jamf/pkg/jamf"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/helpers"
"github.com/conductorone/baton-sdk/pkg/pagination"
rs "github.com/conductorone/baton-sdk/pkg/types/resource"
)
Expand All @@ -23,7 +22,7 @@ func (o *userAccountResourceType) ResourceType(_ context.Context) *v2.ResourceTy

// Create a new connector resource for a Jamf user account.
func userAccountResource(account *jamf.UserAccount, parentResourceID *v2.ResourceId) (*v2.Resource, error) {
firstName, lastName := helpers.SplitFullName(account.Name)
firstName, lastName := rs.SplitFullName(account.Name)
profile := map[string]interface{}{
"first_name": firstName,
"last_name": lastName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/jamf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Client) CreateBearerToken(
request.SetBasicAuth(username, password)

var target TokenResponse
response, err := c.wrapper.Do(request, uhttp.WithJSONResponse(target))
response, err := c.wrapper.Do(request, uhttp.WithJSONResponse(&target))
if err != nil {
return "", err
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a58a9bb

Please sign in to comment.