Skip to content

Commit

Permalink
Merge pull request #331 from GoogleCloudPlatform/issue330
Browse files Browse the repository at this point in the history
feat: adds basic and publish flags to create #330
  • Loading branch information
srinandan authored Dec 29, 2024
2 parents 21b63f2 + 9be4e57 commit b1db063
Show file tree
Hide file tree
Showing 36 changed files with 866 additions and 34 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ base64 ./test/enc_password.txt > ./test/b64_enc_password.txt # on MacOS, use bas

Please refer to this [article](https://www.googlecloudcommunity.com/gc/Cloud-Product-Articles/CI-CD-for-Application-Integration/ta-p/722811) in Google Cloud Community for how to perform CICD in Application Integration with `integrationcli`

## Samples

Please see [here](./samples/README.md)

## How do I verify the binary?

All artifacts are signed by [cosign](https://github.com/sigstore/cosign). We recommend verifying any artifact before using them.
Expand Down
87 changes: 85 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,99 @@
package main

import (
"internal/cmd/authconfigs"
"internal/cmd/connectors"
"io"
"log"
"os"
"path/filepath"
"strings"

cmd "internal/cmd"

integrations "internal/cmd/integrations"

"github.com/spf13/cobra/doc"

apiclient "internal/apiclient"
)

const ENABLED = "true"

var samples = `# integrationcli command Samples
The following table contains some examples of integrationcli.
Set up integrationcli with preferences: ` + getSingleLine("integrationcli prefs set -p $project -r $region") + `
| Operations | Command |
|---|---|
| integrations | ` + getSingleLine(integrations.GetExample(0)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(1)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(2)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(13)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(3)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(4)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(5)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(6)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(7)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(8)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(9)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(10)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(11)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(12)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(14)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(15)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(16)) + `|
| integrations | ` + getSingleLine(integrations.GetExample(17)) + `|
| authconfigs | ` + getSingleLine(authconfigs.GetExample(0)) + `|
| authconfigs | ` + getSingleLine(authconfigs.GetExample(1)) + `|
| authconfigs | ` + getSingleLine(authconfigs.GetExample(2)) + `|
| authconfigs | ` + getSingleLine(authconfigs.GetExample(3)) + `|
| connectors | ` + getSingleLine(connectors.GetExample(0)) + `|
NOTE: This file is auto-generated during a release. Do not modify.`

func main() {
err := doc.GenMarkdownTree(cmd.RootCmd, "./docs")
var err error
var docFiles []string

if os.Getenv("INTEGRATIONCLI_SKIP_DOCS") != ENABLED {

if docFiles, err = filepath.Glob("./docs/integrationcli*.md"); err != nil {
log.Fatal(err)
}

for _, docFile := range docFiles {
if err = os.Remove(docFile); err != nil {
log.Fatal(err)
}
}

if err = doc.GenMarkdownTree(cmd.RootCmd, "./docs"); err != nil {
log.Fatal(err)
}
}

_ = apiclient.WriteByteArrayToFile("./samples/README.md", false, []byte(samples))
}

func WriteFile() (byteValue []byte, err error) {
userFile, err := os.Open("./samples/README.md")
if err != nil {
log.Fatal(err)
return nil, err
}

defer userFile.Close()

byteValue, err = io.ReadAll(userFile)
if err != nil {
return nil, err
}
return byteValue, err
}

func getSingleLine(s string) string {
return "`" + strings.ReplaceAll(strings.ReplaceAll(s, "\\", ""), "\n", "") + "`"
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/GoogleCloudPlatform/application-integration-management-toolkit

go 1.23.2

require internal/apiclient v1.0.0 // indirect
require internal/apiclient v1.0.0

replace internal/apiclient => ./internal/apiclient

Expand Down Expand Up @@ -80,7 +80,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
Expand Down
19 changes: 17 additions & 2 deletions internal/client/integrations/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ type conditionalFailurePolicy struct {

// CreateVersion
func CreateVersion(name string, content []byte, overridesContent []byte, snapshot string,
userlabel string, grantPermission bool,
userlabel string, grantPermission bool, basicInfo bool,
) (respBody []byte, err error) {
iversion := integrationVersion{}
if err = json.Unmarshal(content, &iversion); err != nil {
Expand Down Expand Up @@ -314,9 +314,24 @@ func CreateVersion(name string, content []byte, overridesContent []byte, snapsho
return nil, err
}

if basicInfo {
apiclient.ClientPrintHttpResponse.Set(false)
}

u, _ := url.Parse(apiclient.GetBaseIntegrationURL())
u.Path = path.Join(u.Path, "integrations", name, "versions")
respBody, err = apiclient.HttpClient(u.String(), string(content))

if basicInfo {
var respBasicBody []byte
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
if respBasicBody, err = getBasicInfo(respBody); err != nil {
return nil, err
}
apiclient.PrettyPrint(respBasicBody)
return respBasicBody, nil
}

return respBody, err
}

Expand Down Expand Up @@ -1219,7 +1234,7 @@ func uploadAsync(name string, filePath string) error {
return err
}

if _, err := CreateVersion(name, content, nil, "", "", false); err != nil {
if _, err := CreateVersion(name, content, nil, "", "", false, false); err != nil {
return err
}

Expand Down
11 changes: 11 additions & 0 deletions internal/cmd/authconfigs/authconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ var Cmd = &cobra.Command{
Long: "Manage integration auth configurations",
}

var examples = []string{
`integrationcli authconfigs create -f samples/ac_username.json`,
`integrationcli authconfigs create -f samples/ac_oidc.json`,
`integrationcli authconfigs create -f samples/ac_authtoken.json`,
`integrationcli authconfigs create -e samples/b64encoded_ac.txt -k locations/$region/keyRings/$key/cryptoKeys/$cryptokey`,
}

func init() {
var project, region string

Expand All @@ -41,3 +48,7 @@ func init() {
Cmd.AddCommand(CreateCmd)
Cmd.AddCommand(PatchCmd)
}

func GetExample(i int) string {
return examples[i]
}
4 changes: 4 additions & 0 deletions internal/cmd/authconfigs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ var CreateCmd = &cobra.Command{
_, err = authconfigs.Create(content)
return err
},
Example: `Create a new user name auth config: ` + GetExample(0) + `
Create a new OIDC auth config: ` + GetExample(1) + `
Create a new auth token auth config: ` + GetExample(2) + `
Create a new auth config from Cloud KMS Encrypted files: ` + GetExample(3),
}

var authConfigFile, encryptedFile, encryptionKey string
Expand Down
38 changes: 38 additions & 0 deletions internal/cmd/connectors/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package connectors

import (
"fmt"

"github.com/spf13/cobra"
)

Expand All @@ -25,6 +27,20 @@ var Cmd = &cobra.Command{
Long: "Manage connections for Integration Connectors",
}

var examples = []string{
`integrationcli connectors create -n $name -g=true -f samples/pub_sub_connection.json -sa=connectors --wait=true --default-token`,
`integrationcli connectors create -n $name -f samples/gcs_connection.json -sa=connectors --wait=true --default-token`,
`integrationcli connectors custom versions create --id $version -n $name -f samples/custom-connection.json --sa=connectors --default-token`,
`integrationcli connectors custom create -n $name -d $dispName --type OPEN_API --default-token`,
}

type ConnectorType string

const (
OPEN_API ConnectorType = "OPEN_API"
PROTO ConnectorType = "PROTO"
)

func init() {
var region, project string

Expand All @@ -48,3 +64,25 @@ func init() {
Cmd.AddCommand(CustomCmd)
Cmd.AddCommand(EventSubCmd)
}

func GetExample(i int) string {
return examples[i]
}

func (c *ConnectorType) String() string {
return string(*c)
}

func (c *ConnectorType) Set(r string) error {
switch r {
case "OPEN_API", "PROTO":
*c = ConnectorType(r)
default:
return fmt.Errorf("must be %s or %s", OPEN_API, PROTO)
}
return nil
}

func (c *ConnectorType) Type() string {
return "ConnectorType"
}
2 changes: 2 additions & 0 deletions internal/cmd/connectors/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ var CreateCmd = &cobra.Command{

return err
},
Example: `Create a PubSub connector and grant the Service Account permissions: ` + GetExample(0) + `
Create a GCS Connector: ` + GetExample(1),
}

var connectionFile, serviceAccountName, serviceAccountProject, encryptionKey string
Expand Down
8 changes: 5 additions & 3 deletions internal/cmd/connectors/crtcustom.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,23 @@ var CrtCustomCmd = &cobra.Command{

return err
},
Example: `Create a custom connector for OPEN_API type: ` + GetExample(3),
}

var labels map[string]string
var connType ConnectorType

func init() {
var name, description, displayName, connType string
var name, description, displayName string

CrtCustomCmd.Flags().StringVarP(&name, "name", "n",
"", "Connection name")
CrtCustomCmd.Flags().StringVarP(&displayName, "display-name", "d",
"", "Custom Connection display name")
CrtCustomCmd.Flags().StringVarP(&description, "description", "",
"", "Custom Connection description")
CrtCustomCmd.Flags().StringVarP(&connType, "type", "",
"", "Custom Connection type")
CrtCustomCmd.Flags().Var(&connType, "type",
"Custom Connection type must be set to OPEN_API or PROTO")
CrtCustomCmd.Flags().StringToStringVarP(&labels, "labels", "l",
map[string]string{}, "Custom Connection labels")

Expand Down
1 change: 1 addition & 0 deletions internal/cmd/connectors/crtcustomver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var CrtCustomVerCmd = &cobra.Command{
_, err = connections.CreateCustomVersion(name, id, content, serviceAccountName, serviceAccountProject)
return err
},
Example: `Create a custom connection version: ` + GetExample(2),
}

func init() {
Expand Down
12 changes: 7 additions & 5 deletions internal/cmd/integrations/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ var ApplyCmd = &cobra.Command{

return err
},
Example: `Apply scaffold configuration and wait for connectors: ` + GetExample(9) + `
Apply scaffold configuration for a specific environment: ` + GetExample(10) + `
Apply scaffold configuration and grant permissions to the service account: ` + GetExample(11) + `
Apply scaffold configuration, but skip connectors: ` + GetExample(12),
}

var serviceAccountName, serviceAccountProject, encryptionKey, pipeline, release, outputGCSPath string
Expand Down Expand Up @@ -582,7 +586,7 @@ func processIntegration(overridesFile string, integrationFolder string,

clilog.Info.Printf("Create integration %s\n", getFilenameWithoutExtension(integrationNames[0]))
respBody, err := integrations.CreateVersion(getFilenameWithoutExtension(integrationNames[0]),
integrationBytes, overridesBytes, "", userLabel, grantPermission)
integrationBytes, overridesBytes, "", userLabel, grantPermission, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -642,8 +646,7 @@ func processCodeFolders(javascriptFolder string, jsonnetFolder string) (codeMap
if err != nil {
return nil, err
}
codeMap["JavaScriptTask"][strings.ReplaceAll(getFilenameWithoutExtension(javascriptName), "javascript_", "")] =
strings.ReplaceAll(string(javascriptBytes), "\n", "\\n")
codeMap["JavaScriptTask"][strings.ReplaceAll(getFilenameWithoutExtension(javascriptName), "javascript_", "")] = strings.ReplaceAll(string(javascriptBytes), "\n", "\\n")
}
}

Expand All @@ -667,8 +670,7 @@ func processCodeFolders(javascriptFolder string, jsonnetFolder string) (codeMap
if err != nil {
return nil, err
}
codeMap["JsonnetMapperTask"][strings.ReplaceAll(getFilenameWithoutExtension(jsonnetName), "datatransformer_", "")] =
strings.ReplaceAll(string(jsonnetBytes), "\n", "\\n")
codeMap["JsonnetMapperTask"][strings.ReplaceAll(getFilenameWithoutExtension(jsonnetName), "datatransformer_", "")] = strings.ReplaceAll(string(jsonnetBytes), "\n", "\\n")
}
}

Expand Down
Loading

0 comments on commit b1db063

Please sign in to comment.