func Create()

in internal/client/connections/connectors.go [255:308]


func Create(name string, content []byte, serviceAccountName string, serviceAccountProject string,
	encryptionKey string, grantPermission bool, createSecret bool, wait bool,
) (respBody []byte, err error) {
	if serviceAccountName != "" && strings.Contains(serviceAccountName, ".iam.gserviceaccount.com") {
		serviceAccountName = strings.Split(serviceAccountName, "@")[0]
	}

	operationsBytes, err := create(name, content, serviceAccountName,
		serviceAccountProject, encryptionKey, grantPermission, createSecret)
	if err != nil {
		return nil, err
	}

	if wait {
		apiclient.ClientPrintHttpResponse.Set(false)
		defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())

		o := operation{}
		if err = json.Unmarshal(operationsBytes, &o); err != nil {
			return nil, err
		}

		operationId := filepath.Base(o.Name)
		clilog.Info.Printf("Checking connection status for %s in %d seconds\n", operationId, interval)

		stop := apiclient.Every(interval*time.Second, func(time.Time) bool {
			var respBody []byte

			if respBody, err = GetOperation(operationId); err != nil {
				return false
			}

			if err = json.Unmarshal(respBody, &o); err != nil {
				return false
			}

			if o.Done {
				if o.Error != nil {
					clilog.Error.Printf("Connection completed with error: %s\n", o.Error.Message)
				} else {
					clilog.Info.Println("Connection completed successfully!")
				}
				return false
			} else {
				clilog.Info.Printf("Connection status is: %t. Waiting %d seconds.\n", o.Done, interval)
				return true
			}
		})

		<-stop
	}

	return respBody, err
}