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

add oidc client #161

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions apiv2/pkg/clients/oidc/oidc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package oidc

import (
"context"
"github.com/go-openapi/runtime"
v2client "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client"
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/oidc"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
)

// RESTClient is a subclient for handling oidc related actions.
type RESTClient struct {
// Options contains optional configuration when making API calls.
Options *config.Options

// The new client of the harbor v2 API
V2Client *v2client.Harbor

// AuthInfo contains the auth information that is provided on API calls.
AuthInfo runtime.ClientAuthInfoWriter
}

func NewClient(v2Client *v2client.Harbor, opts *config.Options, authInfo runtime.ClientAuthInfoWriter) *RESTClient {
return &RESTClient{
Options: opts,
V2Client: v2Client,
AuthInfo: authInfo,
}
}

type Client interface {
PingOIDC(ctx context.Context) error
}

func (c *RESTClient) PingOIDC(ctx context.Context, body oidc.PingOIDCBody) error {
params := &oidc.PingOIDCParams{
Endpoint: body,
Context: ctx,
}

_, err := c.V2Client.OIDC.PingOIDC(params, c.AuthInfo)
if err != nil {
return err
}

return nil
}
24 changes: 24 additions & 0 deletions apiv2/pkg/clients/oidc/oidc_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build integration

package oidc

import (
"context"
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/oidc"
clienttesting "github.com/mittwald/goharbor-client/v5/apiv2/pkg/testing"
"github.com/stretchr/testify/require"
"testing"
)

func TestAPIPingOIDC(t *testing.T) {
ctx := context.Background()
c := NewClient(clienttesting.V2SwaggerClient, clienttesting.DefaultOpts, clienttesting.AuthInfo)

body := oidc.PingOIDCBody{
URL: "",
VerifyCert: false,
}

err := c.PingOIDC(ctx, body)
require.NoError(t, err)
}