Path: blob/main/components/ws-manager-api/go/exposed_ports.go
2496 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package api56import (7"encoding/base64"89"golang.org/x/xerrors"10"google.golang.org/protobuf/proto"11)1213// ToBase64 marshals the image spec using protobuf and encodes it in base6414func (spec *ExposedPorts) ToBase64() (res string, err error) {15if spec == nil {16return17}1819rspec, err := proto.Marshal(spec)20if err != nil {21return "", xerrors.Errorf("cannot marshal image spec: %w", err)22}2324return base64.StdEncoding.EncodeToString(rspec), nil25}2627// ExposedPortsFromBase64 decodes an image specification from a base64 encoded protobuf message28func ExposedPortsFromBase64(input string) (res *ExposedPorts, err error) {29if len(input) == 0 {30return31}3233specPB, err := base64.StdEncoding.DecodeString(input)34if err != nil {35return nil, xerrors.Errorf("cannot decode image spec: %w", err)36}3738var spec ExposedPorts39err = proto.Unmarshal(specPB, &spec)40if err != nil {41return nil, xerrors.Errorf("cannot unmarshal image spec: %w", err)42}4344return &spec, nil45}464748