Skip to content

Commit 44442df

Browse files
jasonpetwhitesource-ets[bot]michael-magrianreggeenrJohn Sartore
authored
Sdk update 20240123 124000 (#15)
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>
1 parent 99e81b3 commit 44442df

File tree

8 files changed

+925
-58
lines changed

8 files changed

+925
-58
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.env
3+
.vscode
34

45
# ignore vendor/
56
vendor/
@@ -9,6 +10,9 @@ vendor/
910
.openapi-generator/VERSION
1011
/.project
1112

13+
# API repo (pulled from Github)
14+
api
15+
1216
# credentials files
1317
*.env
1418

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ to your `Gopkg.toml` file. Here is an example:
9292
then run `dep ensure`.
9393

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

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

example/v2/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Code Engine Go SDK Example
2+
3+
## Running example_v2.go
4+
5+
To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory:
6+
1. `export CE_API_KEY=<Your IBM Cloud API key>`
7+
2. `export CE_PROJECT_REGION=<The region (e.g. 'us-south') of your Code Engine project>`
8+
3. `export CE_DOMAIN_MAPPING_NAME=<The name of your domain>`
9+
4. `export CE_TLS_CERT_FILE_PATH=<The path to your TLS certificate file>`
10+
5. `export CE_TLS_KEY_FILE_PATH=<The path to your TLS key file>`
11+
6. `go run example_v2.go`
12+
13+
## How-to
14+
15+
### Set up an authenticator
16+
```go
17+
authenticator := &core.IamAuthenticator{
18+
ApiKey: os.Getenv("CE_API_KEY"),
19+
ClientId: "bx",
20+
ClientSecret: "bx",
21+
URL: "https://iam.cloud.ibm.com",
22+
}
23+
```
24+
25+
### Set up a Code Engine client
26+
```go
27+
codeEngineServiceOptions := &codeenginev2.CodeEngineV2Options{
28+
Authenticator: authenticator,
29+
URL: "https://api." + os.Getenv("CE_PROJECT_REGION") + ".codeengine.cloud.ibm.com/v2",
30+
}
31+
codeEngineService, err := codeenginev2.NewCodeEngineV2UsingExternalConfig(codeEngineServiceOptions)
32+
```
33+
34+
### Create a Code Engine project
35+
```go
36+
projectName := "my-project"
37+
createdProject, _, err := codeEngineService.CreateProject(&codeenginev2.CreateProjectOptions{
38+
Name: &projectName,
39+
})
40+
```
41+
42+
### Create a Code Engine application
43+
```go
44+
createAppOpts := codeEngineService.NewCreateAppOptions(
45+
*createdProject.ID,
46+
"icr.io/codeengine/helloworld",
47+
"my-app",
48+
)
49+
createdApp, _, err := codeEngineService.CreateApp(createAppOpts)
50+
```
51+
52+
### Create a Code Engine TLS secret
53+
```go
54+
createTLSSecretOpts := codeEngineService.NewCreateSecretOptions(
55+
*createdProject.ID,
56+
"tls",
57+
"my-tls-secret",
58+
)
59+
60+
tlsCert, _ := os.ReadFile(os.Getenv("CE_TLS_CERT_FILE_PATH"))
61+
tlsKey, _ := os.ReadFile(os.Getenv("CE_TLS_KEY_FILE_PATH"))
62+
63+
createTLSSecretOpts.Data = &codeenginev2.SecretDataTLSSecretData{
64+
TlsCert: core.StringPtr(string(tlsCert)),
65+
TlsKey: core.StringPtr(string(tlsKey)),
66+
}
67+
createdTLSSecret, _, err := codeEngineService.CreateSecret(createTLSSecretOpts)
68+
```
69+
70+
### Create a Code Engine domain mapping
71+
```go
72+
domainMappingName := os.Getenv("CE_DOMAIN_MAPPING_NAME")
73+
appComponentRef := &codeenginev2.ComponentRef{
74+
Name: createdApp.Name,
75+
ResourceType: core.StringPtr("app_v2"),
76+
}
77+
78+
createDomainMappingOpts := codeEngineService.NewCreateDomainMappingOptions(
79+
*createdProject.ID,
80+
appComponentRef,
81+
domainMappingName,
82+
*createdTLSSecret.Name,
83+
)
84+
createdDomainMapping, _, err := codeEngineService.CreateDomainMapping(createDomainMappingOpts)
85+
```

0 commit comments

Comments
 (0)