1// Copyright 2023 The Gitea Authors. All rights reserved.2// SPDX-License-Identifier: MIT34package config56import (7 "encoding/json"8 "os"9)1011const registrationWarning = "This file is automatically generated by act-runner. Do not edit it manually unless you know what you are doing. Removing this file will cause act runner to re-register as a new runner."1213// Registration is the registration information for a runner14type Registration struct {15 Warning string `json:"WARNING"` // Warning message to display, it's always the registrationWarning constant1617 ID int64 `json:"id"`18 UUID string `json:"uuid"`19 Name string `json:"name"`20 Token string `json:"token"`21 Address string `json:"address"`22 Labels []string `json:"labels"`23}2425func LoadRegistration(file string) (*Registration, error) {26 f, err := os.Open(file)27 if err != nil {28 return nil, err29 }30 defer f.Close()3132 var reg Registration33 if err := json.NewDecoder(f).Decode(®); err != nil {34 return nil, err35 }3637 reg.Warning = ""3839 return ®, nil40}4142func SaveRegistration(file string, reg *Registration) error {43 f, err := os.Create(file)44 if err != nil {45 return err46 }47 defer f.Close()4849 reg.Warning = registrationWarning5051 enc := json.NewEncoder(f)52 enc.SetIndent("", " ")53 return enc.Encode(reg)54}