Skip to content

Commit

Permalink
updated models_gen (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-codefresh authored Apr 13, 2022
1 parent 134733c commit 6f07a1b
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.40.0
0.41.0
134 changes: 134 additions & 0 deletions pkg/codefresh/ap_git-sources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package codefresh

import (
"context"
"fmt"

platformModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
appProxyModel "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
)

type (
IAppProxyGitSourcesAPI interface {
Create(ctx context.Context, appName, appSpecifier, destServer, destNamespace string, isInternal bool) error
Delete(ctx context.Context, appName string) error
Edit(ctx context.Context, appName, appSpecifier string) error
}

appProxyGitSources struct {
codefresh *codefresh
}

graphqlGitSourceListResponse struct {
Data struct {
GitSources platformModel.GitSourceSlice
}
Errors []graphqlError
}

graphqlGitSourceCreateResponse struct {
Errors []graphqlError
}

graphqlGitSourceDeleteResponse struct {
Errors []graphqlError
}

graphqlGitSourceEditResponse struct {
Errors []graphqlError
}

)

func newAppProxyGitSourcesAPI(c *codefresh) IAppProxyGitSourcesAPI {
return &appProxyGitSources{codefresh: c}
}

func (c *appProxyGitSources) Create(ctx context.Context, appName, appSpecifier, destServer, destNamespace string, isInternal bool) error {
jsonData := map[string]interface{}{
"query": `
mutation CreateGitSource($args: CreateGitSourceInput!) {
createGitSource(args: $args)
}
`,
"variables": map[string]interface{}{
"args": appProxyModel.CreateGitSourceInput{
AppName: appName,
AppSpecifier: appSpecifier,
DestServer: destServer,
DestNamespace: destNamespace,
IsInternal: &isInternal,
},
},
}

res := &graphqlGitSourceCreateResponse{}
err := c.codefresh.graphqlAPI(ctx, jsonData, res)

if err != nil {
return fmt.Errorf("failed making a graphql API call to create git source: %w", err)
}

if len(res.Errors) > 0 {
return graphqlErrorResponse{errors: res.Errors}
}

return nil
}

func (c *appProxyGitSources) Delete(ctx context.Context, appName string) error {
jsonData := map[string]interface{}{
"query": `
mutation DeleteApplication($args: DeleteApplicationInput!) {
deleteApplication(args: $args)
}
`,
"variables": map[string]interface{}{
"args": appProxyModel.DeleteApplicationInput{
AppName: appName,
},
},
}

res := &graphqlGitSourceDeleteResponse{}
err := c.codefresh.graphqlAPI(ctx, jsonData, res)

if err != nil {
return fmt.Errorf("failed making a graphql API call to delete git source: %w", err)
}

if len(res.Errors) > 0 {
return graphqlErrorResponse{errors: res.Errors}
}

return nil
}

func (c *appProxyGitSources) Edit(ctx context.Context, appName, appSpecifier string) error {
jsonData := map[string]interface{}{
"query": `
mutation EditGitSource($args: EditGitSourceInput!) {
editGitSource(args: $args)
}
`,
"variables": map[string]interface{}{
"args": appProxyModel.EditGitSourceInput{
AppName: appName,
AppSpecifier: appSpecifier,
},
},
}

res := &graphqlGitSourceEditResponse{}
err := c.codefresh.graphqlAPI(ctx, jsonData, res)

if err != nil {
return fmt.Errorf("failed making a graphql API call to edit git source: %w", err)
}

if len(res.Errors) > 0 {
return graphqlErrorResponse{errors: res.Errors}
}

return nil
}
5 changes: 5 additions & 0 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type (
AppProxyClusters() IAppProxyClustersAPI
GitIntegrations() IAppProxyGitIntegrationsAPI
VersionInfo() IAppProxyVersionInfoAPI
AppProxyGitSources() IAppProxyGitSourcesAPI
}
)

Expand Down Expand Up @@ -161,6 +162,10 @@ func (c *codefresh) VersionInfo() IAppProxyVersionInfoAPI {
return newAppProxyVersionInfoAPI(c)
}

func (c *codefresh) AppProxyGitSources() IAppProxyGitSourcesAPI {
return newAppProxyGitSourcesAPI(c)
}

func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
return c.requestAPIWithContext(context.Background(), opt)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/codefresh/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
model "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
)

type (
Expand Down
68 changes: 63 additions & 5 deletions pkg/codefresh/model/app-proxy/models_gen.go

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

Loading

0 comments on commit 6f07a1b

Please sign in to comment.