@@ -24,21 +24,30 @@ var libraryCmd = cobra.Command{
2424 Args : cobra .ExactArgs (1 ),
2525 Run : func (cmd * cobra.Command , args []string ) {
2626 az := alzlib .NewAlzLib (nil )
27- creds , err := auth . NewToken ( )
27+ offline , err := cmd . Flags (). GetBool ( "offline" )
2828 if err != nil {
29- cmd .PrintErrf ("%s could not get Azure credential : %v\n " , cmd .ErrPrefix (), err )
29+ cmd .PrintErrf ("%s could not get offline flag : %v\n " , cmd .ErrPrefix (), err )
3030 os .Exit (1 )
3131 }
32- cf , err := armpolicy .NewClientFactory ("" , creds , & arm.ClientOptions {
33- ClientOptions : policy.ClientOptions {
34- Cloud : auth .GetCloudFromEnv (),
35- },
36- })
37- if err != nil {
38- cmd .PrintErrf ("%s could not create Azure policy client factory: %v\n " , cmd .ErrPrefix (), err )
39- os .Exit (1 )
32+
33+ if ! offline {
34+ creds , err := auth .NewToken ()
35+ if err != nil {
36+ cmd .PrintErrf ("%s could not get Azure credential: %v\n " , cmd .ErrPrefix (), err )
37+ os .Exit (1 )
38+ }
39+ cf , err := armpolicy .NewClientFactory ("" , creds , & arm.ClientOptions {
40+ ClientOptions : policy.ClientOptions {
41+ Cloud : auth .GetCloudFromEnv (),
42+ },
43+ })
44+ if err != nil {
45+ cmd .PrintErrf ("%s could not create Azure policy client factory: %v\n " , cmd .ErrPrefix (), err )
46+ os .Exit (1 )
47+ }
48+ az .AddPolicyClient (cf )
4049 }
41- az . AddPolicyClient ( cf )
50+
4251 thisRef := alzlib .NewCustomLibraryReference (args [0 ])
4352 libs , err := thisRef .FetchWithDependencies (cmd .Context ())
4453 if err != nil {
@@ -63,13 +72,19 @@ var libraryCmd = cobra.Command{
6372
6473 chk := checker .NewValidator (
6574 checks .CheckAllDefinitionsAreReferenced (az ),
66- checks .CheckAllArchitectures (az ),
6775 checks .CheckLibraryMemberPath (az ),
6876 checks .CheckDefaults (az ),
6977 checks .CheckLibraryFileNames (args [0 ], & checks.CheckLibraryFileNameOptions {
7078 Fix : shouldFix ,
7179 }),
7280 )
81+
82+ if ! offline {
83+ chk = chk .AddChecks (
84+ checks .CheckAllArchitectures (az ),
85+ )
86+ }
87+
7388 err = chk .Validate ()
7489 if err != nil {
7590 cmd .PrintErrf ("%s library check error: %v\n " , cmd .ErrPrefix (), err )
@@ -82,4 +97,6 @@ func init() {
8297 libraryCmd .Flags ().
8398 BoolP ("fix" , "f" , false ,
8499 "Whether to fix any fixable issues (currently only filename issues)." )
100+ libraryCmd .Flags ().
101+ Bool ("offline" , false , "Whether to run the checks in offline mode (no Azure calls)." )
85102}
0 commit comments