@@ -1851,3 +1851,194 @@ func (s *Artifacts) Preflight(ctx context.Context, request *shared.PreflightRequ
1851
1851
return res , nil
1852
1852
1853
1853
}
1854
+
1855
+ // SetVisibility - Set visibility of a namespace with an existing metadata entry
1856
+ func (s * Artifacts ) SetVisibility (ctx context.Context , request operations.SetVisibilityRequest , opts ... operations.Option ) (* operations.SetVisibilityResponse , error ) {
1857
+ hookCtx := hooks.HookContext {
1858
+ Context : ctx ,
1859
+ OperationID : "setVisibility" ,
1860
+ OAuth2Scopes : []string {},
1861
+ SecuritySource : s .sdkConfiguration .Security ,
1862
+ }
1863
+
1864
+ o := operations.Options {}
1865
+ supportedOptions := []string {
1866
+ operations .SupportedOptionRetries ,
1867
+ operations .SupportedOptionTimeout ,
1868
+ }
1869
+
1870
+ for _ , opt := range opts {
1871
+ if err := opt (& o , supportedOptions ... ); err != nil {
1872
+ return nil , fmt .Errorf ("error applying option: %w" , err )
1873
+ }
1874
+ }
1875
+
1876
+ baseURL := utils .ReplaceParameters (s .sdkConfiguration .GetServerDetails ())
1877
+ opURL , err := utils .GenerateURL (ctx , baseURL , "/v1/artifacts/namespaces/{namespace_name}/visibility" , request , nil )
1878
+ if err != nil {
1879
+ return nil , fmt .Errorf ("error generating URL: %w" , err )
1880
+ }
1881
+
1882
+ bodyReader , reqContentType , err := utils .SerializeRequestBody (ctx , request , false , true , "RequestBody" , "json" , `request:"mediaType=application/json"` )
1883
+ if err != nil {
1884
+ return nil , err
1885
+ }
1886
+
1887
+ timeout := o .Timeout
1888
+ if timeout == nil {
1889
+ timeout = s .sdkConfiguration .Timeout
1890
+ }
1891
+
1892
+ if timeout != nil {
1893
+ var cancel context.CancelFunc
1894
+ ctx , cancel = context .WithTimeout (ctx , * timeout )
1895
+ defer cancel ()
1896
+ }
1897
+
1898
+ req , err := http .NewRequestWithContext (ctx , "POST" , opURL , bodyReader )
1899
+ if err != nil {
1900
+ return nil , fmt .Errorf ("error creating request: %w" , err )
1901
+ }
1902
+ req .Header .Set ("Accept" , "application/json" )
1903
+ req .Header .Set ("User-Agent" , s .sdkConfiguration .UserAgent )
1904
+ req .Header .Set ("Content-Type" , reqContentType )
1905
+
1906
+ if err := utils .PopulateSecurity (ctx , req , s .sdkConfiguration .Security ); err != nil {
1907
+ return nil , err
1908
+ }
1909
+
1910
+ globalRetryConfig := s .sdkConfiguration .RetryConfig
1911
+ retryConfig := o .Retries
1912
+ if retryConfig == nil {
1913
+ if globalRetryConfig != nil {
1914
+ retryConfig = globalRetryConfig
1915
+ }
1916
+ }
1917
+
1918
+ var httpRes * http.Response
1919
+ if retryConfig != nil {
1920
+ httpRes , err = utils .Retry (ctx , utils.Retries {
1921
+ Config : retryConfig ,
1922
+ StatusCodes : []string {
1923
+ "429" ,
1924
+ "500" ,
1925
+ "502" ,
1926
+ "503" ,
1927
+ "504" ,
1928
+ },
1929
+ }, func () (* http.Response , error ) {
1930
+ if req .Body != nil {
1931
+ copyBody , err := req .GetBody ()
1932
+ if err != nil {
1933
+ return nil , err
1934
+ }
1935
+ req .Body = copyBody
1936
+ }
1937
+
1938
+ req , err = s .sdkConfiguration .Hooks .BeforeRequest (hooks.BeforeRequestContext {HookContext : hookCtx }, req )
1939
+ if err != nil {
1940
+ if retry .IsPermanentError (err ) || retry .IsTemporaryError (err ) {
1941
+ return nil , err
1942
+ }
1943
+
1944
+ return nil , retry .Permanent (err )
1945
+ }
1946
+
1947
+ httpRes , err := s .sdkConfiguration .Client .Do (req )
1948
+ if err != nil || httpRes == nil {
1949
+ if err != nil {
1950
+ err = fmt .Errorf ("error sending request: %w" , err )
1951
+ } else {
1952
+ err = fmt .Errorf ("error sending request: no response" )
1953
+ }
1954
+
1955
+ _ , err = s .sdkConfiguration .Hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, nil , err )
1956
+ }
1957
+ return httpRes , err
1958
+ })
1959
+
1960
+ if err != nil {
1961
+ return nil , err
1962
+ } else {
1963
+ httpRes , err = s .sdkConfiguration .Hooks .AfterSuccess (hooks.AfterSuccessContext {HookContext : hookCtx }, httpRes )
1964
+ if err != nil {
1965
+ return nil , err
1966
+ }
1967
+ }
1968
+ } else {
1969
+ req , err = s .sdkConfiguration .Hooks .BeforeRequest (hooks.BeforeRequestContext {HookContext : hookCtx }, req )
1970
+ if err != nil {
1971
+ return nil , err
1972
+ }
1973
+
1974
+ httpRes , err = s .sdkConfiguration .Client .Do (req )
1975
+ if err != nil || httpRes == nil {
1976
+ if err != nil {
1977
+ err = fmt .Errorf ("error sending request: %w" , err )
1978
+ } else {
1979
+ err = fmt .Errorf ("error sending request: no response" )
1980
+ }
1981
+
1982
+ _ , err = s .sdkConfiguration .Hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, nil , err )
1983
+ return nil , err
1984
+ } else if utils .MatchStatusCodes ([]string {"4XX" , "5XX" }, httpRes .StatusCode ) {
1985
+ _httpRes , err := s .sdkConfiguration .Hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, httpRes , nil )
1986
+ if err != nil {
1987
+ return nil , err
1988
+ } else if _httpRes != nil {
1989
+ httpRes = _httpRes
1990
+ }
1991
+ } else {
1992
+ httpRes , err = s .sdkConfiguration .Hooks .AfterSuccess (hooks.AfterSuccessContext {HookContext : hookCtx }, httpRes )
1993
+ if err != nil {
1994
+ return nil , err
1995
+ }
1996
+ }
1997
+ }
1998
+
1999
+ res := & operations.SetVisibilityResponse {
2000
+ StatusCode : httpRes .StatusCode ,
2001
+ ContentType : httpRes .Header .Get ("Content-Type" ),
2002
+ RawResponse : httpRes ,
2003
+ }
2004
+
2005
+ switch {
2006
+ case httpRes .StatusCode >= 200 && httpRes .StatusCode < 300 :
2007
+ case httpRes .StatusCode >= 400 && httpRes .StatusCode < 500 :
2008
+ switch {
2009
+ case utils .MatchContentType (httpRes .Header .Get ("Content-Type" ), `application/json` ):
2010
+ rawBody , err := utils .ConsumeRawBody (httpRes )
2011
+ if err != nil {
2012
+ return nil , err
2013
+ }
2014
+
2015
+ var out sdkerrors.Error
2016
+ if err := utils .UnmarshalJsonFromResponseBody (bytes .NewBuffer (rawBody ), & out , "" ); err != nil {
2017
+ return nil , err
2018
+ }
2019
+
2020
+ return nil , & out
2021
+ default :
2022
+ rawBody , err := utils .ConsumeRawBody (httpRes )
2023
+ if err != nil {
2024
+ return nil , err
2025
+ }
2026
+ return nil , sdkerrors .NewSDKError (fmt .Sprintf ("unknown content-type received: %s" , httpRes .Header .Get ("Content-Type" )), httpRes .StatusCode , string (rawBody ), httpRes )
2027
+ }
2028
+ case httpRes .StatusCode >= 500 && httpRes .StatusCode < 600 :
2029
+ rawBody , err := utils .ConsumeRawBody (httpRes )
2030
+ if err != nil {
2031
+ return nil , err
2032
+ }
2033
+ return nil , sdkerrors .NewSDKError ("API error occurred" , httpRes .StatusCode , string (rawBody ), httpRes )
2034
+ default :
2035
+ rawBody , err := utils .ConsumeRawBody (httpRes )
2036
+ if err != nil {
2037
+ return nil , err
2038
+ }
2039
+ return nil , sdkerrors .NewSDKError ("unknown status code returned" , httpRes .StatusCode , string (rawBody ), httpRes )
2040
+ }
2041
+
2042
+ return res , nil
2043
+
2044
+ }
0 commit comments