Files
zeekay ea3403ef9c refactor(compute): hand-rolled GCP REST (net/http + oauth2), drop google.golang.org/api
Replace the google.golang.org/api/compute/v1 SDK with a plain net/http client
against the compute REST endpoints (.../instances GET list+get, POST start|stop).
Unexported JSON structs map only the fields the adapter needs. Auth is an OAuth2
bearer token from the service-account JSON via golang.org/x/oauth2/google
(JWTConfigFromJSON -> TokenSource, pure HTTP token exchange — proven grpc-free),
with Application Default Credentials fallback (in-cluster workload identity).

MachineClientInterface preserved exactly; Instance->Machine mapping unchanged;
len-guards kept. start/stop now address the instance by name (the correct compute
resource id; the old numeric-id path could never resolve). getLocalTimestamp made
multi-layout + non-panicking so real RFC3339-with-offset timestamps parse.

go.mod: google.golang.org/api removed. grpc is NOT yet zero in go.mod, but NOT
from the compute path: it is pulled (never dialed) by the OTLP HTTP telemetry
exporter — telemetry -> otlpmetrichttp -> internal/oconf -> grpc. Tracked separately.
2026-07-05 12:32:04 -07:00

40 lines
1.2 KiB
Go

// Copyright 2024 Hanzo Industries Inc. All Rights Reserved.
//
// 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 service
import "time"
func getLocalTimestamp(input string) string {
if input == "" {
return ""
}
// Providers report timestamps in different shapes: RFC3339 with a zone
// offset or fractional seconds (GCP), and a minute-precision UTC form
// (Aliyun). Try each known layout and normalize to local RFC3339; an
// unparseable value degrades to empty rather than panicking.
layouts := []string{
time.RFC3339,
"2006-01-02T15:04Z",
}
for _, layout := range layouts {
if utcTime, err := time.Parse(layout, input); err == nil {
return utcTime.Local().Format(time.RFC3339)
}
}
return ""
}