diff --git a/app/gitspace/orchestrator/common/detect_os.go b/app/gitspace/orchestrator/common/detect_os.go new file mode 100644 index 000000000..9a9f31b39 --- /dev/null +++ b/app/gitspace/orchestrator/common/detect_os.go @@ -0,0 +1,26 @@ +// Copyright 2023 Harness, Inc. +// +// 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 common + +import ( + _ "embed" +) + +//go:embed script/os_info.sh +var osDetectScript string + +func GetOSInfoScript() (script string) { + return osDetectScript +} diff --git a/app/gitspace/orchestrator/ide/vscode.go b/app/gitspace/orchestrator/ide/vscode.go index 2154d2de1..fabd3dc22 100644 --- a/app/gitspace/orchestrator/ide/vscode.go +++ b/app/gitspace/orchestrator/ide/vscode.go @@ -17,9 +17,9 @@ package ide import ( "context" "fmt" - "os" "strconv" + "github.com/harness/gitness/app/gitspace/orchestrator/common" "github.com/harness/gitness/app/gitspace/orchestrator/devcontainer" "github.com/harness/gitness/app/gitspace/orchestrator/template" "github.com/harness/gitness/types" @@ -48,15 +48,12 @@ func (v *VSCode) Setup( ctx context.Context, exec *devcontainer.Exec, ) ([]byte, error) { - osInfoScript, err := os.ReadFile("app/gitspace/orchestrator/common/script/os_info.sh") - if err != nil { - return nil, fmt.Errorf("failed to read os_info.sh: %w", err) - } + osInfoScript := common.GetOSInfoScript() sshServerScript, err := template.GenerateScriptFromTemplate( templateSetupSSHServer, &template.SetupSSHServerPayload{ Username: exec.UserIdentifier, AccessType: exec.AccessType, - OSInfoScript: string(osInfoScript), + OSInfoScript: osInfoScript, }) if err != nil { return nil, fmt.Errorf( diff --git a/app/gitspace/orchestrator/user/user_impl.go b/app/gitspace/orchestrator/user/user_impl.go index f5438e560..cc02f7c05 100644 --- a/app/gitspace/orchestrator/user/user_impl.go +++ b/app/gitspace/orchestrator/user/user_impl.go @@ -17,8 +17,8 @@ package user import ( "context" "fmt" - "os" + "github.com/harness/gitness/app/gitspace/orchestrator/common" "github.com/harness/gitness/app/gitspace/orchestrator/devcontainer" "github.com/harness/gitness/app/gitspace/orchestrator/template" ) @@ -35,17 +35,14 @@ func NewUserServiceImpl() Service { } func (u *ServiceImpl) Manage(ctx context.Context, exec *devcontainer.Exec) ([]byte, error) { - osInfoScript, err := os.ReadFile("app/gitspace/orchestrator/common/script/os_info.sh") - if err != nil { - return nil, fmt.Errorf("failed to read os_info.sh: %w", err) - } + osInfoScript := common.GetOSInfoScript() script, err := template.GenerateScriptFromTemplate( templateManagerUser, &template.SetupUserPayload{ Username: exec.UserIdentifier, AccessKey: exec.AccessKey, AccessType: exec.AccessType, HomeDir: exec.HomeDir, - OSInfoScript: string(osInfoScript), + OSInfoScript: osInfoScript, }) if err != nil { return nil, fmt.Errorf(