Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SecureSourceManagerInstance PrivateConfig field API #3238

Open
wants to merge 169 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
5133fee
add repository controller
ericpang777 Nov 12, 2024
4923ad8
Add delete lro handling hack
ericpang777 Nov 12, 2024
fa3db49
Add mock
ericpang777 Nov 12, 2024
5c84414
Fix instance ref in repo controller
ericpang777 Nov 12, 2024
f6ec389
Add direct annotation to dependencies.yaml
ericpang777 Nov 12, 2024
e563022
Fix namespace reference
ericpang777 Nov 12, 2024
04ecd6c
log: real gcp
ericpang777 Nov 13, 2024
1e12a9c
Update log
ericpang777 Nov 13, 2024
b9ec860
fix mockgcp repository
ericpang777 Nov 13, 2024
4e010dd
Remove direct annotation
ericpang777 Nov 19, 2024
e1797e7
Remove another direct annotation
ericpang777 Nov 20, 2024
fcd512b
Remove direct annotation
ericpang777 Nov 20, 2024
3c69d73
Remove some todos
ericpang777 Nov 21, 2024
efe72f8
Fix instance controller delete handling, and add a recording for the …
ericpang777 Nov 21, 2024
8d8dbae
Use ref func
ericpang777 Nov 23, 2024
6e60e62
Add new private config field
ericpang777 Nov 21, 2024
09c79fa
Add private config field
ericpang777 Nov 21, 2024
8b1a550
Change to a capool ref
ericpang777 Nov 21, 2024
bf9a4ad
Remove pscallowedprojects and add a capoolref func
ericpang777 Nov 21, 2024
bc1c8ae
run make ready pr
ericpang777 Nov 21, 2024
3616c9c
move privateca ref to a separate file
ericpang777 Nov 26, 2024
db74799
fix import
ericpang777 Nov 26, 2024
25e8d06
Move privateca ref to refs package
ericpang777 Nov 28, 2024
655c25d
Fix build
ericpang777 Nov 28, 2024
d86f2e1
Fix privateca ref
ericpang777 Nov 29, 2024
0b8f55d
chore: create scripts to update APIs in mockgcp
justinsb Jul 18, 2024
5818661
chore: drop patch for psc_config in alloydb
justinsb Nov 20, 2024
224b707
autogen: update mockgcp API definitions
justinsb Nov 20, 2024
9763346
chore: ignore latest proto fields in fuzzer tests
justinsb Nov 20, 2024
542cd72
chore: rewrite policycontroller import in mockgcp
justinsb Nov 20, 2024
ef4421f
chore: add dependency on aiplatform api_auth
justinsb Nov 21, 2024
1f8a81c
chore: update golden output for new fields
justinsb Nov 21, 2024
fa31ab0
mockgcp: support VPCAccessConnector
justinsb Oct 18, 2024
c7da57b
mockgcp: generate vpcaccess
justinsb Oct 18, 2024
0299a55
mockgcp: update CloudFunctionsFunction mock
justinsb Nov 24, 2024
050ac2e
tests: golden output for VPCAccessConnector tests
justinsb Nov 24, 2024
e83005f
chore: controllergen uses pinned googleapi version
justinsb Nov 20, 2024
147e63b
mockgcp: support LoggingLogSink
justinsb Oct 18, 2024
9f1d06b
mockgcp: use correct version in selfLink
justinsb Nov 23, 2024
dbae825
mockgcp: pin googleapis for GRPC generation also
justinsb Nov 23, 2024
87cdd7c
mockgcp: update generated GRPC bindings
justinsb Nov 23, 2024
7a159ea
canonicalize memebershipID in order to make postsubmit tests pass
ziyue-101 Nov 22, 2024
2f75503
update backend service in compute tcp proxy
gemmahou Nov 21, 2024
13c0eac
mockGCP log
gemmahou Nov 23, 2024
16cba11
fix: Update apigee proto definition to fix naming conflict
jasonvigil Nov 14, 2024
2e9f039
Support env var to only compare http log events with given URL prefix
maqiuyujoyce Nov 22, 2024
2014132
Address comments
maqiuyujoyce Nov 23, 2024
481e0ba
mockgcp: generate cloudidentity proto from OpenAPI
justinsb Sep 23, 2024
d356c4e
mockgcp: implement cloudidentity group
justinsb Sep 23, 2024
d9eb7cb
mockgcp: add generated code
justinsb Sep 23, 2024
43ce2ab
tests: add CloudIdentityGroup output
justinsb Sep 23, 2024
6261c48
api: rework listing types
acpana Oct 23, 2024
9a71eba
api:refs: table ref
acpana Oct 23, 2024
c72cb40
feat: direct controller listing
acpana Oct 23, 2024
ef36507
tests: turn on mock listing
acpana Nov 12, 2024
a613777
tests: listing base
acpana Nov 12, 2024
9a7e436
refactor:refs: rework refs
acpana Nov 19, 2024
f419ad7
refs: use NormalizeExternal (new refs style)
acpana Nov 22, 2024
1ac8d92
chore: specify run for download-e2e-logs
justinsb Nov 26, 2024
d2c94eb
mockgcp: fidelity for ComputeNetworks with autoCreateSubnets
justinsb Jul 16, 2024
9f641ad
tests: create test for ComputeNetwork with autoCreateSubnets=true
justinsb Jul 16, 2024
8c26e80
tests: update golden output
justinsb Nov 26, 2024
8809696
Memorystore API spec and status
himanikh Nov 26, 2024
2ac3357
pr-ready
himanikh Nov 26, 2024
2325f24
addressing the comments
himanikh Nov 26, 2024
78fa440
pr-ready
himanikh Nov 26, 2024
7a95a56
chore: add fmt to `make ready-pr`
yuwenma Nov 26, 2024
afd873e
feat: add v1beta1 API for customizing contorller rate limit
jingyih Nov 22, 2024
0c04621
chore: add back v1alpha1 API for container rate limit
jingyih Nov 22, 2024
9f0a4b1
feat: mark v1beta1 as storage version
jingyih Nov 22, 2024
1c6a0f8
feat: update controllers and tests to use v1beta1
jingyih Nov 22, 2024
dba5206
chore: update samples to use v1beta1
jingyih Nov 22, 2024
7ebaea9
tool: no need to specify flags with default values
jingyih Nov 26, 2024
393f93e
chore: remove e2e.log
justinsb Nov 26, 2024
565138a
fix: Remove wait after SQLInstance periodic test steps
jasonvigil Nov 15, 2024
9c904c7
Ignore NotFound error when deleting PrivilegedAccessManagerEntitlement
maqiuyujoyce Nov 26, 2024
5c95559
Sync mockalloydb with latest googleapis repo
maqiuyujoyce Nov 14, 2024
61ccfa6
Run AlloyDBCluster and AlloyDBInstance test cases against real GCP
maqiuyujoyce Nov 14, 2024
af08660
Run AlloyDBCluster and AlloyDBInstance test cases against mock GCP
maqiuyujoyce Nov 21, 2024
7aab48f
Update mockgcp and test data normalization logic to match the golden …
maqiuyujoyce Nov 21, 2024
a192aee
Fix presubmit tests
maqiuyujoyce Nov 21, 2024
fe486fa
Address comments
maqiuyujoyce Nov 23, 2024
1c643b0
Revert the change in mockgcp/Makefile
maqiuyujoyce Nov 26, 2024
49eb060
Remove unnecessary normalizer and update mockalloydb
maqiuyujoyce Nov 26, 2024
1629bfe
feat: A new parent interface
yuwenma Nov 21, 2024
aa5e4ba
improve generate-crds
yuwenma Nov 27, 2024
269b196
docs: update release note from #3244
jingyih Nov 27, 2024
23c63ee
chore: skip dcl code-generation in read-pr
yuwenma Nov 27, 2024
9525ed5
Release 1.126.0-rc.1
yuwenma Nov 27, 2024
782c0d0
chore: add apt-get update to install-tools
justinsb Dec 2, 2024
393a88c
improve update method to avoid permanent diff
ziyue-101 Nov 27, 2024
1a3c89d
feat: add mockgcp for bigqueryroutine
xiaoweim Oct 17, 2024
a7e710b
add real GCP log
xiaoweim Nov 5, 2024
e026833
add mock GCP log
xiaoweim Nov 5, 2024
aaa6d33
update the update.yaml files
xiaoweim Nov 7, 2024
6974405
enable bigquery in e2e
yuwenma Nov 27, 2024
5a91ed9
Add management field for gkehubfeaturemembership
ziyue-101 Nov 25, 2024
57afaf8
fix: regen logs
acpana Dec 3, 2024
45e6662
Create mockGCP service for Apigee
Camila-B Nov 27, 2024
a53819e
Add Apigee envgroup test suite
Camila-B Dec 2, 2024
a9728d7
log: real gcp
Camila-B Dec 2, 2024
bab3dc2
log: mock gcp
Camila-B Dec 2, 2024
26ec0da
Remove unnecessary cases
Camila-B Dec 2, 2024
2fcabc1
Release 1.126.0-rc.2
yuwenma Dec 3, 2024
1356e03
chore: pass in just enough args to ResolveProject
yuwenma Nov 21, 2024
a2e5125
chore: improve secretmanager on edge case handling
yuwenma Dec 2, 2024
2bfa9f9
improve annotations
yuwenma Dec 2, 2024
67bfac1
tf-based result
yuwenma Dec 3, 2024
bafcb50
direct real gcp
yuwenma Dec 3, 2024
de164cf
revert label and annotation changes
yuwenma Dec 3, 2024
837af00
feat: support referencing serviceAccountID from bigquery connection i…
jingyih Nov 20, 2024
7e0f80c
address comments
jingyih Dec 3, 2024
4112ca4
chore: move BQCC service account ref to bigqueryconnection package
jingyih Dec 3, 2024
eba52a5
fix: update to use new ResolveProject func
acpana Dec 4, 2024
6121799
fix: update to use new ResolveProject func
acpana Dec 4, 2024
f43b189
docs:Update release-1.126.md
acpana Dec 3, 2024
1d99eba
chore: do not import direct package in apis
jingyih Dec 3, 2024
31ef9d6
tests: stage random filler
acpana Nov 11, 2024
6e4768b
chore: add public sample for BQCC referenced in IAMPolicyMemeber
jingyih Dec 4, 2024
9f4fc6c
refactor: add source for ToProto
acpana Dec 2, 2024
05a3901
refactor: s/table/tableRef
acpana Dec 2, 2024
07cd77e
chore: regen log
acpana Dec 3, 2024
7a851a9
tests: set 0 llm
acpana Nov 20, 2024
06b7e96
chore: add real logs
acpana Dec 3, 2024
15dc886
feat: Implement WorkstationConfig direct controller and record GCP
jasonvigil Nov 14, 2024
0b5f1c0
fix: Update docs for ApigeeEnvironment conditional IAM support
jasonvigil Dec 3, 2024
d0b2a1d
docs: update release note from #3231
jingyih Dec 4, 2024
fbbe572
feat: Add mockgcp for WorkstationConfig
jasonvigil Nov 27, 2024
66aeb43
initial commit for alpha to beta for keyhandl
nb-goog Dec 5, 2024
b5d1759
test
nb-goog Dec 5, 2024
4b05af1
resource tmpl for keyhandl
nb-goog Dec 5, 2024
46fb99b
doc
nb-goog Dec 5, 2024
85e5900
fix: Update help text for controller-builder command
jasonvigil Dec 5, 2024
a7f8b7a
feat: add secretManager version alias
yuwenma Dec 4, 2024
9d2c7a2
test: scenario test for SecretManager version alias
yuwenma Dec 3, 2024
71cbc12
add export
yuwenma Dec 4, 2024
57a2c83
real->mock
yuwenma Dec 4, 2024
da243c1
fix: Add known acronyms for type generator
jasonvigil Nov 19, 2024
6eed0a3
Release 1.126.0
yuwenma Dec 5, 2024
4ad6423
Correct typo in autokey config documentation
nb-goog Dec 6, 2024
5082cf5
Add SSM Instance CMEK tests
ericpang777 Nov 22, 2024
1914afc
Add cmek example and record real gcp
ericpang777 Nov 24, 2024
198c40f
realgcp log
ericpang777 Nov 24, 2024
dfad879
log mock
ericpang777 Nov 24, 2024
aa6cecd
log real gcp
ericpang777 Nov 24, 2024
fce0462
use the mock test
ericpang777 Nov 24, 2024
ae16c2f
fix refs
ericpang777 Nov 29, 2024
37c18ac
chore: enable disco api for tests
acpana Dec 4, 2024
b3c66f0
chore: turn on readOnlyRootFilesystem for GKE add-on release'
yuwenma Dec 9, 2024
6703d17
feat: Add capability to replace proto contents in patch-proto
jasonvigil Dec 10, 2024
2442fa0
fix: add version
acpana Dec 10, 2024
da92db6
fix: improve listing
acpana Dec 6, 2024
5ce622c
refactor: rename field
acpana Dec 6, 2024
24265ed
refactor: rename var
acpana Dec 11, 2024
b673255
test:add a scenario test for unset fields in bigquerydataset
xiaoweim Dec 6, 2024
b953f12
tool: optionally skip scaffolding files when generating types
jingyih Dec 5, 2024
7d5c777
chore: update types and mappers for bigquerydatatransferconfig
jingyih Dec 5, 2024
bdaf8fc
chore: bump cloud.google.com/go/bigquery from 1.63.1 to 1.65.0
jingyih Dec 5, 2024
cf79201
chore: manual edits to types and mappers for bigquerydatatransferconfig
jingyih Dec 6, 2024
3f27718
feat: make spec.scheduleOptionsV2.eventDrivenSchedule.pubsubSubscript…
jingyih Dec 6, 2024
fee5549
test: fix fuzz test FuzzBigQueryDataTransferConfigSpec
jingyih Dec 6, 2024
9f32ac7
make ready-pr
jingyih Dec 6, 2024
e439a3e
chore: address comments
jingyih Dec 11, 2024
ba6022b
refactor: refactor type updater code
jingyih Dec 7, 2024
fac2946
tool: improve typeupdater to handle spec/obeservedState case
jingyih Dec 8, 2024
70bedca
Log error when update is not supported
gemmahou Nov 25, 2024
b6c51b5
refactor:tests: add overrides
acpana Dec 11, 2024
d97e873
Enable klog in dynamic test
maqiuyujoyce Dec 6, 2024
7594763
Merge remote-tracking branch 'origin' into ssmins-private
umairidris Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions apis/refs/v1beta1/privatecaref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1

