mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 02:05:26 +00:00
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 (GetMachines/GetMachine/UpdateMachineState with lang); Instance->Machine mapping unchanged; len-guards kept. start/stop now address the instance by name. getLocalTimestamp made multi-layout + non-panicking. pkgmachine no longer imports google.golang.org/api. grpc is NOT yet zero in ai go.mod, but NOT from the compute path: it is pulled (never dialed) by the OTLP HTTP telemetry exporter (object -> otlptracehttp -> internal/otlpconfig -> grpc) and by the Gemini SDK google.golang.org/genai (model/gemini.go). Tracked separately.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
// Copyright 2023-2025 Hanzo AI Inc. All Rights Reserved.
|
|
// Portions Copyright 2025 The OpenAgent Authors. 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 pkgmachine
|
|
|
|
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 ""
|
|
}
|