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

chore: bump server to use API types for step, service, and secret #337

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835
github.com/coreos/go-semver v0.3.1
github.com/gin-gonic/gin v1.10.0
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5
github.com/go-vela/types v0.25.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e h1:3wUbrVnaMvZSbl8zrU5iHzkYh1xU5fo/QQD/ILcOe5g=
github.com/go-vela/server v0.25.1-0.20241011184259-67a8e47f475e/go.mod h1:/DmGHNzsjsBOStLzlGDIDGCmNztUgCdvHiuWmyafFs8=
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5 h1:rj2IBy+Gy16ePQTsQYmpCfBsJyYaQFPiqmDv8EZMXE8=
github.com/go-vela/server v0.25.1-0.20241018183530-cb37db9087c5/go.mod h1:/DmGHNzsjsBOStLzlGDIDGCmNztUgCdvHiuWmyafFs8=
github.com/go-vela/types v0.25.1 h1:DCPHv1+ouqldjfsjfcVTcm/Yyd0OwazIfxYyR+GwpMo=
github.com/go-vela/types v0.25.1/go.mod h1:5+MHUI9ZSY2Uz1cTJa64FWUv8jKzzUUq96UQTokGJzs=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
Expand Down
12 changes: 6 additions & 6 deletions vela/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ func (svc *AdminRepoService) Update(r *api.Repo) (*api.Repo, *Response, error) {
}