import (
"context"
"fmt"
"strings"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type PrivateCACAPoolRef struct {
// A reference to an externally managed PrivateCACAPool.
// Should be in the format `projects/{project_id}/locations/{region}/caPools/{caPool}`.
External string `json:"external,omitempty"`

// The `name` of a `PrivateCACAPool` resource.
Name string `json:"name,omitempty"`
// The `namespace` of a `PrivateCACAPool` resource.
Namespace string `json:"namespace,omitempty"`
}

type PrivateCACAPool struct {
Ref *PrivateCACAPoolRef
ResourceID string
}

// ResolvePrivateCACAPoolRef will resolve a PrivateCACAPoolRef to a PrivateCACAPool.
func ResolvePrivateCACAPoolRef(ctx context.Context, reader client.Reader, src client.Object, ref *PrivateCACAPoolRef) (*PrivateCACAPoolRef, error) {
if ref == nil {
return nil, nil
}

if ref.Name == "" && ref.External == "" {
return nil, fmt.Errorf("must specify either name or external on PrivateCACAPoolRef")
}
if ref.Name != "" && ref.External != "" {
return nil, fmt.Errorf("cannot specify both name and external on PrivateCACAPoolRef")
}

// External should be in the `projects/{project_id}/locations/{region}/caPools/{caPool}` format
if ref.External != "" {
tokens := strings.Split(ref.External, "/")
if len(tokens) == 6 && tokens[0] == "projects" && tokens[2] == "locations" && tokens[4] == "caPools" {
ref = &PrivateCACAPoolRef{
External: fmt.Sprintf("projects/%s/locations/%s/caPools/%s", tokens[1], tokens[3], tokens[5]),
}
return ref, nil
}
return nil, fmt.Errorf("format of PrivateCACAPoolRef external=%q was not known (use projects/{project_id}/locations/{region}/caPools/{caPool})", ref.External)
}

key := types.NamespacedName{
Namespace: ref.Namespace,
Name: ref.Name,
}
if key.Namespace == "" {
key.Namespace = src.GetNamespace()
}

// Fetch object from k8s cluster to construct the external form
caPool := &unstructured.Unstructured{}
caPool.SetGroupVersionKind(schema.GroupVersionKind{
Group: "privateca.cnrm.cloud.google.com",
Version: "v1beta1",
Kind: "PrivateCACAPool",
})
if err := reader.Get(ctx, key, caPool); err != nil {
if apierrors.IsNotFound(err) {
return nil, fmt.Errorf("referenced PrivateCACAPool %v not found", key)
}
return nil, fmt.Errorf("error reading referenced PrivateCACAPool %v: %w", key, err)
}

caPoolResourceID, err := GetResourceID(caPool)
if err != nil {
return nil, err
}

projectID, err := ResolveProjectID(ctx, reader, caPool)
if err != nil {
return nil, err
}

location, err := GetLocation(caPool)
if err != nil {
return nil, err
}

ref = &PrivateCACAPoolRef{
External: fmt.Sprintf("projects/%s/locations/%s/caPools/%s", projectID, location, caPoolResourceID),
}

return ref, nil
}
3 changes: 3 additions & 0 deletions apis/securesourcemanager/v1alpha1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type SecureSourceManagerInstanceSpec struct {

// Optional. Immutable. Customer-managed encryption key name.
KmsKeyRef *refs.KMSCryptoKeyRef `json:"kmsKeyRef,omitempty"`

// Optional. PrivateConfig includes settings for private instance.
PrivateConfig *Instance_PrivateConfig `json:"privateConfig,omitempty"`
}

// SecureSourceManagerInstanceStatus defines the config connector machine state of SecureSourceManagerInstance
Expand Down
6 changes: 5 additions & 1 deletion apis/securesourcemanager/v1alpha1/types.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions apis/securesourcemanager/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,51 @@ spec:
location:
description: Immutable. Location of the instance.
type: string
privateConfig:
description: Optional. PrivateConfig includes settings for private
instance.
properties:
caPoolRef:
description: Required. Immutable. CA pool resource, resource must
in the format of `projects/{project}/locations/{location}/caPools/{ca_pool}`.
oneOf:
- not:
required:
- external
required:
- name
- not:
anyOf:
- required:
- name
- required:
- namespace
required:
- external
properties:
external:
description: A reference to an externally managed PrivateCACAPool.
Should be in the format `projects/{project_id}/locations/{region}/caPools/{caPool}`.
type: string
name:
description: The `name` of a `PrivateCACAPool` resource.
type: string
namespace:
description: The `namespace` of a `PrivateCACAPool` resource.
type: string
type: object
httpServiceAttachment:
description: Output only. Service Attachment for HTTP, resource
is in the format of `projects/{project}/regions/{region}/serviceAttachments/{service_attachment}`.
type: string
isPrivate:
description: Required. Immutable. Indicate if it's private instance.
type: boolean
sshServiceAttachment:
description: Output only. Service Attachment for SSH, resource
is in the format of `projects/{project}/regions/{region}/serviceAttachments/{service_attachment}`.
type: string
type: object
projectRef:
description: Immutable. The Project that this resource belongs to.
oneOf:
Expand Down
1 change: 1 addition & 0 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured
case schema.GroupKind{Group: "secretmanager.cnrm.cloud.google.com", Kind: "SecretManagerSecretVersion"}:

case schema.GroupKind{Group: "securesourcemanager.cnrm.cloud.google.com", Kind: "SecureSourceManagerInstance"}:
case schema.GroupKind{Group: "securesourcemanager.cnrm.cloud.google.com", Kind: "SecureSourceManagerRepository"}:

case schema.GroupKind{Group: "servicedirectory.cnrm.cloud.google.com", Kind: "ServiceDirectoryNamespace"}:
case schema.GroupKind{Group: "servicedirectory.cnrm.cloud.google.com", Kind: "ServiceDirectoryService"}:
Expand Down
167 changes: 167 additions & 0 deletions mockgcp/mocksecuresourcemanager/repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mocksecuresourcemanager

import (
"context"
"fmt"
"strings"
"time"

longrunning "google.golang.org/genproto/googleapis/longrunning"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/securesourcemanager/v1"
)

func (s *secureSourceManagerServer) GetRepository(ctx context.Context, req *pb.GetRepositoryRequest) (*pb.Repository, error) {
name, err := s.parseRepositoryName(req.Name)
if err != nil {
return nil, err
}

fqn := name.String()

obj := &pb.Repository{}
if err := s.storage.Get(ctx, fqn, obj); err != nil {
if status.Code(err) == codes.NotFound {
return nil, status.Errorf(codes.NotFound, "Resource '%s' was not found", fqn)
}
return nil, err
}

return obj, nil
}

func (s *secureSourceManagerServer) CreateRepository(ctx context.Context, req *pb.CreateRepositoryRequest) (*longrunning.Operation, error) {
reqName := req.Parent + "/repositories/" + req.RepositoryId
name, err := s.parseRepositoryName(reqName)
if err != nil {
return nil, err
}

fqn := name.String()

now := time.Now()

obj := proto.Clone(req.Repository).(*pb.Repository)
obj.Name = fqn

obj.CreateTime = timestamppb.New(now)
obj.UpdateTime = timestamppb.New(now)

instanceName, err := s.parseInstanceName(obj.GetInstance())
if err != nil {
return nil, err
}

obj.InitialConfig = req.GetRepository().GetInitialConfig()

prefix := fmt.Sprintf("https://%s-%d", instanceName.InstanceID, name.Project.Number)
domain := "." + name.Location + ".sourcemanager.dev"
obj.Uris = &pb.Repository_URIs{
Html: prefix + domain + fmt.Sprintf("/%s/%s", name.Project.ID, req.GetRepositoryId()),
Api: prefix + "-api" + domain + fmt.Sprintf("/v1/projects/%s/locations/%s/repositories/%s", name.Project.ID, name.Location, req.GetRepositoryId()),
GitHttps: prefix + "-git" + domain + fmt.Sprintf("/%s/%s.git", name.Project.ID, req.GetRepositoryId()),
}

if err := s.storage.Create(ctx, fqn, obj); err != nil {
return nil, err
}

op := &pb.OperationMetadata{
CreateTime: timestamppb.New(now),
Target: name.String(),
Verb: "create",
ApiVersion: "v1",
}
opPrefix := fmt.Sprintf("projects/%s/locations/%s", name.Project.ID, name.Location)
return s.operations.StartLRO(ctx, opPrefix, op, func() (proto.Message, error) {
op.EndTime = timestamppb.Now()
return obj, nil
})
}

func (s *secureSourceManagerServer) DeleteRepository(ctx context.Context, req *pb.DeleteRepositoryRequest) (*longrunning.Operation, error) {
name, err := s.parseRepositoryName(req.GetName())
if err != nil {
return nil, err
}

fqn := name.String()
now := time.Now()

deleted := &pb.Repository{}
if err := s.storage.Delete(ctx, fqn, deleted); err != nil {
return nil, err
}

op := &pb.OperationMetadata{
CreateTime: timestamppb.New(now),
Target: name.String(),
Verb: "delete",
ApiVersion: "v1",
}
opPrefix := fmt.Sprintf("projects/%s/locations/%s", name.Project.ID, name.Location)
return s.operations.StartLRO(ctx, opPrefix, op, func() (proto.Message, error) {
op.EndTime = timestamppb.Now()
return &emptypb.Empty{}, nil
})
}

type RepositoryName struct {
Project *projects.ProjectData
Location string
RepositoryID string
}

func (n *RepositoryName) String() string {
return fmt.Sprintf("projects/%s/locations/%s/repositories/%s", n.Project.ID, n.Location, n.RepositoryID)
}

// func (n *RepositoryName) Target() string {
// return fmt.Sprintf("projects/%s/locations/%s/repositories/%s", n.Project.ID, n.Location, n.RepositoryID)
// }

// parseRepositoryName parses a string into a RepositoryName.
// The expected form is projects/*/locations/*/repositories/*
func (s *MockService) parseRepositoryName(name string) (*RepositoryName, error) {
tokens := strings.Split(name, "/")

if len(tokens) == 6 && tokens[0] == "projects" && tokens[2] == "locations" && tokens[4] == "repositories" {
projectName, err := projects.ParseProjectName(tokens[0] + "/" + tokens[1])
if err != nil {
return nil, err
}
project, err := s.Projects.GetProject(projectName)
if err != nil {
return nil, err
}

name := &RepositoryName{
Project: project,
Location: tokens[3],
RepositoryID: tokens[5],
}
return name, nil
} else {
return nil, status.Errorf(codes.InvalidArgument, "name %q is not valid", name)
}
}
Loading
Loading