Skip to content

Commit

Permalink
Sdk update 20240123 124000 (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Peterson <[email protected]>
Co-authored-by: whitesource-ets[bot] <328400+whitesource-ets[bot]@users.noreply.github.ibm.com>
Co-authored-by: Michael Magrian <[email protected]>
Co-authored-by: Enrico Regge <[email protected]>
Co-authored-by: John Sartore <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: whitesource-ets[bot] <409986+whitesource-ets[bot]@users.noreply.github.ibm.com>
Co-authored-by: whitesource-ets[bot] <whitesource-ets[bot]@users.noreply.github.ibm.com>
  • Loading branch information
8 people authored Jan 23, 2024
1 parent 99e81b3 commit 44442df
Show file tree
Hide file tree
Showing 8 changed files with 925 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.env
.vscode

# ignore vendor/
vendor/
Expand All @@ -9,6 +10,9 @@ vendor/
.openapi-generator/VERSION
/.project

# API repo (pulled from Github)
api

# credentials files
*.env

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ to your `Gopkg.toml` file. Here is an example:
then run `dep ensure`.

## Using the SDK
Examples and a demo are available in the [example](/example) folder.
Examples are available [here](./example/v2/README.md).

For general SDK usage information, please see [this link](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md)

Expand Down
85 changes: 85 additions & 0 deletions example/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Code Engine Go SDK Example

## Running example_v2.go

To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory:
1. `export CE_API_KEY=<Your IBM Cloud API key>`
2. `export CE_PROJECT_REGION=<The region (e.g. 'us-south') of your Code Engine project>`
3. `export CE_DOMAIN_MAPPING_NAME=<The name of your domain>`
4. `export CE_TLS_CERT_FILE_PATH=<The path to your TLS certificate file>`
5. `export CE_TLS_KEY_FILE_PATH=<The path to your TLS key file>`
6. `go run example_v2.go`

## How-to

### Set up an authenticator
```go
authenticator := &core.IamAuthenticator{
ApiKey: os.Getenv("CE_API_KEY"),
ClientId: "bx",
ClientSecret: "bx",
URL: "https://iam.cloud.ibm.com",
}
```

### Set up a Code Engine client
```go
codeEngineServiceOptions := &codeenginev2.CodeEngineV2Options{
Authenticator: authenticator,
URL: "https://api." + os.Getenv("CE_PROJECT_REGION") + ".codeengine.cloud.ibm.com/v2",
}
codeEngineService, err := codeenginev2.NewCodeEngineV2UsingExternalConfig(codeEngineServiceOptions)
```

### Create a Code Engine project
```go
projectName := "my-project"
createdProject, _, err := codeEngineService.CreateProject(&codeenginev2.CreateProjectOptions{
Name: &projectName,
})
```

### Create a Code Engine application
```go
createAppOpts := codeEngineService.NewCreateAppOptions(
*createdProject.ID,
"icr.io/codeengine/helloworld",
"my-app",
)
createdApp, _, err := codeEngineService.CreateApp(createAppOpts)
```

### Create a Code Engine TLS secret
```go
createTLSSecretOpts := codeEngineService.NewCreateSecretOptions(
*createdProject.ID,
"tls",
"my-tls-secret",
)

tlsCert, _ := os.ReadFile(os.Getenv("CE_TLS_CERT_FILE_PATH"))
tlsKey, _ := os.ReadFile(os.Getenv("CE_TLS_KEY_FILE_PATH"))

createTLSSecretOpts.Data = &codeenginev2.SecretDataTLSSecretData{
TlsCert: core.StringPtr(string(tlsCert)),
TlsKey: core.StringPtr(string(tlsKey)),
}
createdTLSSecret, _, err := codeEngineService.CreateSecret(createTLSSecretOpts)
```

### Create a Code Engine domain mapping
```go
domainMappingName := os.Getenv("CE_DOMAIN_MAPPING_NAME")
appComponentRef := &codeenginev2.ComponentRef{
Name: createdApp.Name,
ResourceType: core.StringPtr("app_v2"),
}

createDomainMappingOpts := codeEngineService.NewCreateDomainMappingOptions(
*createdProject.ID,
appComponentRef,
domainMappingName,
*createdTLSSecret.Name,
)
createdDomainMapping, _, err := codeEngineService.CreateDomainMapping(createDomainMappingOpts)
```
Loading

0 comments on commit 44442df

Please sign in to comment.