@@ -9,29 +9,31 @@ import (
99 "net/http"
1010)
1111
12- const nfsFlagRouteTemplate = "%s/projects/%s/storage/nfs/is-using-nfs"
12+ const (
13+ nfsFlagRouteTemplate = "%s/projects/%s/storage/nfs/is-using-nfs"
14+ vastUseSecondaryClusterFlagRouteTemplate = "%s/projects/%s/storage/nfs/vast-use-secondary-cluster"
15+ )
1316
1417var (
15- errCreateNfsFlagRequest = errors .New ("failed to create NFS flag request" )
16- errGetNfsFlag = errors .New ("failed to get NFS flag" )
17- errReadNfsResponse = errors .New ("failed to read NFS flag response" )
18- errUnmarshalNfsFlag = errors .New ("failed to unmarshal NFS flag response" )
18+ errCreateFlagRequest = errors .New ("failed to create flag request" )
19+ errGetFlag = errors .New ("failed to get flag" )
20+ errReadFlagResponse = errors .New ("failed to read flag response" )
21+ errUnmarshalFlag = errors .New ("failed to unmarshal flag response" )
1922)
2023
2124type NfsFlagResponse struct {
2225 Status bool `json:"status"`
2326}
2427
25- // GetNFSFlag returns true if the project has NFS enabled.
26- func GetNFSFlag (ctx context.Context , crusoeHTTPClient * http.Client , apiEndpoint , projectID string ) (bool , error ) {
27- nfsFlagRoute := fmt .Sprintf (nfsFlagRouteTemplate , apiEndpoint , projectID )
28- req , err := http .NewRequestWithContext (ctx , http .MethodGet , nfsFlagRoute , http .NoBody )
28+ // getFlag is a helper function to fetch a boolean flag from the API.
29+ func getFlag (ctx context.Context , crusoeHTTPClient * http.Client , flagRoute string ) (bool , error ) {
30+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , flagRoute , http .NoBody )
2931 if err != nil {
30- return false , fmt .Errorf ("%w: %w" , errCreateNfsFlagRequest , err )
32+ return false , fmt .Errorf ("%w: %w" , errCreateFlagRequest , err )
3133 }
3234 resp , err := crusoeHTTPClient .Do (req )
3335 if err != nil {
34- return false , fmt .Errorf ("%w: %w" , errGetNfsFlag , err )
36+ return false , fmt .Errorf ("%w: %w" , errGetFlag , err )
3537 }
3638
3739 if resp != nil && resp .Body != nil {
@@ -40,15 +42,33 @@ func GetNFSFlag(ctx context.Context, crusoeHTTPClient *http.Client, apiEndpoint,
4042
4143 bodyBytes , err := io .ReadAll (resp .Body )
4244 if err != nil {
43- return false , fmt .Errorf ("%w: %w" , errReadNfsResponse , err )
45+ return false , fmt .Errorf ("%w: %w" , errReadFlagResponse , err )
4446 }
4547
46- var nfsFlag NfsFlagResponse
48+ var flagResponse NfsFlagResponse
4749
48- unmarshalErr := json .Unmarshal (bodyBytes , & nfsFlag )
50+ unmarshalErr := json .Unmarshal (bodyBytes , & flagResponse )
4951 if unmarshalErr != nil {
50- return false , fmt .Errorf ("%w: %w" , errUnmarshalNfsFlag , unmarshalErr )
52+ return false , fmt .Errorf ("%w: %w" , errUnmarshalFlag , unmarshalErr )
5153 }
5254
53- return nfsFlag .Status , nil
55+ return flagResponse .Status , nil
56+ }
57+
58+ // GetNFSFlag returns true if the project has NFS enabled.
59+ func GetNFSFlag (ctx context.Context , crusoeHTTPClient * http.Client , apiEndpoint , projectID string ) (bool , error ) {
60+ nfsFlagRoute := fmt .Sprintf (nfsFlagRouteTemplate , apiEndpoint , projectID )
61+
62+ return getFlag (ctx , crusoeHTTPClient , nfsFlagRoute )
63+ }
64+
65+ // GetVastUseSecondaryClusterFlag returns true if the project has the vast-use-secondary-cluster flag enabled.
66+ func GetVastUseSecondaryClusterFlag (
67+ ctx context.Context ,
68+ crusoeHTTPClient * http.Client ,
69+ apiEndpoint , projectID string ,
70+ ) (bool , error ) {
71+ flagRoute := fmt .Sprintf (vastUseSecondaryClusterFlagRouteTemplate , apiEndpoint , projectID )
72+
73+ return getFlag (ctx , crusoeHTTPClient , flagRoute )
5474}
0 commit comments