|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package containerattached |
| 16 | + |
| 17 | +import ( |
| 18 | + pb "cloud.google.com/go/gkemulticloud/apiv1/gkemulticloudpb" |
| 19 | + krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/containerattached/v1beta1" |
| 20 | + "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct" |
| 21 | +) |
| 22 | + |
| 23 | +func Fleet_FromProto(mapCtx *direct.MapContext, in *pb.Fleet) *krm.Fleet { |
| 24 | + if in == nil { |
| 25 | + return nil |
| 26 | + } |
| 27 | + out := &krm.Fleet{} |
| 28 | + out.ProjectRef.External = in.GetProject() |
| 29 | + out.Membership = direct.LazyPtr(in.GetMembership()) |
| 30 | + return out |
| 31 | +} |
| 32 | + |
| 33 | +func Fleet_ToProto(mapCtx *direct.MapContext, in *krm.Fleet) *pb.Fleet { |
| 34 | + if in == nil { |
| 35 | + return nil |
| 36 | + } |
| 37 | + out := &pb.Fleet{} |
| 38 | + if in.ProjectRef.External == "" { |
| 39 | + mapCtx.Errorf("Fleet project external reference was not pre-resolved") |
| 40 | + } |
| 41 | + out.Project = in.ProjectRef.External |
| 42 | + out.Membership = direct.ValueOf(in.Membership) |
| 43 | + return out |
| 44 | +} |
| 45 | + |
| 46 | +func AttachedClustersAuthorization_FromProto(mapCtx *direct.MapContext, in *pb.AttachedClustersAuthorization) *krm.AttachedClustersAuthorization { |
| 47 | + if in == nil { |
| 48 | + return nil |
| 49 | + } |
| 50 | + out := &krm.AttachedClustersAuthorization{} |
| 51 | + out.AdminUsers = direct.Slice_FromProto(mapCtx, in.AdminUsers, func(mapCtx *direct.MapContext, p *pb.AttachedClusterUser) *string { |
| 52 | + return direct.LazyPtr(p.GetUsername()) |
| 53 | + }) |
| 54 | + /*NOTYET |
| 55 | + // MISSING: AdminGroups |
| 56 | + */ |
| 57 | + return out |
| 58 | +} |
| 59 | + |
| 60 | +func AttachedClustersAuthorization_ToProto(mapCtx *direct.MapContext, in *krm.AttachedClustersAuthorization) *pb.AttachedClustersAuthorization { |
| 61 | + if in == nil { |
| 62 | + return nil |
| 63 | + } |
| 64 | + out := &pb.AttachedClustersAuthorization{} |
| 65 | + out.AdminUsers = direct.Slice_ToProto(mapCtx, in.AdminUsers, func(mapCtx *direct.MapContext, p *string) *pb.AttachedClusterUser { |
| 66 | + return &pb.AttachedClusterUser{Username: direct.ValueOf(p)} |
| 67 | + }) |
| 68 | + /*NOTYET |
| 69 | + // MISSING: AdminGroups |
| 70 | + */ |
| 71 | + return out |
| 72 | +} |
| 73 | + |
| 74 | +func AttachedOidcConfig_FromProto(mapCtx *direct.MapContext, in *pb.AttachedOidcConfig) *krm.AttachedOidcConfig { |
| 75 | + if in == nil { |
| 76 | + return nil |
| 77 | + } |
| 78 | + out := &krm.AttachedOidcConfig{} |
| 79 | + out.IssuerURL = in.GetIssuerUrl() |
| 80 | + out.Jwks = in.GetJwks() |
| 81 | + return out |
| 82 | +} |
| 83 | + |
| 84 | +func AttachedOidcConfig_ToProto(mapCtx *direct.MapContext, in *krm.AttachedOidcConfig) *pb.AttachedOidcConfig { |
| 85 | + if in == nil { |
| 86 | + return nil |
| 87 | + } |
| 88 | + out := &pb.AttachedOidcConfig{} |
| 89 | + out.IssuerUrl = in.IssuerURL |
| 90 | + out.Jwks = in.Jwks |
| 91 | + return out |
| 92 | +} |
| 93 | + |
| 94 | +func ContainerAttachedClusterSpec_FromProto(mapCtx *direct.MapContext, in *pb.AttachedCluster) *krm.ContainerAttachedClusterSpec { |
| 95 | + if in == nil { |
| 96 | + return nil |
| 97 | + } |
| 98 | + out := &krm.ContainerAttachedClusterSpec{} |
| 99 | + out.Description = direct.LazyPtr(in.GetDescription()) |
| 100 | + out.OidcConfig = *AttachedOidcConfig_FromProto(mapCtx, in.GetOidcConfig()) |
| 101 | + out.PlatformVersion = in.GetPlatformVersion() |
| 102 | + out.Distribution = in.GetDistribution() |
| 103 | + out.Fleet = *Fleet_FromProto(mapCtx, in.GetFleet()) |
| 104 | + /*NOTYET |
| 105 | + // MISSING: Etag |
| 106 | + */ |
| 107 | + out.Annotations = in.Annotations |
| 108 | + out.LoggingConfig = LoggingConfig_FromProto(mapCtx, in.GetLoggingConfig()) |
| 109 | + out.Authorization = AttachedClustersAuthorization_FromProto(mapCtx, in.GetAuthorization()) |
| 110 | + out.MonitoringConfig = MonitoringConfig_FromProto(mapCtx, in.GetMonitoringConfig()) |
| 111 | + /*NOTYET |
| 112 | + // MISSING: ProxyConfig |
| 113 | + */ |
| 114 | + out.BinaryAuthorization = BinaryAuthorization_FromProto(mapCtx, in.GetBinaryAuthorization()) |
| 115 | + return out |
| 116 | +} |
| 117 | + |
| 118 | +func ContainerAttachedClusterSpec_ToProto(mapCtx *direct.MapContext, in *krm.ContainerAttachedClusterSpec) *pb.AttachedCluster { |
| 119 | + if in == nil { |
| 120 | + return nil |
| 121 | + } |
| 122 | + out := &pb.AttachedCluster{} |
| 123 | + out.Description = direct.ValueOf(in.Description) |
| 124 | + out.OidcConfig = AttachedOidcConfig_ToProto(mapCtx, &in.OidcConfig) |
| 125 | + out.PlatformVersion = in.PlatformVersion |
| 126 | + out.Distribution = in.Distribution |
| 127 | + out.Fleet = Fleet_ToProto(mapCtx, &in.Fleet) |
| 128 | + /*NOTYET |
| 129 | + // MISSING: Etag |
| 130 | + */ |
| 131 | + out.Annotations = in.Annotations |
| 132 | + out.LoggingConfig = LoggingConfig_ToProto(mapCtx, in.LoggingConfig) |
| 133 | + out.Authorization = AttachedClustersAuthorization_ToProto(mapCtx, in.Authorization) |
| 134 | + out.MonitoringConfig = MonitoringConfig_ToProto(mapCtx, in.MonitoringConfig) |
| 135 | + /*NOTYET |
| 136 | + // MISSING: ProxyConfig |
| 137 | + */ |
| 138 | + out.BinaryAuthorization = BinaryAuthorization_ToProto(mapCtx, in.BinaryAuthorization) |
| 139 | + return out |
| 140 | +} |
| 141 | + |
| 142 | +func LoggingComponentConfig_FromProto(mapCtx *direct.MapContext, in *pb.LoggingComponentConfig) *krm.LoggingComponentConfig { |
| 143 | + if in == nil { |
| 144 | + return nil |
| 145 | + } |
| 146 | + out := &krm.LoggingComponentConfig{} |
| 147 | + out.EnableComponents = slice_FromProto(mapCtx, in.EnableComponents, func(mapCtx *direct.MapContext, p pb.LoggingComponentConfig_Component) *string { |
| 148 | + return direct.Enum_FromProto(mapCtx, p) |
| 149 | + }) |
| 150 | + return out |
| 151 | +} |
| 152 | + |
| 153 | +func LoggingComponentConfig_ToProto(mapCtx *direct.MapContext, in *krm.LoggingComponentConfig) *pb.LoggingComponentConfig { |
| 154 | + if in == nil { |
| 155 | + return nil |
| 156 | + } |
| 157 | + out := &pb.LoggingComponentConfig{} |
| 158 | + out.EnableComponents = slice_ToProto(mapCtx, in.EnableComponents, func(mapCtx *direct.MapContext, s *string) pb.LoggingComponentConfig_Component { |
| 159 | + ret := direct.Enum_ToProto[pb.LoggingComponentConfig_Component](mapCtx, s) |
| 160 | + return ret |
| 161 | + }) |
| 162 | + return out |
| 163 | +} |
| 164 | + |
| 165 | +func slice_ToProto[T, U any](mapCtx *direct.MapContext, in []T, mapper func(mapCtx *direct.MapContext, in *T) U) []U { |
| 166 | + if in == nil { |
| 167 | + return nil |
| 168 | + } |
| 169 | + |
| 170 | + outSlice := make([]U, 0, len(in)) |
| 171 | + for _, inItem := range in { |
| 172 | + outItem := mapper(mapCtx, &inItem) |
| 173 | + outSlice = append(outSlice, outItem) |
| 174 | + } |
| 175 | + return outSlice |
| 176 | +} |
| 177 | + |
| 178 | +func slice_FromProto[T, U any](mapCtx *direct.MapContext, in []T, mapper func(mapCtx *direct.MapContext, in T) *U) []U { |
| 179 | + if in == nil { |
| 180 | + return nil |
| 181 | + } |
| 182 | + |
| 183 | + outSlice := make([]U, 0, len(in)) |
| 184 | + for _, inItem := range in { |
| 185 | + outItem := mapper(mapCtx, inItem) |
| 186 | + outSlice = append(outSlice, *outItem) |
| 187 | + } |
| 188 | + return outSlice |
| 189 | +} |
0 commit comments