Skip to content

Commit

Permalink
docs: Generate better titles for samples
Browse files Browse the repository at this point in the history
We probably should have an override capability, but .... this works.
  • Loading branch information
justinsb committed Nov 3, 2024
1 parent 84014d5 commit a8dca2c
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ observedState:

## Sample YAML(s)

### Bigquerydatatransferconfig Salesforce
### BigQueryDataTransferConfig Salesforce
```yaml
# Copyright 2024 Google LLC
#
Expand Down Expand Up @@ -690,7 +690,7 @@ spec:
location: us-central1
```

### Bigquerydatatransferconfig Scheduledquery
### BigQueryDataTransferConfig Scheduledquery
```yaml
# Copyright 2024 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ results in a new version of a function being created.{% endverbatim %}</p>

## Sample YAML(s)

### Eventtrigger With Pubsubtopic
### Eventtrigger With PubSubTopic
```yaml
# Copyright 2022 Google LLC
#
Expand Down Expand Up @@ -804,7 +804,7 @@ spec:
external: "projects/${PROJECT_ID?}"
```

### Eventtrigger With Storagebucket
### Eventtrigger With StorageBucket
```yaml
# Copyright 2022 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ spec:
displayName: Example Service Account
```

### Scheduler Job Pubsub
### Scheduler Job PubSub
```yaml
# Copyright 2020 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ if the cluster does not have any worker nodes.{% endverbatim %}</p>

## Sample YAML(s)

### Edgecontainercluster Local Control Plane
### EdgeContainerCluster Local Control Plane
```yaml
# Copyright 2023 Google LLC
#
Expand Down Expand Up @@ -1106,7 +1106,7 @@ spec:
- ${EXTERNAL_LOAD_BALANCER_IPV4_CIDR?}
```

### Edgecontainercluster Remote Control Plane
### EdgeContainerCluster Remote Control Plane
```yaml
# Copyright 2023 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ observedGeneration: integer
## Sample YAML(s)
### Project Level Policy
### Project Level Iampartialpolicy
```yaml
# Copyright 2020 Google LLC
#
Expand Down Expand Up @@ -1120,7 +1120,7 @@ spec:
external: "${ORG_ID?}"
```
### Pubsub Admin Policy
### PubSub Admin Iampartialpolicy
```yaml
# Copyright 2020 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ spec:
external: "${ORG_ID?}"
```
### Pubsub Admin Policy
### PubSub Admin Policy
```yaml
# Copyright 2020 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ metadata:
name: iampolicymember-dep-memberref
```
### Pubsub Admin Policy Member
### PubSub Admin Policy Member
```yaml
# Copyright 2020 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ spec:
enabled: false
```
### Pubsub Monitoring Notification Channel
### PubSub Monitoring Notification Channel
```yaml
# Copyright 2022 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ observedGeneration: integer

## Sample YAML(s)

### Basic Pubsub Subscription
### Basic PubSub Subscription
```yaml
# Copyright 2020 Google LLC
#
Expand Down Expand Up @@ -906,7 +906,7 @@ metadata:
name: pubsubsubscription-dep2-basic
```

### BigQuery Pubsub Subscription
### BigQuery PubSub Subscription
```yaml
# Copyright 2022 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ spec:
- launch_stage
```

### Job With Iamserviceaccount
### Job With IAMServiceAccount
```yaml
# Copyright 2023 Google LLC
#
Expand Down Expand Up @@ -1930,7 +1930,7 @@ spec:
displayName: runjob-dep-iamserviceaccount
```

### Job With Kmscryptokey
### Job With KMSCryptoKey
```yaml
# Copyright 2023 Google LLC
#
Expand Down Expand Up @@ -2043,7 +2043,7 @@ spec:
tier: db-n1-standard-1
```

### Job With Secretmanagersecret
### Job With SecretManagerSecret
```yaml
# Copyright 2023 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2487,7 +2487,7 @@ spec:
name: runservice-dep-serviceaccount
```