// Update modifies a secret with the provided details.
func (svc *AdminSecretService) Update(s *library.Secret) (*library.Secret, *Response, error) {
func (svc *AdminSecretService) Update(s *api.Secret) (*api.Secret, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/secret"

// library Secret type we want to return
v := new(library.Secret)
v := new(api.Secret)

// send request using client
resp, err := svc.client.Call("PUT", u, s, v)
Expand All @@ -204,12 +204,12 @@ func (svc *AdminSecretService) Update(s *library.Secret) (*library.Secret, *Resp
}

// Update modifies a service with the provided details.
func (svc *AdminSvcService) Update(s *library.Service) (*library.Service, *Response, error) {
func (svc *AdminSvcService) Update(s *api.Service) (*api.Service, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/service"

// library Service type we want to return
v := new(library.Service)
v := new(api.Service)

// send request using client
resp, err := svc.client.Call("PUT", u, s, v)
Expand All @@ -218,12 +218,12 @@ func (svc *AdminSvcService) Update(s *library.Service) (*library.Service, *Respo
}

// Update modifies a step with the provided details.
func (svc *AdminStepService) Update(s *library.Step) (*library.Step, *Response, error) {
func (svc *AdminStepService) Update(s *api.Step) (*api.Step, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/admin/step"

// library Step type we want to return
v := new(library.Step)
v := new(api.Step)

// send request using client
resp, err := svc.client.Call("PUT", u, s, v)
Expand Down
14 changes: 7 additions & 7 deletions vela/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ func TestAdmin_Secret_Update_200(t *testing.T) {

data := []byte(server.SecretResp)

var want library.Secret
var want api.Secret
_ = json.Unmarshal(data, &want)

req := library.Secret{
req := api.Secret{
Name: String("foo"),
Value: String("bar"),
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// run test
Expand Down Expand Up @@ -288,10 +288,10 @@ func TestAdmin_Service_Update_200(t *testing.T) {

data := []byte(server.ServiceResp)

var want library.Service
var want api.Service
_ = json.Unmarshal(data, &want)

req := library.Service{
req := api.Service{
Number: Int(1),
Status: String("finished"),
Started: Int64(1563475419),
Expand Down Expand Up @@ -323,10 +323,10 @@ func TestAdmin_Step_Update_200(t *testing.T) {

data := []byte(server.StepResp)

var want library.Step
var want api.Step
_ = json.Unmarshal(data, &want)

req := library.Step{
req := api.Step{
Number: Int(1),
Status: String("finished"),
Started: Int64(1563475419),
Expand Down
30 changes: 0 additions & 30 deletions vela/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/library"
libraryActions "github.com/go-vela/types/library/actions"
)

func TestRepo_Get_200(t *testing.T) {
Expand Down Expand Up @@ -481,31 +479,3 @@ func testEvents() *api.Events {
},
}
}

// TODO: remove this once library.Secret is converted to api.Secret.
func testLibraryEvents() *library.Events {
return &library.Events{
Push: &libraryActions.Push{
Branch: Bool(true),
Tag: Bool(true),
DeleteBranch: Bool(true),
DeleteTag: Bool(true),
},
PullRequest: &libraryActions.Pull{
Opened: Bool(true),
Edited: Bool(true),
Synchronize: Bool(true),
Reopened: Bool(true),
},
Deployment: &libraryActions.Deploy{
Created: Bool(true),
},
Comment: &libraryActions.Comment{
Created: Bool(true),
Edited: Bool(true),
},
Schedule: &libraryActions.Schedule{
Run: Bool(true),
},
}
}
18 changes: 9 additions & 9 deletions vela/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ package vela
import (
"fmt"

"github.com/go-vela/types/library"
api "github.com/go-vela/server/api/types"
)

// SecretService handles retrieving secrets from
// the server methods of the Vela API.
type SecretService service

// Get returns the provided secret.
func (svc *SecretService) Get(engine, sType, org, name, secret string) (*library.Secret, *Response, error) {
func (svc *SecretService) Get(engine, sType, org, name, secret string) (*api.Secret, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/secrets/%s/%s/%s/%s/%s", engine, sType, org, name, secret)

// library Secret type we want to return
v := new(library.Secret)
v := new(api.Secret)

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -27,7 +27,7 @@ func (svc *SecretService) Get(engine, sType, org, name, secret string) (*library
}

// GetAll returns a list of all secrets.
func (svc *SecretService) GetAll(engine, sType, org, name string, opt *ListOptions) (*[]library.Secret, *Response, error) {
func (svc *SecretService) GetAll(engine, sType, org, name string, opt *ListOptions) (*[]api.Secret, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/secrets/%s/%s/%s/%s", engine, sType, org, name)

Expand All @@ -38,7 +38,7 @@ func (svc *SecretService) GetAll(engine, sType, org, name string, opt *ListOptio
}

// slice library Secret type we want to return
v := new([]library.Secret)
v := new([]api.Secret)

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand All @@ -47,12 +47,12 @@ func (svc *SecretService) GetAll(engine, sType, org, name string, opt *ListOptio
}

// Add constructs a secret with the provided details.
func (svc *SecretService) Add(engine, sType, org, name string, s *library.Secret) (*library.Secret, *Response, error) {
func (svc *SecretService) Add(engine, sType, org, name string, s *api.Secret) (*api.Secret, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/secrets/%s/%s/%s/%s", engine, sType, org, name)

// library Secret type we want to return
v := new(library.Secret)
v := new(api.Secret)

// send request using client
resp, err := svc.client.Call("POST", u, s, v)
Expand All @@ -61,12 +61,12 @@ func (svc *SecretService) Add(engine, sType, org, name string, s *library.Secret
}

// Update modifies a secret with the provided details.
func (svc *SecretService) Update(engine, sType, org, name string, s *library.Secret) (*library.Secret, *Response, error) {
func (svc *SecretService) Update(engine, sType, org, name string, s *api.Secret) (*api.Secret, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/secrets/%s/%s/%s/%s/%s", engine, sType, org, name, s.GetName())

// library Secret type we want to return
v := new(library.Secret)
v := new(api.Secret)

// send request using client
resp, err := svc.client.Call("PUT", u, s, v)
Expand Down
39 changes: 20 additions & 19 deletions vela/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"

api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/library"
)

func TestSecret_Get_200(t *testing.T) {
Expand All @@ -25,7 +26,7 @@ func TestSecret_Get_200(t *testing.T) {

data := []byte(server.SecretResp)

var want library.Secret
var want api.Secret
_ = json.Unmarshal(data, &want)

// run test
Expand All @@ -39,8 +40,8 @@ func TestSecret_Get_200(t *testing.T) {
t.Errorf("Secret returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Secret get is %v, want %v", got, want)
if diff := cmp.Diff(&want, got); diff != "" {
t.Errorf("Secret get mismatch (-want +got):\n%s", diff)
}
}

Expand All @@ -51,7 +52,7 @@ func TestSecret_Get_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Secret{}
want := api.Secret{}

// run test
got, resp, err := c.Secret.Get("native", "repo", "github", "not-found", "not-found")
Expand All @@ -78,7 +79,7 @@ func TestSecret_GetAll_200(t *testing.T) {

data := []byte(server.SecretsResp)

var want []library.Secret
var want []api.Secret
_ = json.Unmarshal(data, &want)

// run test
Expand Down Expand Up @@ -106,16 +107,16 @@ func TestSecret_Add_201(t *testing.T) {

data := []byte(server.SecretResp)

var want library.Secret
var want api.Secret
_ = json.Unmarshal(data, &want)

req := library.Secret{
req := api.Secret{
Org: String("github"),
Repo: String("octocat"),
Name: String("foo"),
Value: String("bar"),
Images: &[]string{"foo", "bar"},
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// run test
Expand Down Expand Up @@ -143,13 +144,13 @@ func TestSecret_Update_200(t *testing.T) {

data := []byte(server.SecretResp)

var want library.Secret
var want api.Secret
_ = json.Unmarshal(data, &want)

req := library.Secret{
req := api.Secret{
Name: String("foo"),
Value: String("bar"),
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// run test
Expand All @@ -175,12 +176,12 @@ func TestSecret_Update_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Secret{}
want := api.Secret{}

req := library.Secret{
req := api.Secret{
Name: String("foo"),
Value: String("bar"),
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// run test
Expand Down Expand Up @@ -276,11 +277,11 @@ func ExampleSecretService_Add() {
// Set new token in existing client
c.Authentication.SetPersonalAccessTokenAuth("token")

req := library.Secret{
req := api.Secret{
Name: String("foo"),
Value: String("bar"),
Images: &[]string{"foo", "bar"},
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// Create the secret in the server
Expand All @@ -299,10 +300,10 @@ func ExampleSecretService_Update() {
// Set new token in existing client
c.Authentication.SetPersonalAccessTokenAuth("token")

req := library.Secret{
req := api.Secret{
Name: String("foo"),
Value: String("bar"),
AllowEvents: testLibraryEvents(),
AllowEvents: testEvents(),
}

// Update the secret in the server
Expand Down
Loading
Loading