MCPcopy Create free account
hub / github.com/clouditor/clouditor / ContinueSession

Function ContinueSession

cli/session.go:104–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102}
103
104func ContinueSession() (session *Session, err error) {
105 var (
106 file *os.File
107 folder string
108 )
109
110 folder = viper.GetString(SessionFolderFlag)
111
112 // try to read from session.json
113 if file, err = os.OpenFile(fmt.Sprintf("%s/session.json", folder), os.O_RDONLY, 0600); err != nil {
114 return
115 }
116
117 defer func(file *os.File) {
118 _ = file.Close()
119 }(file)
120
121 session = new(Session)
122 session.Folder = folder
123
124 if err = json.NewDecoder(file).Decode(&session); err != nil {
125 return nil, fmt.Errorf("could not parse session file: %w", err)
126 }
127
128 // If we detect that this session is "dirty", try to save it again
129 if session.dirty {
130 _ = session.Save()
131 }
132
133 if session.ClientConn, err = grpc.NewClient(session.URL, api.DefaultGrpcDialOptions(session.URL, session)...); err != nil {
134 return nil, fmt.Errorf("could not connect: %w", err)
135 }
136
137 return session, nil
138}
139
140// Save saves the session into the `.clouditor` folder in the home directory
141func (s *Session) Save() (err error) {

Calls 3

DefaultGrpcDialOptionsFunction · 0.92
ErrorfMethod · 0.80
SaveMethod · 0.65

Tested by 2

TestSessionFunction · 0.74
TestReflectionNoAuthFunction · 0.74