### Run Service Vpcaccess
### Run Service VPCAccess
```yaml
# Copyright 2022 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ observedState:

## Sample YAML(s)

### Vertexai Dataset Basic
### VertexAI Dataset Basic
```yaml
# Copyright 2024 Google LLC
#
Expand Down Expand Up @@ -355,7 +355,7 @@ spec:
external: ${PROJECT_ID?}
```

### Vertexai Dataset Encryptionkey
### VertexAI Dataset Encryptionkey
```yaml
# Copyright 2024 Google LLC
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ observedState:

## Sample YAML(s)

### Vertexai Endpoint Encryptionkey
### VertexAI Endpoint Encryptionkey
```yaml
# Copyright 2024 Google LLC
#
Expand Down Expand Up @@ -453,7 +453,7 @@ spec:
resourceID: aiplatform.googleapis.com
```

### Vertexai Endpoint Network
### VertexAI Endpoint Network
```yaml
# Copyright 2024 Google LLC
#
Expand Down
45 changes: 26 additions & 19 deletions scripts/generate-google3-docs/resource-reference/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"fmt"
"io/fs"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -487,7 +488,7 @@ func buildSamples(kind, sampleDirPath string, smLoader *servicemappingloader.Ser
if err != nil {
return nil, fmt.Errorf("error building sample at %v: %w", subDirPath, err)
}
name := formatDirectoryName(subDir.Name(), smLoader.GetServiceMappings())
name := titleForSample(subDir, smLoader.GetServiceMappings())
sampleYAMLs[name] = sample
}
} else {
Expand Down Expand Up @@ -766,31 +767,37 @@ func referencesSupportedByIAMAuditConfig(smLoader *servicemappingloader.ServiceM
return refs, nil
}

func formatDirectoryName(s string, serviceMappings []v1alpha1.ServiceMapping) string {
nameToSm := make(map[string]v1alpha1.ServiceMapping)
// titleForSample returns the title that should be used for the sample
func titleForSample(dir fs.FileInfo, serviceMappings []v1alpha1.ServiceMapping) string {
serviceMappingNames := make(map[string]v1alpha1.ServiceMapping)
resourceKinds := make(map[string]v1alpha1.ResourceConfig)
for _, sm := range serviceMappings {
nameToSm[sm.Spec.Name] = sm
serviceMappingNames[strings.ToLower(sm.Spec.Name)] = sm

for _, resource := range sm.Spec.Resources {
resourceKinds[strings.ToLower(resource.Kind)] = resource
}
}
split := strings.Split(s, "-")
ret := ""
for i, v := range split {
title := strings.Title(v)
if _, ok := nameToSm[strings.ToUpper(title)]; ok {
// value is IAM, KMS, etc, don't use strings.Title(v) as it will result in Kms or Iam
title = strings.ToUpper(title)
split := strings.Split(dir.Name(), "-")
var words []string
for _, v := range split {
word := strings.Title(v)
if serviceMapping, ok := serviceMappingNames[strings.ToLower(word)]; ok {
// If it's a well-known service, use its correctly capitalized name (PubSub, VertexAI etc)
word = serviceMapping.Spec.Name
}
if resource, ok := resourceKinds[strings.ToLower(word)]; ok {
// If it's a well-known kind, use the correct capitalization
word = resource.Kind
}
for _, s := range allowedSpellings {
if strings.ToLower(s) == strings.ToLower(title) {
title = s
if strings.EqualFold(s, word) {
word = s
}
}
if i != len(split)-1 {
ret += title + " "
} else {
ret += title
}
words = append(words, word)
}
return ret
return strings.Join(words, " ")
}

func resourceSupportsIAMPolicyAndPolicyMember(rc *v1alpha1.ResourceConfig) bool {
Expand Down

0 comments on commit a8dca2c

Please sign in to comment.